Ruby is considered to be a very popular language used for web development. It is a very simple yet powerful language in terms of application and is supported by various online content. If you have a fair knowledge of how WebDriver works, you will have an idea to get WebDriver working using various languages and editors.
You will need the following components to create and run the WebDriver test in Ruby.
- Gecko driver proxy for Firefox
- An editor
There are different ways to install Ruby. Using Ruby as part of OSx system could be complex if you are using an older version of it. However, you can create a specific working environment using a Ruby environment manager for your own development.
Though there are different ways to do this, you can use Homebrew package manager for OSx to install Ruby environment manager, rbenv.
brew install rbenv ruby-build
You can install a specific Ruby environment using the following command.
rbenv install 2.4.1 rbenv global 2.4.1
For the test framework, you need to add RSpec.
gem install rspec
You can add WebDriver using the following commands.
gem install web driver
In order to talk to the browser, you need to add an appropriate proxy. In this case, you need Firefox proxy. Firefox’s driver is part of the releases of Mozilla’s Gecko Driver. So, you must download the driver according to the version of Windows (x32/x64). The drivers are available in zip format. Extract the zip file to a location and add the location to the system’s PATH environment variable.
Ruby’s code files are simple text files, like Java, C#, Python, and other languages. You can use any plain text editor to create and edit the .rb files. Vim, Emacs, TextMate, Sublime, etc. are some of the most common editors.
Writing and Running a Simple Test
You can simply open a new text file to create your first test in Ruby. However, the mechanism is specific to the editor being used.
For example, if you have created your test by the name webdriver_basics.rb, you can run the test using the following command from the same directory where you have created the file.
You may also like: How to use WebDriver in Python on OSx