[英]Rails Testing link found with rspec/Capybara but form not generated on click
我打算進行此測試的目的是找到“創建”鏈接-因此我first
使用了許多鏈接-然后填寫單擊該鏈接時使用javascript生成的表單。 盡管成功找到了Create鏈接並調用了它,但仍未生成該表單。
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操作之后,我無法模擬訪問Create鏈接所需的on-hover效果,因此我不確定要采用哪種測試方法來改善我的情況。
您需要使用支持javascript的驅動程序,而capybara的默認驅動程序則不支持。
您可以在此處找到驅動程序的文檔。
我更喜歡poltergeist,因為它完全沒有頭(不需要實際的瀏覽器),因此可以在無頭的無聊的盒子中運行。 如果您已經安裝了Firefox,則Selenium幾乎不需要進行任何設置。
為了解決我的問題,我使用了poltergeist和phantomjs,然后使用mouseover
操作,如下所示
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.