Ruby code example using Selenium Grid

This Ruby code example will get you a quick start using a selenium grid to run a single test

Install the latest selenium client version equivalent to your selected selenium grid version. Example: If you selected to use selenium version 2.53.1 for your selenium grid, install the latest 2.53.x for Ruby.

gem install selenium-webdriver -v 2.53.x
Note: starting from selenium version 3.9.1 you must also include "platformName": "windows" in the request when testing with firefox and IE.

require "selenium-webdriver" 

# If the requested test environment is not registered with the hub
# or busy, allow enough time for the Gridlastic auto scaling
# functionality to launch a node with the requested environment.
client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = 600 # seconds.  

caps = Selenium::WebDriver::Remote::Capabilities.chrome(
:version               => "latest",
:platform              => "VISTA",
:platformName          => "windows",
:video                 => "True"
)
driver = Selenium::WebDriver.for(:remote, :url => "http://USERNAME:ACCESS_KEY@SUBDOMAIN.gridlastic.com:80/wd/hub", :http_client => client, :desired_capabilities => caps)
driver.manage.timeouts.implicit_wait = 60 # seconds
driver.manage.window.maximize # If Linux always set window size like driver.manage.window.size = Selenium::WebDriver::Dimension.new(1920, 1080)

begin
print 'Video: ' + VIDEO_URL + driver.capabilities['webdriver.remote.sessionid']

driver.navigate.to "https://www.google.com/ncr"
element = driver.find_element(:name, 'q')
element.send_keys "Hello WebDriver!"
element.submit
ensure
driver.quit
end

The Gridlastic hub endpoint and the video url used in this code example is displayed after launching your Gridlastic selenium grid. See documention Selenium Grid Configuration Parameters where to find these credentials and replace with your own.

NOTE: Gridlastic auto scaling requires all 3 test environment parameters platform, browser and browser version to be specified in each request in order to launch test nodes to fulfill test demand. Video recording is optional. See test environments for capabilities options.
It is important to ensure that "driver.quit" is always called for proper test execution and creation of video recordings of failed tests.