简体   繁体   English

PhantomJS不适用于黄瓜测试

[英]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. 我已经在Rails应用程序中添加了javascript,以仅在选中其中一个复选框时才启用按钮。

$(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). 但是,当我使用poltergeist(phantomjs)运行黄瓜测试时,似乎没有拾取javascript。 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. 我在黄瓜功能中添加了@javascript标记,并且还按照phantomjs网站上的所有说明进行操作,以包含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: 请检查是否添加了“水豚” gem(如果您在Gemfile中没有它)和以下代码:

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. 对features / support / env.rb文件的帮助。

Also please check if you can run phantomjs from command line, ie. 另外请检查您是否可以从命令行运行phantomjs。 "phantomjs --version". “ 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. 如果您使用的是Ubuntu,则必须删除Ubuntu phantomjs软件包(该软件包已损坏: https : //github.com/ariya/phantomjs/issues/14376 ),并使用http://phantomjs.org/download.html中的软件包页。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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