我試圖設置一個Jquery移動應用程序的黃瓜測試,但測試點擊是拋出一個意外的錯誤。下面是這種情況:點擊鏈接使用水豚/黃瓜
problems.feature
Scenario: Clicking problem when not signed in
When I go to the wall page for The Beast
Then I should see "Blue"
When I click the problem "Blue"
Then I go to the sign up page
和實施,以捕捉到倒數第二行的相關步驟如下:
steps.rb
When /^I click the problem "(.*)"$/ do |problem_name|
find(:xpath, "//h3[text() = '#{problem_name}']/parent::a").click
end
一切直到這一點才能通過。當它到達點擊這個問題,下面的錯誤被拋出:
When I click the problem "Blue"
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each (ActionView::Template::Error)
我也曾嘗試立即查找之前,包括一個調試器()點擊steps.rb調用。當我再手動運行find命令,它確實返回以下內容:
(rdb:1) p find(:xpath, "//h3[text() = 'Blue']/parent::a")
#<Capybara::Element tag="a" path="/html/body/div/div[2]/ul/li[2]/a">
然後在調試器就完了「單擊」運行產生如下:
(rdb:1) p find(:xpath, "//h3[text() = '#{problem_name}']/parent::a").click
ActionView::Template::Error Exception: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each
(rdb:1) p find(:xpath, "//h3[text() = '#{problem_name}']/parent::a").click
nil
所以似乎水豚可以找到正確的元素,但當試圖點擊它設置爲零?我想知道如何正確執行我正在使用Capybara執行的點擊。
已嘗試使用:「然後顯示頁面」步驟來調試問題。 –