I am trying to run a simple google search test in the headless mode using Capybara-webkit.
I have set the drivers as in env.rb file:
Capybara.default_driver = :webkit
Capybara.current_driver = :webkit
Capybara.javascript_driver = :webkit
And the feature file has a simple scenario outline which searches for a input and verifies whether the result contains the expected output:
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 |
In the step definition, the google page is visited and the input is entered into the text box and the search button is clicked.
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
When I run these tests, I get the error:
Unable to find field "gbqfq" (Capybara::ElementNotFound)
But, if I change the driver to selenium:
Capybara.default_driver = :selenium
Capybara.current_driver = :selenium
Capybara.javascript_driver = :selenium
then, the tests run and all the steps pass.
In the headless mode, are the elements found in some other way? Is my approach wrong? I am unable to understand why the element is not found in the headless mode when it works fine in the browser mode (that opens firefox instance).
I am a novice in this field, so any help will be deeply appreciated. Thank you in advance.