2017-08-07 103 views
0

我已经在我的Rails应用程序中添加了javascript,以便仅在其中一个复选框被选中时启用按钮。PhantomJS不适用于黄瓜测试

$(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'); 
     } 
    }); 
    }); 
}) 

当我测试它时,代码在浏览器中肯定会起作用。但是,当我用poltergeist(phantomjs)运行我的黄瓜测试时,似乎没有找到javascript。我在我的黄瓜功能中添加了@javascript标记,并且我还按照phantomjs website上的所有说明添加了phantomjs。我想知道我失踪了什么?

回答

0

请检查是否加入“水豚”宝石(如果你没有它的Gemfile) 和下面的代码:

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

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

的功能/支持/ env.rb文件帮助。

另请检查是否可以从命令行运行phantomjs,即。 “phantomjs --version”。如果你在Ubuntu上,你必须删除Ubuntu phantomjs软件包(已损坏:https://github.com/ariya/phantomjs/issues/14376),并使用http://phantomjs.org/download.html页面。