How to work with jQuery with PhantomJS, Poltergeist and Capybara

I have a series of automated tests in Ruby that use Capybara, Poltergeist, and PhantomJS to interact with web pages. However, the problem is that some pages are not working properly because jQuery does not seem to load. For example, on one web page there is such code as:

<script type="text/javascript">
<!--
  jQuery(window).load(function() {
    //Do Javascript-y things
  });
//-->
</script>

But this does not work / works. From what I read, it seems that PhantomJS doesn't work fine with jQuery (or at least it doesn't load jQuery automatically). How can I fix this. Keep in mind that I cannot change the actual code of the webpage.

Summary. How can I add / insert / load jQuery when using PhantomJS, Poltergeist and Capybara?

EDIT: This is how I use phantomjs. Please note that I never use phantomjs directly. The phantomjs executable file is indirectly used by the 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
       )       
+4
source share
1 answer

Your jQuery probably needs time to execute. Add the find () statement to your test, looking for the jQuery result. It will be blocked as described here: http://www.elabs.se/blog/53-why-wait_until-was-removed-from-capybara

0
source

All Articles