2
rspec test_name_spec.rb
運行確定單項測試每一個包含@driver = Selenium::WebDriver
我需要運行它們,並保持登錄狀態,使用從測試到測試的相同窗口。
我設置了一套房,但是當我使用下面的代碼移動@driver=
分配到before(:all)
,我得到一個錯誤,因爲@driver
爲空:
describe "district" do
before(:all) do
@driver = Selenium::WebDriver.for :firefox
end
require File.join(File.dirname(__FILE__), "units/set_QA_district_name_spec.rb")
require File.join(File.dirname(__FILE__), "units/set_file_uploads_source_location_spec.rb")
require File.join(File.dirname(__FILE__), "units/login_as_admin_spec.rb")
end
錯誤:
1) SetQADistrictName test_set_q_a_district_name
Failure/Error: @driver.manage.timeouts.implicit_wait = 30
NoMethodError:
undefined method `manage' for nil:NilClass
內容set_QA_district_name:
require_relative "../../../spec_helper"
include RSpec::Expectations
describe "SetQADistrictName" do
before(:each) do
@driver = Selenium::WebDriver.for :firefox
@base_url = "http://dmstaffing-stage.herokuapp.com/"
@accept_next_alert = true
@driver.manage.timeouts.implicit_wait = 30
@verification_errors = []
end
after(:each) do
#@driver.quit
@verification_errors.should == []
end
it "test_set_q_a_district_name" do
QA_run_number = "056"
end
def element_present?(how, what)
@driver.find_element(how, what)
true
rescue Selenium::WebDriver::Error::NoSuchElementError
false
end
def verify(&blk)
yield
rescue ExpectationNotMetError => ex
@verification_errors << ex
end
def close_alert_and_get_its_text(how, what)
alert = @driver.switch_to().alert()
if (@accept_next_alert) then
alert.accept()
else
alert.dismiss()
end
alert.text
ensure
@accept_next_alert = true
end
end
可你也分享你所擁有的'* _spec.rb' file.Say內例如'單位/ set_QA_district_name_spec.rb「' – Amey 2013-05-03 16:08:54
快樂。上面添加。 – 2013-05-03 16:51:22