2

Is there a way to inject the javascript sooner?

visit("/path/to/my/page")
page.execute_script("document.getElementsByTagName('html')[0].className += ' hybrid-app';")

I'm testing some things that only effect a web app when it is used from within a hybrid mobile app. My hybrid app related code does not run unless this class exists. From the native iOS code I inject some javascript which adds a class to the HTML tag before the page loads.

The problem is that when do the same from the Capybara test, it is added too late.

Currently I am working around this by explicitly calling my hybrid app setup code. This is not ideal because this is not how the hybrid app works and could cause side effects.

visit("/path/to/my/page")
script = %q(
     document.getElementsByTagName('html')[0].className += ' neeman-hybrid-app';
     hybridAppSetup();
)
page.execute_script(script)
Onato
  • 9,916
  • 5
  • 46
  • 54
  • A page is not loaded until all resources are loaded. I would like to run the code as soon as soon as the DOM is ready, but before the external scripts have been downloaded and executed. – Onato Jan 21 '16 at 23:29

0 Answers0