How much Ruby should you know to get started?
Learning how to define functions and classes in Ruby should be sufficient to get started. Check out the excellent open source course,
Ruby for Testers for a quick, concise introduction to Ruby.
Writing a test
The structure of a typical Frankenstein test is as follows:
#Include the Frankenstein driver module.
require 'frankenstein_driver'
#The test class name will be displayed in the report
class YourTest
include FrankensteinDriver
#All Frankenstein tests need to define a 'test' method
def test
#Steps go here
end
end
Extracting functions
A series of logical steps can be grouped together into functions.
For example, a test may start off looking like this:
class LoginTest
include FrankensteinDriver
def test
enter_text "login" , "foo"
enter_text "password", "bar"
click_button "login"
# Remaining steps
...
end
end
This test could be refactored as follows:
class LoginTest
include FrankensteinDriver
def test
login("foo","bar")
# Remaining steps
...
end
def login(username,password)
#Parameterize the username
enter_text "login" , "#{username}"
#Parameterize the password
enter_text "password", "#{password}"
click_button "login"
end
end
Refactoring logical chunks of a user's workflow into functions allow you to create a test library. The library
can then be used to create new tests. As the application evolves, changes to a specific workflow will
require localized changes to a test library function, and will avoid having to make drastic changes to your test scripts.
In other words, creating a library of test functions at the right level of abstraction can significantly reduce maintenance effort.
For example, let's see what happens if the login process changes slightly - a change to the user interface adds a new checkbox
called 'Remember Me'. As part of the testing strategy, we may want to ensure that this button is never selected.
The login function we defined above would now change to:
def login(username,password)
#Parameterize the username
enter "login" , "#{username}"
#Parameterize the password
enter "password", "#{password}"
click_checkbox "Remember Me" , "false"
click_button "login"
end
Regular expression support
Most of the driver functions support regular expressions. Please refer to the driver documentation for more.
Driver reference
The Frankenstein driver documentation is here
Running tests in a suite
The TestRunner can be used to run multiple tests:
TestRunner.new.run < comma separated list of tests >
For example, if you'd like to run two tests, which are in classes named TestOne and TestTwo:
TestRunner.new.run TestOne,TestTwo
Changing the reporting directory
To change the directory where reports are generated, add a line in your test script:
FrankensteinDriver.report_dir="C:\your\report\dir"
Ruby references
Check out http://www.ruby-lang.org/en/documentation for additional information on Ruby.
A list of Ruby books is available here.