Reputation: 1878
I'm trying to get up and running with capybara and I'm testing out the functional differences between poltergeist and selenium-webdriver. A pretty basic test is giving me unexpected results and I'd like to confirm if this is something I'm doing wrong in my configuration, or if this is simply expected behavior.
spec_helper:
require 'capybara/rspec'
# require 'selenium/webdriver'
require 'capybara/poltergeist'
Capybara.run_server = false
# Capybara.default_driver = :selenium
Capybara.default_driver = :poltergeist
Capybara.javascript_driver = :poltergeist
Capybara.app_host = 'http://google.com'
hello_world_spec:
require 'spec_helper'
feature 'testing with rspec' do
before :each do
visit '/'
end
scenario 'visit google main page' do
expect(page).to have_content 'About'
end
scenario 'search for something', js: true do
fill_in 'q', with: 'test search'
# click_on 'Google Search'
sleep 5
page.driver.render 'screenshot.png', full: true
expect(page).to have_content 'Wikipedia'
end
end
The first test succeeds as expected, but the second one only works with selenium. If you perform this test manually in any browser, google will perform the search as you type. With poltergeist, the search is never performed until I manually click the "Google Search" button. What's going on here?
Upvotes: 0
Views: 131
Reputation: 557
Selenium uses native.send_keys
to fill out an input field. However, looking at poltergiest's changelog it appears it currently only has basic send_keys support and as far as I can see in the code base it doesn't use send_keys
to set a fields value.
Try using the send_keys method directly to see if this solves your problem. It should you work in your case as your are only sending a simple string without key modifiers
Here's how I'd suggest -
find_field('q').native.send_keys('test search')
Upvotes: 1