LambdaTest ● Automation Testing ● Quick Guide To Run Ruby Tests On LambdaTest Selenium Grid

Quick Guide To Run Ruby Tests On LambdaTest Selenium Grid

LambdaTest Selenium Automation Grid is a secure, scalable, and reliable Selenium Grid on cloud that can help you run your Ruby automation scripts on 2000+ different browsers and operating system environments. The grid is specifically built for high performance and gives you not only a greater browser coverage but also an ability to run automation tests in parallel. This helps you reduce your automation test execution time significantly. This post will help you quickly get started with running Ruby test scripts on LambdaTest Selenium Grid.

Prerequisites

First, you would have to install Ruby and gem on your local system. We recommend installing the latest version of Ruby. Installing these platforms is a little different in each operating system

For windows, you can download the latest installed the official website.

If you are using Linux or Ubuntu OS, you can run a simple apt command like below. You can also refer to this doc to know more about which command suits your OS better.

$ sudo apt-get install ruby-full 1 $ sudo apt - get install ruby - full If you are using MacOS you can run a homebrew command like this $ brew install ruby 1 $ brew install ruby

Installing Selenium Dependencies For Ruby

Once you have ruby and gem setup, you would now have to install Selenium dependencies. You can install Selenium via simple gem command

gem install selenium-webdriver 1 gem install selenium - webdriver

Sample Ruby and Selenium Test To Get You started

Once you have installed necessary dependencies, you are all set to run your Ruby automation scripts on LambdaTest Selenium grid. To get started you can try out the code below. It’s a simple Ruby scripts that opens up Google.com, search LambdaTest in Google search, and then output the title of the search result page. You can also fork it from our Ruby GitHub repository here.

//Sample Ruby and Selenium Automation Script require 'selenium-webdriver' require 'test/unit' class LtTest < Test::Unit::TestCase """ LambdaTest selenium automation sample example Configuration ---------- username: Username can be found at automation dashboard accessToken: AccessToken can be generated from automation dashboard or profile section Result ------- Execute Ruby Automation Tests on LambdaTest Distributed Selenium Grid """ def setup """ Setup remote driver Params ---------- platform : Supported platform - (Windows 10, Windows 8.1, Windows 8, Windows 7, macOS High Sierra, macOS Sierra, OS X El Capitan, OS X Yosemite, OS X Mavericks) browserName : Supported platform - (chrome, firefox, Internet Explorer, MicrosoftEdge) version : Supported list of version can be found at https://www.lambdatest.com/capabilities-generator/ Result ------- """ username= "{username}" accessToken= "{accessToken}" gridUrl = "hub.lambdatest.com/wd/hub" caps = { :browserName => "chrome", :version => "67.0", :platform => "win10", :name => "LambdaTest ruby google search name", :build => "LambdaTest ruby google search build", :network => true, :visual => true, :video => true, :console => true } puts (caps) # URL: https://{username}:{accessToken}@hub.lambdatest.com/wd/hub @driver = Selenium::WebDriver.for(:remote, :url => "https://"+username+":"+accessToken+"@"+gridUrl, :desired_capabilities => caps) end def test_Login """ Setup remote driver Params ---------- Execute test: navigate google.com search LambdaTest Result ------- print title """ puts("Searching LambdaTest on google.com ") sleep(15) @driver.get("https://www.google.com/ncr") elem = @driver.find_element(:name, 'q') elem.send_keys("LambdaTest.com") elem.submit() puts("Printing title of current page :"+@driver.title) end def teardown """ Quit selenium driver """ @driver.quit end end 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 //Sample Ruby and Selenium Automation Script require 'selenium-webdriver' require 'test/unit' class LtTest < Test :: Unit :: TestCase "" " LambdaTest selenium automation sample example Configuration ---------- username: Username can be found at automation dashboard accessToken: AccessToken can be generated from automation dashboard or profile section Result ------- Execute Ruby Automation Tests on LambdaTest Distributed Selenium Grid " "" def setup "" " Setup remote driver Params ---------- platform : Supported platform - (Windows 10, Windows 8.1, Windows 8, Windows 7, macOS High Sierra, macOS Sierra, OS X El Capitan, OS X Yosemite, OS X Mavericks) browserName : Supported platform - (chrome, firefox, Internet Explorer, MicrosoftEdge) version : Supported list of version can be found at https://www.lambdatest.com/capabilities-generator/ Result ------- " "" username = "{username}" accessToken = "{accessToken}" gridUrl = "hub.lambdatest.com/wd/hub" caps = { : browserName = > "chrome" , : version = > "67.0" , : platform = > "win10" , : name = > "LambdaTest ruby google search name" , : build = > "LambdaTest ruby google search build" , : network = > true , : visual = > true , : video = > true , : console = > true } puts ( caps ) # URL: https://{username}:{accessToken}@hub.lambdatest.com/wd/hub @ driver = Selenium :: WebDriver . for ( : remote , : url = > "https://" + username + ":" + accessToken + "@" + gridUrl , : desired_capabilities = > caps ) end def test _ Login "" " Setup remote driver Params ---------- Execute test: navigate google.com search LambdaTest Result ------- print title " "" puts ( "Searching LambdaTest on google.com " ) sleep ( 15 ) @ driver . get ( "https://www.google.com/ncr" ) elem = @ driver . find_element ( : name , 'q' ) elem . send_keys ( "LambdaTest.com" ) elem . submit ( ) puts ( "Printing title of current page :" + @ driver . title ) end def teardown "" " Quit selenium driver " "" @ driver . quit end end

Here’s how you can execute the test from your terminal.

ruby google-search-lambdatest.rb 1 ruby google - search - lambdatest . rb

The first thing to note in this code is the use of remote webdriver. To access LambdaTest grid, you would have to invoke remote webdriver instead of local webdrivers. In addition, the browser enthronement details are passed on through desired_capabilities.

In this example we are running a test on Windows 10, Chrome 67 environment. You can test your own choice of an environment by changing the parameters in the object. You can leverage our capabilities generator tool to create code for your environments.

LambdaTest Capability Generator Tool