[英]How to have jQuery work with PhantomJS, Poltergeist and Capybara
I have a series of automated tests in Ruby that use Capybara, Poltergeist and PhantomJS to interact with webpages. 我在Ruby中进行了一系列自动化测试,使用Capybara,Poltergeist和PhantomJS与网页进行交互。 However, the problem is some of the pages are not working properly because jQuery does not appear to be getting loaded.
但是,问题是某些页面无法正常工作,因为jQuery似乎没有加载。 For instance, on one webpage there is code like:
例如,在一个网页上有以下代码:
<script type="text/javascript">
<!--
jQuery(window).load(function() {
//Do Javascript-y things
});
//-->
</script>
But this does not seem to work/run. 但这似乎不起作用/运行。 From what I've read it appears that PhantomJS does not work naturally with jQuery (or at the very least it does not automatically load jQuery).
从我所看到的看来,PhantomJS似乎不能自然地与jQuery一起工作(或者至少它不会自动加载jQuery)。 How can I fix this.
我怎样才能解决这个问题。 Keep in mind I can't change the webpage's actual code.
请记住,我无法更改网页的实际代码。
Summary: How can I add/inject/load jQuery when using PhantomJS, Poltergeist and Capybara? 简介:如何在使用PhantomJS,Poltergeist和Capybara时添加/注入/加载jQuery?
EDIT: Here is how I'm using phantomjs. 编辑:这是我如何使用phantomjs。 Notice how I never actually use phantomjs directly.
请注意我从未直接使用过phantomjs。 The phantomjs executable is indirectly used by Poltergeist:
Phateromjs可执行文件由Poltergeist间接使用:
Capybara.register_driver :poltergeist do |app|
driver = Capybara::Poltergeist::Driver.new(app,
:debug => debug,
:window_size => [1616, 1000],
:js_errors => true,
:cookies => true,
:phantomjs_options => ['--ignore-ssl-errors=true',
'--web-security=false',
'--local-to-remote-url-access=true',
'--proxy-type=none' ],:timeout => 180
)
Likely your jQuery needs time to execute. 可能你的jQuery需要时间来执行。 Add a find() statement in your test looking for a result of the jQuery.
在测试中添加一个find()语句,查找jQuery的结果。 It will block, as described here: http://www.elabs.se/blog/53-why-wait_until-was-removed-from-capybara
它将阻止,如下所述: http : //www.elabs.se/blog/53-why-wait_until-was-removed-from-capybara
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.