简体   繁体   中英

PhantomJS does not work for Cucumber test

I have added javascript in my Rails app to enable the button only when one of the checkboxes has been checked.

$(document).on('turbolinks:load', function() {
  $(function () {
    $('.delete-checkbox').change(function() {
      if ($('.delete-checkbox:checked').length) {
        $('#delete-url-btn').removeAttr('disabled');
      } else {
        $('#delete-url-btn').attr('disabled', 'disabled');
      }
    });
  });
})

The code definitely works in the browser when I test it. However, it seems like the javascript is not picked up when I am running my cucumber test with poltergeist (phantomjs). I have added the @javascript tag in my cucumber feature and I have also followed all the instructions on the phantomjs website to include phantomjs. I am wondering what I am missing?

please check if adding 'capybara' gem (if you don't have it in Gemfile) and following code:

Capybara.register_driver :poltergeist do |app|
  Capybara::Poltergeist::Driver.new(app, js_errors: false)
end

Capybara.default_driver = :poltergeist
Capybara.javascript_driver = :poltergeist

to the features/support/env.rb file helps.

Also please check if you can run phantomjs from command line, ie. "phantomjs --version". If you're on Ubuntu you have to remove Ubuntu phantomjs package (it's broken: https://github.com/ariya/phantomjs/issues/14376 ), and use the one from http://phantomjs.org/download.html page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM