Introduction
This article describe how to add chromedriver and run test case to test multiple browsers in Selenium.
Note:
Environment: Ubuntu 14.04, Rails 4.1
Pre-Request
Make sure you have set up Selenium correctly
Rails, minitest and Selenium
Steps:
1. Download and install google chrome
2. Download and extract chromedriver from
http://chromedriver.storage.googleapis.com/index.html
3. Create a softlink to the extract chromedriver
# create soft link # change /your/home/ as needed sudo ln -s /your/home/Downloads/chromedriver /usr/bin/chromedriver
4. edit SeleniumTest/test/test_helper.rb
to declare browser array
# other code @@browsers = [:firefox, :chrome] # other code def self.browsers @@browsers end
5. generate a new test case
# generate test case bin/rails generate integration_test add_chrome_driver
6. write test case to test firefox and chrome in one method
require "test_helper" class AddChromeDriverTest < ActionDispatch::IntegrationTest def test_sanity ActiveSupport::TestCase.browsers.each do |browser| driver = Selenium::WebDriver.for browser driver.navigate.to "http://google.com" element = driver.find_element(:name, 'q') element.send_keys "Hello WebDriver!" element.submit puts driver.title sleep 2 # quit driver, close browser window driver.quit end end end
7. then run test cases
# run test cases rake test
References:
(get correct path from)
https://github.com/watir/watirbook/blob/master/manuscript/installation/ubuntu.md#chrome
(choose soft link instead of move file because)
https://code.google.com/p/selenium/wiki/ChromeDriver
Added / Updated Files:
SeleniumTest/test/test_helper.rb
SeleniumTest/test/integration/add_chrome_driver_test.rb
No comments:
Post a Comment