How do I use Selenium with Ruby?

SeleniumAutomation TestingTesting Tools

We can use Selenium with Ruby. First of all we have to install Ruby in the system. For installation in Windows, we have to take the help of the RubyInstaller package by navigating to the link −

https://rubyinstaller.org/

Click on Download.

The various versions of Ruby Installers links get displayed. Select the latest version and click on it.

Click on the Save File button to download the corresponding rubyinstaller.exe file.

Once the download is completed, accept the license agreement and proceed to the next steps till installation is completed.

To have Selenium webdriver package for Ruby, run the command −

gem install selenium−webdriver

To have Rest−Client package for Ruby, run the command −

gem install rest−client

To have test−unit package for Ruby, run the command −

gem install test−unit

Example

#set webdriver gem for Selenium
require "selenium−webdriver"
require "rubygems"
#driver object creation
driver = Selenium::WebDriver.for :chrome
#launch browser
driver.navigate.to "https://www.tutorialspoint.com/index.htm"
#close browser
driver.close
raja
Published on 02-Feb-2021 12:38:22
Advertisements