Wednesday, October 6, 2010

Hello World Robot Framework library

This is the way I did my first Robot Framework keyword library. It should show the basic steps to add your own python keywords.

Let's do it in a test-driven way!

Failing test case

Add a file called HelloWorld.txt. This is our robot test suite file.

Add following text to the file:

*** Test Cases ***
HelloWorld
Hello World



After this run pybot HelloWorld.txt - this will execute your Hello World test case.
Output should be something like:

==============================================================================
HelloWorld
==============================================================================
HelloWorld | FAIL |
No keyword with name 'Hello World' found.
------------------------------------------------------------------------------
HelloWorld | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================


Now we have a failing test case! So we can begin to implement our super cool Hello World keyword.

Keyword file

Add a file called HelloWorld.py to the same directory as our HelloWorld.txt test suite.

Add following text to the file:

def hello_world():
print "HELLO WORLD!"


Now we have implemented our fine keyword that prints "HELLO WORLD!". Although our test still fails..

Passing test case

We have to import our super cool library to our test suite. Add following lines to the HelloWorld.txt (before test cases):

*** Settings ***
Library HelloWorld.py



After this run pybot HelloWorld.txt - and watch it PASS:
==============================================================================
HelloWorld
==============================================================================
HelloWorld.HelloWorld
==============================================================================
HelloWorld | PASS |
------------------------------------------------------------------------------
HelloWorld.HelloWorld | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
HelloWorld | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================



Thats it.

1 comment: