我正嘗試在使用Capybara-webkit的無頭模式下運行簡單的Google搜索測試。使用Capybara webkit時發現元素錯誤,但測試在非無頭模式下正常運行
我已經設置了司機在env.rb文件:
Capybara.default_driver = :webkit
Capybara.current_driver = :webkit
Capybara.javascript_driver = :webkit
和特徵文件有一個簡單的場景輪廓,其搜索的輸入,並驗證結果是否包含預期輸出:
Given User opens the google page
When she searches for "<input>"
Then verify that the result has "<output>"
Examples:
|input | output |
|Agile Samurai author name|Jonathan Rasmusson|
|Eloquent Ruby author name|Russ Olsen |
在步驟定義中,訪問google頁面並將輸入輸入到文本框中並單擊搜索按鈕。
Given /^User opens the google page$/ do
visit "http://google.com"
end
When /^she searches for "(.*?)"$/ do |search_query|
fill_in "gbqfq", :with => search_query
click_button "gbqfba"
end
Then /^verify that the result has "(.*?)"$/ do |output|
should have_content output
end
當我運行這些測試,我得到的錯誤:
Unable to find field "gbqfq" (Capybara::ElementNotFound)
但是,如果我改變司機硒:
Capybara.default_driver = :selenium
Capybara.current_driver = :selenium
Capybara.javascript_driver = :selenium
然後,測試運行,所有的步驟通過。
在無頭模式下,是否以其他方式找到元素? 我的方法錯了嗎?我無法理解爲什麼在瀏覽器模式下工作正常(打開firefox實例)時無法在無頭模式下找到該元素。
我是這個領域的新手,所以任何幫助都會深表謝意。 預先感謝您。