Smart Contracts

Updating Solidity code and Testing a Smart Contract

Books on the Blockchain

Publica Self Publishing

Goodbye Contracting

Hello brave new old world...

Ruby-Selenium Webdriver

In under 10 Minutes

%w or %W? Secrets revealed!

Delimited Input discussed in depth.

Wednesday, 1 October 2014

Ruby Selenium-Webdriver - Quick Start

Guess how old Selenium is? If you didn't know, it's now (over) 10 years old... no really! How about Selenium 2? Well that was released in July of 2011, so it's not 'new' by any means. 

If you've not had a look at it yet, now's the time! Selenium-Webdriver will allow you to execute web tests using a range of browser easier than before. You can also use your favourite programming or scripting language and a range of other tools to enhance your testing.

As always, I'll be using Ruby on Windows for this demo and assume you have Firefox browser available - let's get going!


1. Install Ruby
To do that either read the blog post here or watch the video on YouTube:

Set-up and install Ruby


2. Check your Gems
We're going to need the selenium-webdriver gem. To install that, open a CMD window (start > run > 'cmd') and type gem install selenium-webdriver. You can check installed Gems by typing gem list which shows what's available and their version.

3. Start Interactive Ruby (IRB)
For this demo we'll just run commands straight from IRB. Using a CMD window type irb to start IRB.

In IRB type require 'selenium-webdriver' to start a webdriver instance so we can pass it commands to execute.

4.  Open the browser!
Yes, we're ready to start using Webdriver. Now type the following to invoke an instance of Firefox with the reference of browser.

browser = Selenium::WebDriver.for(:firefox)

If all is OK then Firefox will open. If you get an 'access' warning, just click OK.

5.  Run some tests
Now work through the following commands to run a basic test using Google.

Google will now load in the blank browser instance.

Type: browser.find_element(:name, "q").send_keys("Hello)
This will type 'Hello' in the query text field, but not return it.

Type: browser.find_element(:name, "btnG".click)
We'll now see search results returned.


Watch the video!

References for DYOR:


Liked this post?


Ruby Basics » Part 15 | Hashes - A Quick Intro

Welcome to the first post of the second part, in our series on Ruby Basics. To see what's coming up, check out the Trello board:


When we looked at Arrays, we saw that collections of data were stored under a given Array name. These were accessed by knowing the integer value of the data item’s location in the array. If you recall in the Basics 1 Wrap Up, we had the following Array:

        rolesArray = ["Developer", "Tester"]

To access these we need to use [0] and [1], as in

        print rolesArray[0]
Later on we assigned David or Alan as one of these roles and this worked fine. But what if we now wanted to assign them individual salaries, periods of employment, holidays allocated or other relevant data. We could create Arrays and put the data in the same sequence as the employee array. For example we might set-up:

rolesArray = ["Developer", "Tester"]
rolesHolder = ["Dave", "Alan"]
rolesSalary = [40000, 35000]
rolesHoliday = [25, 25]
I’m guessing you can see that’s all well and good if everything stays in order. For those with a little Database knowledge this problems with the above approach scream even louder. What we need is a way to explicitly pair the data above with a key bit of data that won’t change. In this case that key bit of data is the employee name.  How can we label the various bits of data with the employee name?

What we need is a key --> value pairing of data, so no matter what order they are stored, we can find, edit, update, and delete the correct one. As luck (Ruby) would have it, what we need is a Hash.


A Hash is a collection of Key-Value pairs. Hashes are also referred to as associative arrays, maps and dictionaries. They’re like Arrays in that they’re still variables storing variables, however unlike Arrays the data isn’t stored in a particular order. Also unlike Arrays, we don’t push/pop data into and out of the Hash, we simply insert and delete Hash values. Let’s look at making a Hash for some of the above data.

We can make a new empty Hash in a similar way to a new empty Array;

        rolesHash =

If we print the above, of course nothing will be returned. As we then acquire data to add to it, we can insert the data by giving the key-value pairs:

        rolesHash["David"] = "Developer"

Try running the entire snippet below:

rolesHash =
puts rolesHash

rolesHash["David"] = "Developer"
rolesHash["Alan"] = "Tester"

puts rolesHash

Here we add two key-value pairs to our newly created Hash and print the entire Hash out, which looks something like this:

        {"David"=>"Developer", "Alan"=>"Tester"}

If we wanted to find out what role David was currently in we could look it up using the key:

                    puts rolesHash["David"]

If you try this with a name that is not in the Hash, then the result will be nil which isn’t very informative. A better way is to define a default value, for example:

                    rolesHash ="No Role Assigned")

Try it again and watch the default message get printed.

Adding to the Hash is good, but we also need to delete items too. To do this we simply call the delete method on the hash and specify which key we want deleting.


If you’d prefer to just build out your Hash from the start, you can do that too.

salaryHash = Hash["David" => 30000, "Alan" => 35000]
puts salaryHash

We’ll leave the basics of Hashes there, as always have a look at the Ruby docs to see more of the methods available. Later on, we’ll look at some of the more complex aspects of Hashes, but for now we have what we need!