Selenium is a popular open source functional test automation tool to test web applications. It supports multiple browsers, operating systems. It allows scripting using various programming languages like Python, Java, C#, Ruby, Perl, JavaScript etc. Java, and Python implementation of Selenium is quite popular. Ruby with Rails development of web applications is also quite popular and holds a significant market share. So it is only advisable to build your automation suite using ruby as a language.
The tagline of the ruby programming language says “It’s a Programmer’s best friend”. Ruby is also known as a tester’s language. The creator of Ruby Yukihiro Matz Matsumoto blended parts of his favorite languages (Perl, Smalltalk, Ada, Lisp and Eiffel) to form this new language. It is a completely free language to use, modify and distribute. Ruby is dynamic, interpreted, objective, general purpose programming language. Everything is an object in ruby.
One can download and setup ruby on their system from this link - https://www.ruby-lang.org/en/downloads/
Selenium, is a gem in Ruby. You can install it using the following command on your command prompt –
C:/> gem install selenium-webdriver
https://rubygems.org/gems/selenium-webdriver/versions/2.53.4
We will have a look at the following script, and see how can we automate using selenium with ruby.
a. Open the application with url – http://www.5elementslearning.com
b. Click on the my account link
c. Type in the username abc@demo.com
d. Type in the password demo@123
e. Click on the Log off link
f. Click on the Continue link.
The above script will be created in using Ruby as follows –
1. require "selenium-webdriver"
2. require "test/unit"
3. require 'rubygems'
4.
5.
6. class LoginClass < Test::Unit::TestCase
7.
8. def setup
9. Selenium::WebDriver::Chrome.driver_path = File.join(File.absolute_path('', File.dirname("D://Driverss")),"Drivers","chromedriver.exe")
10. @driver = Selenium::WebDriver.for :chrome
11. @driver.get('http://www.5elementslearning.com/demosite”)
12. @driver.manage.window.maximize
13. end
14.
15.
16. def teardown
17. @driver.quit
18. end
19.
20.
21. def test_login
31. end
The concepts of using Selenium with Ruby remains largely the same, as you may have learnt with any other programming language. The changes will be, because of the change in the language used to implement Selenium. If you have any query, please feel free to reach out.
Hope the article helped.