I said that I was going to lay low on automation this year. However, I was also still curious about implementing a Watir-Ruby counterpart of my existing Java-Webdriver automation framework, including an acceptance-test driven development (ATDD) or a behavior-driven development (BDD) functionality built-in, just so I can understand how different the two frameworks are, based on my own experience. Long story short, I learned how to do it, with help from Jeff Morgan’s “Cucumber & Cheese” ebook, and was surprised how easy it was to start, and eventually write code.
If you ever want to try building a Cucumber-Watir-Ruby project from scratch on a Windows machine, try this:
- Download the latest version of Ruby for your machine
- Run the installer, ticking the following options when prompted
- Install Tcl/Tk support
- Add Ruby executables to your PATH
- Associate .rb and .rbw files with this Ruby installation
- Run the command prompt, a shortcut is by pressing the Window and R keyboard buttons at the same time, typing in cmd, and then pressing Enter
- Test the Ruby installation by running ruby -v
- Close the command prompt if the Ruby version is displayed in the screen. If not, try re-installing Ruby or checking if Ruby is set in your machine’s Path under system environment variables
- Download the Ruby Development Kit for your version of Ruby
- Create a new folder under C:\ directory called devkit
- Extract the Development Kit files to the newly created directory
- Run the command prompt again
- In the command prompt, navigate to the devkit directory by running cd C:\devkit
- Once inside the directory, type in ruby dk.rb init and then press Enter
- After that, type in ruby dk.rb install and press Enter
- Then let’s install some gems by running this: gem install cucumber testgen rake bundler yard watir-webdriver page-object fig_newton
- When the gems finish installing, go back to the command prompt and run cd C:\Users\Your_Machine_Name or go to a desired directory where you want to house your automation project
- Still in the command prompt, run testgen project Project_Name –pageobject-driver=watir. This should create a new directory structure inside your project folder which cucumber will use to run your automated checks.
- Create a test_filename.feature file (without anything in it) inside your project directory
- Test if the project works by going to the project directory and then running cucumber test_filename.feature in the command prompt
If you encounter problems with a ffi_c file, such as a “cannot load such file — ffi_c (LoadError)” error, doing the following may help:
- Run gem uninstall ffi
- Then run gem install ffi –platform ruby
If the ffi_c issues persists, uninstalling the latest version of Ruby, installing an older Ruby version (say v2.1.8) and redoing Steps 3-17 may fix the problem.
Note: For a Mac or an Ubuntu machine, the Ruby and Devkit installations may differ.