Selenium WebDriver Java Framework Course Limited Time Offer for $20

Selenium WebDriver Java Framework Course Limited Time Offer for $20



Selenium Ruby Web Driver Unit Test

Using Ruby WebDriver gem and unit test, we can develop automated unit test framework.  We use Mahare ePorfolio site as test example application.

Test Case

Authorized users are able to login Mahara Demo site. Here are test steps.

Test Steps

1.Navigate to and verify that web page title "Home-Mahara" displays.
2.Enter "student2" in the Username filed.
3. Enter "Testing1" in the Password field.

4.Click on the Login button
5.Assert that Logout link is present.
6.Click on the Logout link
7.Wait for login button is displayed.

Test Implementation

Open a Ruby Programming IDE and write the code below.

require 'test/unit'
require 'selenium-webdriver'

class MyTest < Test::Unit::TestCase

  # Called before every test method runs. Can be used
  # to set up fixture information.
  def setup

    #define driver for firefox webdriver
    @driver=Selenium::WebDriver.for :firefox
    #maximize the window

    #navigate to the test site ""

  def test_login
    #define username field element
    #input user name

    #define password field element
    #input password

    #define submit button element
    #click on submit button

    #wait until the Logout link displays, timeout in 10 seconds
    wait = => 10) # seconds
    wait.until {@driver.find_element(:link_text => "Logout") }

    #define logout link
    #if logout link is displayed

    puts isLogoutLinkDisplayed

    #do assertion on logout link
    assert_equal(true,isLogoutLinkDisplayed,'logout button display')


  def teardown
    #quit the driver


Execute the unit test and see the result below

Run options: --name=test_login

# Running tests:


Finished tests in 12.808733s, 0.0781 tests/s, 0.0781 assertions/s.

1 tests, 1 assertions, 0 failures, 0 errors, 0 skips

ruby -v: ruby 2.1.3p242 (2014-09-19 revision 47630) [x64-mingw32]

Process finished with exit code 0

Test Passed. You can follow the unit test example "test_login" to add other tests.