Selenium with Ruby
If you prefer to run your Selenium tests using Ruby, clone the repository, or select and make use of one of the sample tests below to see our platform in action.
info
All the scripts below makes use of the grid access key. In order to run the test do the following
- Get your access key
- Replace it with <YOUR ACCESS KEY>, in the sample tests below.
info
Replace <server> with the appropriate URL.
- Public Continuous Testing Cloud - https://cloud.seetest.io/wd/hub/.
- Dedicated Continuous Testing Cloud environment - Your own domain. For example: https://company.experitest.com/wd/hub/
- On-premises Continuous Testing Cloud environment - Your designated URL. For example: https://company.com/wd/hub
Chrome with Ruby Expand source
require 'test/unit'
require 'selenium-webdriver'
# require 'selenium/webdriver/remote'
class Example < Test::Unit::TestCase
def setup
desired_caps = {
:testName=> 'Running Selenium on Chrome',
:platform=> 'ANY',
:browserName=> 'chrome',
javascript_enabled: true,
css_selectors_enabled: true,
# In order to use the grid code generation, you need to be connected to the cloud
:accessKey=> '<YOUR ACCESS KEY>'
}
@driver = Selenium::WebDriver.for(:remote, :url => '<server>', :desired_capabilities => desired_caps)
end
def test_selenium_on_chrome
@driver.navigate.to "https://seetest.io"
wait = Selenium::WebDriver::Wait.new(:timeout => 10)
wait.until{@driver.find_element(:xpath => "//*[text()='Manual']")}
manual_nav_link = @driver.find_element(:xpath, "//*[text()='Manual']")
manual_nav_link.click
automation_nav_link = @driver.find_element(:xpath, "//*[text()='Automation']")
automation_nav_link.click
webinar_footer_link = @driver.find_element(:xpath, "//*[text()='Webinars']")
webinar_footer_link.click
webinars_h2_title_text = @driver.find_element(:xpath, "//h2[1]").text
puts("The title of the first h2 is: " + webinars_h2_title_text)
end
def teardown
@driver.quit
end
end
Firefox with Ruby Expand source
require 'test/unit'
require 'selenium-webdriver'
# require 'selenium/webdriver/remote'
class Example < Test::Unit::TestCase
def setup
desired_caps = {
:testName=> 'Running Selenium on Firefox',
:platform=> 'ANY',
:browserName => 'firefox',
javascript_enabled: true,
css_selectors_enabled: true,
# In order to use the grid code generation, you need to be connected to the cloud
:accessKey=> '<YOUR ACCESS KEY>'
}
@driver = Selenium::WebDriver.for(:remote, :url => '<server>', :desired_capabilities => desired_caps)
end
def test_selenium_on_firefox
@driver.navigate.to "https://seetest.io"
wait = Selenium::WebDriver::Wait.new(:timeout => 10)
wait.until{@driver.find_element(:xpath => "//*[text()='Manual']")}
manual_nav_link = @driver.find_element(:xpath, "//*[text()='Manual']")
manual_nav_link.click
automation_nav_link = @driver.find_element(:xpath, "//*[text()='Automation']")
automation_nav_link.click
webinar_footer_link = @driver.find_element(:xpath, "//*[text()='Webinars']")
webinar_footer_link.click
webinars_h2_title_text = @driver.find_element(:xpath, "//h2[1]").text
puts("The title of the first h2 is: " + webinars_h2_title_text)
end
def teardown
@driver.quit
end
end
Internet Explorer with Ruby Expand source
require 'test/unit'
require 'selenium-webdriver'
# require 'selenium/webdriver/remote'
class Example < Test::Unit::TestCase
def setup
desired_caps = {
:testName=> 'Running Selenium on IE',
:initialBrowserUrl=> 'https://seetest.io',
:platform=> 'ANY',
:browserName=> 'internet explorer',
javascript_enabled: true,
css_selectors_enabled: true,
# In order to use the grid code generation, you need to be connected to the cloud
:accessKey=> '<YOUR ACCESS KEY>'
}
@driver = Selenium::WebDriver.for(:remote, :url => '<server>', :desired_capabilities => desired_caps)
end
def test_selenium_on_ie
@driver.navigate.to "https://seetest.io"
wait = Selenium::WebDriver::Wait.new(:timeout => 10)
wait.until{@driver.find_element(:xpath => "//*[text()='Manual']")}
manual_nav_link = @driver.find_element(:xpath, "//*[text()='Manual']")
manual_nav_link.click
automation_nav_link = @driver.find_element(:xpath, "//*[text()='Automation']")
automation_nav_link.click
webinar_footer_link = @driver.find_element(:xpath, "//*[text()='Webinars']")
webinar_footer_link.click
webinars_h2_title_text = @driver.find_element(:xpath, "//h2[1]").text
puts("The title of the first h2 is: " + webinars_h2_title_text)
end
def teardown
@driver.quit
end
end