WTA with Ruby - Install and prepare
In the previous blogpost I explained the concepts of a test automation
framework and which one I particularly like and want to share with you. In
this blogpost we'll start to get our hands dirty by installing all
necessary software so we can start with the fun. Keep in mind I'm writing
this guide while working on a Windows computer, so it might be that you need to
do some research for your OS if your following this guide while working on OSX
or Linux.
Browsers
I'm not
going to explain how to install a browser. But it's recommended to pre-install
Firefox so it does not matter on what kind of OS you're working, you could
still follow most of the instructions later on. And I'll start with the Firefox
browser in the first test run. Other browsers will be covered later. So you can
install them now or when we're getting there, that's up to you.
Ruby
Let's
start with the installation of Ruby. My instructions will be similar if
not identical from the Windows installation instructions that you can find on the testautomation.info website (minus the pictures). I went for
the 32 bit version of Ruby because when I installed the software, that was
the most stable version at that time. You can install the 64-bit version if you
want, just keep in mind that if there are issues try the 32-bit version.
- Download Ruby version 2.3.x on https://rubyinstaller.org/downloads/
- Accept the terms and conditions
- Just leave the default folder as is
- e.g. Ruby version 2.3 (32 bit) will be installed in C:\Ruby23
- e.g. Ruby version 2.3 (64 bit) will be installed in C:\Ruby23-x64
- Check all 3 checkboxes (this one is important, don't skip it)
- And complete the installation
Devkit (required for Ruby 2.3 and below)
In
addition to Ruby we also need to install devkit. If during the Ruby
installation you did not check the setting to add ruby to your PATH, you can
still do this manually first (see Known Error section below) or in step 6 and 7
you need to go to the ruby folder first before you can execute those commands.
- Download and open the latest Devkit for Windows 64 bit on https://rubyinstaller.org/downloads/
- In your ruby directory create a new Folder with the name: devkit
- Extract the Devkit download into the newly created folder
- Open command prompt
- In CMD go to your ruby directory `cd c:\ruby23\devkit`
- Write ruby `dk.rb init`
- Write `ruby dk.rb install`
- The installation is completed
Webdrivers
Let's
not forget about the webdrivers. Without them our setup doesn't do anything.
Each browser needs it's own webdriver. Links to the downloads you can find on
the Watir website, on the Selenium website, or just find them yourself (Everyone
know how to Google right?). Which version you need depends on the browser
version you’re on. Since you just started, make sure all browsers are on the
latest version they can be, then it's safe to assume the latest webdriver works
for you. Unpack/unzip these downloads into the Ruby bin folder since the
bin folder is already in the PATH environment variables of Windows.
Ruby gems - lapis_lazuli does all the work
First
make sure we have Ruby up and running.
Open
CMD and type `ruby --version`
Then
make sure we're completely up to date `gem update –system
Now
install the lapis_lazuli gem `gem install lapis_lazuli`
This
gem makes life easy. It will take care of installing cucumber,
selenium-webdriver and water gems, among other needed gems, so all tools,
frameworks and webdriver bindings are ready to be used. A deeper explanation of
lapis_lazuli will follow in the next blogpost.
Make sure it all works
Open a
CMD window and start `irb` followed by an ENTER.
Type
the following commands and see the browser open, navigate to a website and
close.
`require
‘lapis_lazuli’`
`include
LapisLazuli`
`browser.goto
“service-hub.com”`
This
will open Firefox and navigate to the website
`browser.title`
Shows you the current title of the website
`browser.quit`
Closes the browser
Ansicon
Additional, but not mandatory, I've downloaded and installed ANSICON (from Github) to get some colors when you make use of the Cucumber command later on in this guide. It works perfect without as well, so it's up to you if you want it or not.Known Error
No webdriver, webdriver not in ruby's bin folder, bin folder is not in PATH or you decided you want the drivers somewhere else and that folder is not in the PATH environment variable, this is what you'll see:"Selenium::WebDriver::Error::WebDriverError: Unable to find Mozilla geckodriver. Please download the server from https://github.com/mozilla/geckodriver/releases and place it somewhere on your PATH. More info at https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver"
There are so many ways to add this. If you like the command prompt of powershell go ahead. But you can also use the GUI, check this site https://www.computerhope.com/issues/ch000549.htm
Make sure the Ruby bin folder is in there and the driver is unpacked/unzipped in that folder.
For some reason the formatting keeps on going back to smaller letters. I'll try to fix it tonight.
ReplyDeleteFormat keeps on looking weird. I'll switch to another blog as soon as I've time to convert them all
ReplyDelete