10-Minute Guide to Set up Test Automation using Selenium WebDriver with Ruby
Set up your computer to run Selenium WebDriver tests in Chrome
In my one-day Selenium training, I suggest the attendants use the TestWise Ruby edition which bundles a Ruby (Windows) distribution. I want the attendants (most of them are new to test automation) to run/write a Selenium test as quickly as possible, in minutes. However, I emphasize that it is important to set up an automated test execution environment where you can run tests from the command line.
In this article, I will show you how to set up your machine to run raw Selenium WebDriver (Ruby) tests quickly, with 100% free, open-source software.
Table of Contents
∘ 1. Install Ruby (~2 mins)
∘ 2. Install Essential Gems (~1 to 6 mins)
∘ 3. Install Testing Gems (~1 min)
∘ 4. Install ChromeDriver (~ 1 minute)
∘ 5. Verify Test Execution
∘ Next Steps
1. Install Ruby (~2 mins)
Ruby is a popular scripting language and pre-installed in macOS and some Linux distributions. In my opinion, Ruby is the best scripting language for test automation. Here I will cover Ruby installation for Windows, which requires more effort than that for Mac/Linux.
Info: GitHub, AirBNB and many other well-known web sites are written in Ruby.
Download RubyInstaller for Windows with Devkit, such as ‘Ruby+Devkit 2.7.6–1 (x64)’, and run the installer.
(I suggest getting the latest stable version. The ruby version shown in the following screenshots is 2.6.8, the installation process is the same for all versions.)
Important! Ensure the DevKit is selected (see the screenshots below) in the installation process. The DevKit is required for compiling certain libraries (called Gem in Ruby). You can also find a tutorial video (45s) here.
The installation will take a while, about 2–3 minutes. (you may perform Step 4 and a part of Step 5 during the wait)
Verify the installation, and run the command in a Command Window.
ruby -v
The output will be like this:
Step 2–5 are the same for all platforms: Windows, macOS and Linux.
2. Install Essential Gems (~1 to 6 mins)
The libraries in Ruby are called ‘gems’. Installing a gem is easy. Run the below command in a new command window:
gem install bundler --no-document
This installs thebundler
gem, a common Ruby gem to manage dependencies of the application’s gems. We might not need to use it yet, but will need it for setting up Continuous Testing. --no-document
is optional: to save time by skipping installation documentation.
If you encounter some issues (Windows only) later, try running the commands below:
gem install ffi --platform=ruby --no-document
This gem must be compiled (using DevKit) to work on your machine. This will take about 5 minutes. You can install ChromeDriver (step 4) while waiting for this to complete.
3. Install Testing Gems (~1 min)
Now install the gems for test automation. Firstly, the best automation framework: is Selenium WebDriver.
gem install --no-document selenium-webdriver
The current stable Selenium version is 4.0.3. If you want a specific version, supply the version number below:
gem install --no-document selenium-webdriver --version 3.142.7
Then the best test syntax framework: RSpec. (Note: RSpec is the first and most popular BDD framework. It is far better than Cucumber. As a comparison, RSpec v3.8 download count: 196,569,068; Cucumber v5.3 (highest) download count: 554,695).
gem install --no-document rspec
We can install multiple Gems in one go. The commands below will help install some common helper libraries.
> gem install --no-document activesupport faker
Examples of using the above two in test scripts:
5.days.ago # ActiveSupport provides easier syntax
Faker::Internet.email # Faker generates test data
4. Install ChromeDriver (~ 1 minute)
To run Selenium WebDriver tests against the Chrome browser besides the Chrome browser itself, you need to install ChromeDriver. Download and put it into a folder in your PATH, e.g.C:\Ruby26-x64\bin
.
To verify the installation, open a command window (terminal for Unix/Mac), execute the command chromedriver --version
. You shall see output like the below:ChromeDriver 92.0.4515.43
You can find a tutorial video (42s) here.
Please note that the version of ChromeDriver shall match your Chrome browser’s version. ChromeDriver works with its version and version+1 Chrome browsers. For example, ChromeDriver v91 will work fine with Chrome v91 and v92, but not v93 with the following text in the test output:
The version of ChromeDriver only supports Chrome version 91
Current browser version is 93
So test automation engineers must add “chromedriver update” as a regular (about every 2 or 3 months) task.
5. Verify Test Execution
Run the commands below to get a set of sample Selenium WebDriver tests. Please read “10-Minute Guide to Git Version Control for Testers” if you are unfamiliar with Git.
> cd c:\demo
> git clone https://github.com/testwisely/agiletravel-ui-tests.git
Now run a sample RSpec test.
> cd C:\demo\agiletravel-ui-tests\selenium-webdriver-rspec
> rspec spec\login_spec.rb
You shall see test execution in a Chrome browser. The output in the command window:
Next Steps
Switch to TestWise Standard Edition
If you have installed the TestWise Ruby edition, uninstall it. TestWise IDE is independent of the test execution environment. In other words, it will use Ruby (or Python or Nodejs) on your machine. This gives users maximum flexibility. TestWise is just a test automation tool, testers should not depend on it. I am saying this as the creator of TestWise and a professional test automation engineer. Test Automation engineers must make sure their test scripts can be run from the command line, with no vendor locking.
The installer for TestWise standard edition (Windows) is also much smaller, only 5.4MB.Set up BuildWise Continuous Testing Server
Testing IDE is for developing/refining/debugging individual test scripts. To run a suite of tests, you shall do it in a Continuous Testing server, such as BuildWise. BuildWise Server and BuildWise Agents (for parallel execution) require the setup of test execution(like you just did).
Check out this article: “Set Up a Continuous Testing Server to Run Selenium Tests in Minutes”.