当我的水豚测试遇到我的 rspec 文件中的第二个 it 块时,我无法单击链接或基本上执行任何操作。
所以我的代码如下: 注意 - 这是一个基本测试,我浏览到一个页面,在 before 块中创建一个调查,然后我在 it 块中的测试将是编辑和查看调查。
require 'spec_helper'
include Tests # - this is a module where I include the Capybara DSL
describe "Survey Tests" do
before :all do
visit('http://mytestenv.com')
fill_in('login', :with => 'testaccount@test.com')
fill_in('password', :with => 'TestyTest')
click_button('login_button')
all('a.edit', :text => 'Edit')[0].click
click_link('Polls & Feedback')
click_link('Session Polls')
click_link('Create New Session Poll')
fill_in('question', :with => "New Question")
choose('User can type a response')
click_button('Add')
end
describe "View and Edit polls" do
it "allows you to view polls" do
click_link('Polls & Feedback')
click_link('View Poll')
should have_no_css('.form_error')
should have_content('Add another question')
should have_content('Results')
end
it "allows you to edit a poll question" do
click_link('Edit')
first('a.blueb').click
find('.checkbox').click
click_link("Add an answer")
fill_in('options[]', :with=>"Multiple answers")
click_button('Save Changes')
should have_no_css('.form_error')
end
所以,当我使用 webkit(或任何其他驱动程序,如 chrome)时会发生什么,它会运行我的 before 语句没问题,然后它将运行第一个 it 阻塞没有任何问题,但是当它进入第二个它时块,它然后胡扯,说它找不到编辑链接。但是,如果我将 click_link('Edit) 放在第一个 it 语句的底部(在 should have_content('Results') 之后),那么它将单击链接没问题。所以它只会在它进入第二个 it 语句块时发生。有趣的是,如果我这样说:
session = Capybara::Session.new(:selenium)
在我的测试规范文件的顶部并在我的规范帮助文件中注释掉 webkit 驱动程序信息,测试将运行并完成,使用 Firefox 没有任何问题。
我的规范帮助文件如下:
require 'yaml'
require 'capybara'
require 'capybara/rspec'
require 'rspec-expectations'
require 'config'
require 'capybara-webkit'
require 'selenium/webdriver'
########### - chrome driver - ####################### #
#Capybara.default_selector = :css#
#Capybara.default_driver = :selenium#
#Capybara.run_server = false#
#Capybara.register_driver :selenium do |app|#
# Capybara::Selenium::Driver.new(app, :browser => :chrome)
#end
############# - Poltergeist - #######################
#Capybara.default_driver = :poltergeist##Capybara.javascript_driver = :poltergeist##
#Capybara.run_server = false##
#Capybara.register_driver :poltergeist do |app|##
#Capybara::Poltergeist::Driver.new(app, {:inspector => true})
#end
############### - Capybara WebKit - ##################
Capybara.default_driver = :webkit
Capybara.javascript_driver = :webkit
Capybara.run_server = false
#This will including the Capybara DSL in the tests
module Tests
include Capybara::DSL
end
有谁知道我做错了什么?我尝试过使用各种不同的驱动程序,例如 chrome、firefox、poltergeist 和 capybara webkit,但总是同样的问题。
我正在使用 ruby 1.9.3,-安装的水豚版本是 2.1.0 和 1.1.4。
任何帮助将不胜感激!!
谢谢