Skip to content

Commit

Permalink
Switch to chrome for Selenium tests. Done with NUBIC#328.
Browse files Browse the repository at this point in the history
As noted in env.rb, Firefox will not deliver focus/blur events when in the
OS background. This means that tests that rely on the change event being fired
for text inputs, e.g., will fail if Firefox is in the background.
  • Loading branch information
rsutphin committed Jul 23, 2012
1 parent a368bf3 commit cbe83b2
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ rdoc
pkg
Gemfile.lock
reports
chromedriver.log

## PROJECT::SPECIFIC
testbed
Expand Down
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,25 @@ to run the features and start writing tests!

[bundler]: http://gembundler.com/

## Selenium

Some of Surveyor's integration tests use Selenium WebDriver and Capybara. The
WebDriver-based tests default to running in Chrome due to an unfortunate
[Firefox bug][FF566671]. For them to run, you'll either need:

* Chrome and [chromedriver][] installed, or
* to switch to use Firefox instead

To use Firefox instead of Chrome, invoke one or more features with
`SELENIUM_BROWSER` set in the environment:

$ SELENIUM_BROWSER=firefox bundle exec rake cucumber
$ SELENIUM_BROWSER=firefox bundle exec cucumber features/ajax_submissions.feature

Note that when running features in Firefox, you must allow the WebDriver-driven
Firefox to retain focus, otherwise some tests will fail.

[FF566671]: https://bugzilla.mozilla.org/show_bug.cgi?id=566671
[chromedriver]: http://code.google.com/p/selenium/wiki/ChromeDriver

Copyright (c) 2008-2011 Brian Chamberlain and Mark Yoon, released under the MIT license
2 changes: 1 addition & 1 deletion features/step_definitions/surveyor_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def render_context
if dis_or_en == 'dis'
element['disabled'].should == 'true'
else
element['disabled'].should be_nil
[nil, 'false'].should include(element['disabled'])
end
end

Expand Down
8 changes: 7 additions & 1 deletion features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,17 @@
#
ActionController::Base.allow_rescue = false

# Use chrome for Selenium by default. This is because of Firefox's bug 566671
# (https://bugzilla.mozilla.org/show_bug.cgi?id=566671): any test that relies on
# blur or change events will not work when Firefox is in the background.
ENV['SELENIUM_BROWSER'] ||= 'chrome'

# Wait for AJAX requests to complete in selenium
# n.b.: Capybara 2.0 will change the way this works.
# http://groups.google.com/group/ruby-capybara/browse_thread/thread/6d955173ce413b0a/d0682d47a915dfbd
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, :resynchronize => true)
Capybara::Selenium::Driver.new(app, :browser => ENV['SELENIUM_BROWSER'].to_sym,
:resynchronize => true)
end

Before do |scenario|
Expand Down
3 changes: 2 additions & 1 deletion features/support/simultaneous_ajax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ def enable_ajax_call_refcount(driver)
# Provides an alternative selenium driver with resync off and refcounting on.
# This allows for simulation of competing AJAX requests.
Capybara.register_driver :selenium_nowait do |app|
Capybara::Selenium::Driver.new(app, :resynchronize => false, :listener => AjaxRefCountListener.new)
Capybara::Selenium::Driver.new(app, :browser => ENV['SELENIUM_BROWSER'].to_sym,
:resynchronize => false, :listener => AjaxRefCountListener.new)
end

0 comments on commit cbe83b2

Please sign in to comment.