Using Capybara-Webkit, Inject Javascript before client code runs

喜你入骨 提交于 2019-12-24 00:03:19

问题


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)

来源:https://stackoverflow.com/questions/34935587/using-capybara-webkit-inject-javascript-before-client-code-runs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!