Introduction
This article describe how to use Remote WebDriver to run Web Driver on remote machine.
Note:
Environments:
Test Machine - Ubuntu 14.04, rails 4.1
Remote Server - Windows 8.1, IE11
Pre-Request
Make sure you have set up Selenium correctly
Rails, minitest and Selenium
Steps
On the remote server (e.g., windows 8.1 NB)
0. make sure Java JRE is installed
1. Download selenium-server-standalone-2.46.0.jar from
http://selenium-release.storage.googleapis.com/index.html
selenium-server-standalone-2.46.0.jar
2. Download and extract chrome driver and IE driver
chrome driver
http://chromedriver.storage.googleapis.com/index.html
chromedriver_win32.zip
IE driver
http://selenium-release.storage.googleapis.com/index.html
IEDriverServer*.zip
Note:
Basically you should choose 32 bit or 64 bit version of IE Driver according to your OS version, but you can try to switch version if you find send_keys pretty slow.
3. Open console, run selenium-server-standalone-2.46.0.jar by
# update path/filename as needed java -jar -Dwebdriver.ie.driver="D:/things/Downloads/IEDriverServer.exe" -Dwebdriver.chrome.driver="D:\things\Downloads\chromedriver.exe" D:\things\Downloads\selenium-server-standalone-2.46.0.jar
4. Make sure that Internet Options → Security has the same Protected Mode setting (on or off, it doesn't matter as long as it is the same value) for all zones.
On the testing machine (Ubuntu 14.04 this case)
1. Add remote browsers to test_helper.rb
# Capabilities for IE driver iecaps = Selenium::WebDriver::Remote::Capabilities.internet_explorer # need to ignore zoom or it will # complain zoom is 250% but it should be 100% # on IE11/Windows 8.1 iecaps["ignoreZoomSetting"] = true; # ... @@remoteBrowsers = [ { "url" => "http://192.168.31.169:4444/wd/hub", "desired_capabilities" => iecaps}, # assume also want to test remote chrome { "url" => "http://192.168.31.169:4444/wd/hub", "desired_capabilities" => :chrome }, ] # ... def self.remoteBrowsers @@remoteBrowsers end
2. Generate test case
bin/rails generate integration_test remote_webdriver
3. Write test case
require "test_helper" class RemoteWebdriverTest < ActionDispatch::IntegrationTest def test_sanity ActiveSupport::TestCase.remoteBrowsers.each do |remoteBrowser| driver = Selenium::WebDriver.for(:remote, :url => remoteBrowser["url"], :desired_capabilities => remoteBrowser["desired_capabilities"]) doTest(driver) end end def doTest (driver) 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 end4. Run test case
rake test test/integration/remote_webdriver_test.rb
References
Selenium wiki RubyBindings
InternetExplorerDriver Zoom Level Error - Stack Overflow
How to set path for IE driver for a remote machine while using remotewebdriver from the code
Updated / Added Files
test_helper.rb
remote_webdriver_test.rb
No comments:
Post a Comment