EuroPython 2009: Acceptance Testing with RobotFramework

EuroPython 2009 has officially started today and the first talk I am attending is about testing, more in detail it’s about acceptance testing with RobotFramework, presented by Pekka Klärck.

RobotFramework seems to be quite interesting in that it allows you to write test cases in a very high level language which then is compiled into actual running tests. An example of a high level test case description is this:

Test CaseActionArgumentArgument
Valid LoginOpen Login Page
Input Namedemo
Input Passwordmode
Submit Credentials
Welcome Page Should Be Open
Setting VariablesDo Somethingfirst argumentsecond argument
${value} =Get Some Value
Should Be Equal${value}Expected value

This would be an example of a workflow based tests. Data driven tests are also possible.

Now here we have a term „Open Login Page“ which needs to be first converted into a proper action. „Open Login Page“ would be implemented like this (called user keywords):

Open Login PageOpen Browserhttp://host/login.html
Title Should BeLogin Page
Title Should Start With[Arguments]${expected}
${title} =Get Title
Should Start With${title}${expected}

Note that keywords are not single words but the whole phrase, e.g. „Open Login Page“.

The programmer would then create a library for performing the actual tests.

For instance it could look like this:

import os
import sys

class LoginLibrary:

    def __init__(self):
        self._sut_path = os.path.join(os.path.dirname(__file__),
                                      '..', 'sut', '')
        self._status = ''

    def create_user(self, username, password):
        self._run_command('create', username, password)

    def change_password(self, username, old_pwd, new_pwd):
        self._run_command('change-password', username, old_pwd, new_pwd)

    def attempt_to_login_with_credentials(self, username, password):
        self._run_command('login', username, password)

    def status_should_be(self, expected_status):
        if expected_status != self._status:
            raise AssertionError("Expected status to be '%s' but was '%s'"
                                  % (expected_status, self._status))

    def _run_command(self, command, *args):
        command = '"%s" %s %s' % (self._sut_path, command, ' '.join(args))
        process = os.popen(command)
        self._status =

These libraries would then actually perform the tests.

You can do a lot more and there seem to be lots of way on how you can group your tests, there are many tools for reporting and you can implement those test libraries in Java or Python.

Technorati Tags: , , , , ,

Teile diesen Beitrag