Javascript 找到带有rspec/Capybara的Rails测试链接,但单击时未生成表单
这个测试的目的是找到一个Create链接——其中一个是我首先使用的Javascript 找到带有rspec/Capybara的Rails测试链接,但单击时未生成表单,javascript,ruby-on-rails,rspec,capybara,Javascript,Ruby On Rails,Rspec,Capybara,这个测试的目的是找到一个Create链接——其中一个是我首先使用的——然后在单击该链接时填写一个用javascript生成的表单。尽管成功地找到了Create链接并调用click,表单还是不会生成 require 'spec_helper' include Warden::Test::Helpers Warden.test_mode! describe "user log in" do it "allows an existing user to sign in" do visi
——然后在单击该链接时填写一个用javascript生成的表单。尽管成功地找到了Create链接并调用click,表单还是不会生成
require 'spec_helper'
include Warden::Test::Helpers
Warden.test_mode!
describe "user log in" do
it "allows an existing user to sign in" do
visit "/users/sign_in"
fill_in "Login", with: "Kevin"
fill_in "Password", with: "abcdef"
visit "/students/2/schedule"
first(:link, 'Create').click
within '#session_minutes' do
find("option[value='60']").click
end
end
end
这可能是javascript/rspec问题吗?在实现phantomjs和poltergeist以在无头浏览器上生成JS操作后,我无法模拟访问创建链接所需的悬停效果,因此我不确定采用哪种测试方法来改善我的情况。您需要使用支持javascript的驱动程序,而capybara的默认驱动程序则不支持 您可以找到驱动程序的文档
我更喜欢恶作剧,因为它完全没有头(不需要真正的浏览器),所以可以在一个没有头的流浪者盒子里运行。如果您已经安装了Firefox,Selenium几乎不需要安装。为了解决我的问题,我使用了poltergeist和phantomjs,然后使用
鼠标覆盖
操作,如下所示
require 'spec_helper'
include Warden::Test::Helpers
Warden.test_mode!
describe "user log in" do
it "allows an existing user to sign in" do
visit "/users/sign_in"
fill_in "Login", with: "Kevin"
fill_in "Password", with: "abcdef"
visit "/students/2/schedule"
first('.open').trigger('mouseover')
end
end
我已经实现了phantom js,但现在的问题是我无法模拟悬停效果——在poltergeist中,似乎有相当多的人要求使用此功能。它已经实现了吗?Poltergeist支持
find('selector')。悬停
,并根据它的特性,在单击之前悬停。css:hover
伪类与mouseover
事件不同。非常感谢您澄清您的帮助