Our last post on installing Ruby, Cucumber and Watir was written in 2015. But since then, things have changed and software has been updated, so it’s time for another update!
What is Cucumber?
Cucumber is an open-source software tool that is used for test automation. It works off the concept that test cases should be captured in human language (a form of structured English called Gherkin), but automating the execution of test cases is best done in a programming language. The Cucumber tool provides the glue between the two, reporting test results in human language so that they are easily understandable to all stakeholders.
These instructions have been tested on Windows 10 64-bit, but should also work on Windows 7 and 8.1. We’ll be using the 64-bit versions of software where we can, but if you are running a 32-bit system you can install the 32-bit versions instead. But you should probably upgrade! I also assume that you have installed Firefox already, if not you can get Firefox here.
Step 1: Install Ruby
Since Windows does not have a fancy package manager installed by default, like OSX or most Linux distributions, we will have to install Ruby with the RubyInstaller that you can find here. We are going to install the 64-bit version of Ruby 2.4.2. Download the Ruby 2.4.2-2 (x64).exe file, run it, and follow these steps:
1) Click ‘I accept the License’ and click ‘Next’.
2) Make sure ‘Add Ruby executables to your PATH’ and ‘Associate .rb and .rbw files with this Ruby installation’ are selected, and click ‘Install’.
3) Let the Installer run, when it’s finished, make sure ‘Run ‘ridk install’…….’ is selected and click ‘Finish’.
4) You should get to this screen, where you can press ENTER:
5) Now you’ll get to the installer for MSYS2, which we’ll need for a couple of functions in Ruby. Click ‘Next’.
6) Click ‘Next’.
7) Click ‘Next’ and let the installer finish.
8) Once the MSYS2 installer has finished, uncheck ‘Run MSYS now.’ and click ‘Finish’.
9) Ruby is now installed.
Step 2: Install Chrome and Firefox drivers.
In order to let Cucumber and Watir start and control the browser, we have to install ChromeDriver and GeckoDriver. Watir will use ChromeDriver and GeckoDriver to load websites and perform actions on those websites. ChromeDriver will do this if we want to use the Chrome browser, and GeckoDriver will do this when we decide to use Firefox for our tests.
Step 3: Install Bundler and Lapis Lazuli
1) Start PowerShell by pressing (Windows key + R) and enter ‘powershell’ in the popup. This can also be done in Command Prompt, but here we are using PowerShell as an alternative.
2) A PowerShell window should open. Type ‘gem install bundler’ and wait until the installation is complete.
3) Now type ‘gem install lapis_lazuli –no-ri –no-rdoc’ and wait for the installation to finish.
4) You’re done!
Step 4: Create your first test suite
Now it’s time to create our first test suite!
1) Create the directory in which you want to store your Ruby projects. For example, I use C:\projects\ruby.
2) Start PowerShell like we did in step 3, and go to your newly created folder by typing ‘cd c:\projects\ruby’.
3) Now type ‘lapis_lazuli create my-first-test-suite’.
4) Lapis Lazuli has now created a new test suite for us, so go into its relevant folder with PowerShell by typing ‘cd my-first-test-suite’.
5) To run the test suite, we first have to install all of its dependencies that are specified in the ‘.gemfile’ file. We do this by typing ‘bundle install’ and waiting. This can take a few seconds, but it installs Cucumber, Watir and some more gems to your system.
6) Done! We have created our first test suite and we are able to run it by typing
‘bundle exec cucumber’. Congratulations!
As far as these installation instructions go, we’re done and you are ready to go with test automation. But if you want to learn how to use Cucumber and Watir to start automating tests for your web application, you can check out our other resources over at www.testautomation.info.