Complete Setup Guide for Ruby, Cucumber and Watir on Windows
This is an updated version of our previous post on getting a cucumber installation set up on Windows. It has become one of the most popular resources for this on the web, but has aged a little since we published it in 2011.
With this updated guide, we’d like to kick off a new round of cucumber-related blog posts.
What is Cucumber?
Cucumber is an Open Source software tool for test automation. Its basic concept is 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 the human language again.
Cucummber, and thus Gherkin, is compatible with our test results reporting dashboard Calliope.pro. Have a look at the video explaining Calliope at the bottom of this post or head to Calliope.pro now.
The next post in the series will provide an introduction to basic cucumber concepts.
We’ll start this round of cucumber posts with installation instructions so you can follow the next posts as you read them.
After following these instructions, you will have installed cucumber, as well as Watir, a convenient wrapper around the industry leading Selenium browser automation framework, as well as Ruby, the programming language of choice for cucumber test automation. With all three combined, we can test web applications as demonstrated in a later post.
These instructions have been tested on Windows 7 and Windows 8, with both 32bit and 64bit installations. Additionally, Ruby versions 2.0, 2.1 and 2.2 have been used for these instructions.
32bit vs. 64bit
All of the software packages we’re about to install run on 32bit Windows and 64bit Windows, with one small caveat: on 64bit Windows, cucumber will produce warnings about a missing “gherkin lexer”, but otherwise work just fine. If such warnings irritate you, you can work around them with some deeper knowledge of native Ruby gems. Otherwise, we recommend sticking to 32bit packages.
Step 1: Install Ruby
In main installer window, you have four choices to make:
- The installation path. We’re going to use
C:\Rubyin this example rather than using a version-specific installation path. Whenever you see
C:\Ruby, pick the installation path you chose here.
- Whether to install Tcl/Tk support. This is not required for cucumber.
- Whether to add Ruby executables to your path. This is required for the rest of these posts to work well.
- Whether to associate certain files with this Ruby installation. If you have only one version of Ruby installed, this is recommended.
Step 2: Extract DevKit
DevKit is required for some Ruby packages (called “gems”) to be installed. It can be downloaded from the same downloads page. Note that for Ruby 2.0, 2.1 and 2.2, the same version can be used. We’re using 32bit DevKit here.
The executable is just a self-extracting archive. You can extract the archive anywhere you want, but we’ll use
Step 3: Install DevKit
Once DevKit is extracted, you need to go to the Windows Command Console to install it.
- Run a command by pressing the Windows key and the R key.
- Write “cmd” into the input field.
- Hit enter.
In the command console, go to the DevKit installation path,
C:\Ruby\devkit, and enter two commands to finish the DevKit installation.
C:\Users\you> cd \Ruby\devkit C:\Ruby\devkit> ruby dk.rb init C:\Ruby\devkit> ruby dk.rb install
Step 4: Install Cucumber and other Ruby gems
Now you’ve got your system set up for Ruby to download and install “gem” packages. To install cucumber, first update the current gem setup:
C:\Users\you> gem update --system
Next, install the gems you need for cucumber web testing. We recommend at least the following:
C:\Users\you> gem install --no-ri --no-rdoc rspec C:\Users\you> gem install --no-ri --no-rdoc win32console C:\Users\you> gem install --no-ri --no-rdoc watir-webdriver C:\Users\you> gem install --no-ri --no-rdoc cucumber
You can also install multiple packages in a single command, e.g.
C:\Users\you> gem install --no-ri --no-rdoc rspec cucumber
Step 5: Run Cucumber
At this point, you should be able to execute cucumber and watch it complain about not having tests to run.
C:\Users\you\Documents> cucumber No such file or directory - features. You can use `cucumber --init` to get started.
Let’s do what cucumber suggests, shall we?
C:\Users\you\Documents> cucumber --init create features create features/step_definitions create features/support create features/support/env.rb
We’ll explain all the stuff that gets created here later. Right now, if we run cucumber again now, it’ll complain a lot less:
C:\Users\you\Documents> cucumber 0 scenarios 0 steps 0m0.000s
And there you have it! Cucumber runs zero test scenarios containing zero steps, in zero seconds. That seems about right for a fresh installation!
Step 6: Install Bundler
Installing Ruby gems via the
gem command is generally the way to install packages system-wide. If you work a lot on test automation suites, though, it’s quite likely that you want different versions of each package for different projects. For this purpose, the Ruby community has come up with bundler, which we thoroughly recommend to use in your test automation projects.
C:\> gem install bundler
We’ll discuss the use of bundler in later posts, but for now you should just install it so we can refer to it later.
Now that you’ve got Cucumber up and running and you are running test automation scripts, its time to consider how you will manage and make sense of your test results. Performing automated tests can quickly become unmanageable without maintaining a clear overview of your test results. Calliope is tools agnostic, meaning it will work with any testing tools or frameworks you use. Give it a try for free now!