我有兩個場景的簡單Cucumber特性。它使用watir-webdriver執行基本登錄和註銷。第一種情況(登錄)運行良好,watir方法執行沒有問題。當第二個方案中運行(通過運行該功能爲一體),我得到:在特性中運行第二個場景時的Cucumber NoMethodError
NoMethodError: undefined method `wait_until' for nil:NilClass
玩這個圍繞透露,在第二種情況下,任何調用的Watir-webdriver的方法拋出這個錯誤,而同方法在第一種情況下很好。我假設我有一個範圍問題,並嘗試在我的第二個方案的步驟定義中「require'watir-webdriver'」無濟於事。我已經包含了這兩種情況的步驟定義。我更新了所有的寶石,並在Ruby 1.9.2上嘗試過Cucumber 0.10.0和0.10.2。
對不起;對於ruby/cucumber/watir,我很新,並且在發佈之前已經嘗試將其排除幾個小時。非常感謝您的任何建議!
require "watir-webdriver"
Given /^I have the proper credentials$/ do
@username = "matt"
@password = "abc123"
end
When /^I am on the login page$/ do
@browser = Watir::Browser.new(:firefox)
@browser.goto ("http://dev.example.net")
end
When /^I enter username and password$/ do
@browser.text_field(:class, /x-form-field x-form-text/).set @username
@browser.text_field(:index, 1).set @password
sleep 1
@browser.button(:text, 'Login').click
end
Then /^I should should be granted access$/ do
@browser.wait_until { @browser.text.include? "Global Priorities" }
fail unless @browser.text.include? 'Global Priorities'
end
Given /^I am currently logged in$/ do
@browser.wait_until { @browser.text.include? "Welcome: #{@username}" }
fail unless @browser.text.include? "Welcome: #{@username}"
end
When /^I click the Log Out button$/ do
@browser.button(:text, "Log Out").click
end
Then /^I should be logged out$/ do
pending
end
我通過設置我的env.rb文件來啓動瀏覽器實例(對所有場景通用),然後從步驟本身中刪除新的瀏覽器實例,對此進行了排序。謝謝。 – Matt 2011-04-10 13:51:11