Showing posts with label robotframework. Show all posts
Showing posts with label robotframework. Show all posts

Friday, November 4, 2011

Robot Framework Newsletter, November 2011


What's this?


I have been thinking recently that the Robot Framework development must seem quite opaque to anyone outside the core team. We occasionally communicate when a development effort of some project is started, but at other times releases just come out of the woods.

To alleviate the lack of communication, I thought that a monthly newsletter would be in order. My intention is shed light on things that have been done in the recent past as well as highlight the things that we are likely to engage in the near future. I also figured that a slightly longer "feature article" would be nice in each newsletter.

And now you are enjoying the very first issue of the said newsletter. Hopefully it won't be the last. I would be grateful for any feedback, as well as suggestions for feature article topics.

The news


Some of these are actually already "olds", but in my opinion important enough to list here anyway.

Robot Framework 2.7 in development


We recently started the development of Robot Framework 2.7. The list of issues initially targeted for 2.7 is quite long, and subject to heavy pruning, probably during next week.

The core team has been working on faster and less resource consuming rebot, and we've been making good progress. Whole rebot was basically written from scratch and it is now integrated, and all tests are passing in the current HEAD.

If you have any contributions towards 2.7, now is the time to act.

Projects moved to GitHub


We've created a GitHub organization for Robot Framework, and have already moved some projects there. The reasoning for this move warrants its own post, but the short story is that we hope to
  • ease our own work
  • lower the barrier for contributing

We are likely to continue moving projects to GitHub, although the migration of core framework itself has not yet been scheduled.

New test libraries

Ryan Tomac has released Selenium2Library, which is a drop-in replacement for SeleniumLibrary, but it uses the new Selenium2 WebDriver API instead of the Remote control API used by the old library. Thanks Ryan for this major contribution!

The core team has released first version of Rammbock, which is a generic network protocol test library for Robot Framework. Rammbock is still in its early stages, but shows great promise.

Feature of the month: How Robot Framework development is organized


As mentioned in project pages, Robot Framework was started as an internal project at Nokia Networks (which was later merged with Siemens network business to create NSN), and was open sourced later. It is widely used at NSN, and NSN still funds RF development.

The core team (currently numbering one part-time NSN person and 4,5 externals) is paid by NSN and works at NSN premises in Espoo, Finland. Pekka Klärck, creator of the framework, is part of the core team.

In addition to developing the core framework and RIDE, and maintaining several test libraries, the core team is responsible for NSN-wide training and support of Robot Framework.

Priorities for RF development arise mainly from the internal users, and these needs affect the order in which, for example RF and RIDE releases are made. However, we tend to fix bugs regardless of who opened the bug report. Similarly, generic, useful enhancements of reasonable scope are also often made without direct internal need.

All the core team projects have issue trackers, and even though sometimes neglected for a while, the issue tracker is the most accurate source of information about the scope of any upcoming release.

We do not have any kind of roadmaps, or deadlines for releases. We try to work on only one project at any given time, and after a release is made, next project is chosen based on the priorities at that point. This also means that most of the time, most of the projects are on hold.

All the above applies obviously only to projects that are directly maintained by the core team. There's a growing number of test libraries and other tools maintained by active community members, and those projects have their own governing rules.

If this raises further questions, use comments, or start a thread in mailing list.

Upcoming events


Here's a list of upcoming events that are going to feature Robot Framework in one way or another.


Friday, January 28, 2011

Functional Robot

Robot has some interesting keywords that allow users to make keywords that use function delegation or are higher order functions. Here are some examples that I think could be useful.

Keyword that opens and closes a resource

Basic idea is to have keyword that does something (opens a resource) before executing a delegated keyword and does something (closes a resource) after it has executed the delegated keyword.

Here is an example keyword that executes the argument keyword without producing log output.


With No Logging
[Arguments] @{keyword with args}
${original log level}= Set Log Level NONE
${result}= Run Keyword @{keyword with args}
Set Log Level ${original log level}
[Return] ${result}


Example use:

With No Logging Generated Huge Report Is Valid


Keyword for consuming unknown number of items


Consume All
[Arguments] ${producer function} ${consumer function}
${product}= Run Keyword ${producer function}
Run Keyword If ${product} ${consumer function} ${product}
Run Keyword If ${product} Consume All ${producer function} ${consumer function}


Consume All keyword takes a function that produces items and another function that consumes those items. Item could be anything for example a web page url or a custom xml message from a server. Consume All keyword stops when producer returns an empty value.
This keyword is useful in situations where there isn't total control of the number of produced items or when that number isn't really interesting from the testing point of view or it takes too much time to first find the number of items and then go through all of them. For cases where the number of items or the list of items is easy to get robotframework has BuiltIn.Repeat Keyword and :FOR.

Example uses:

All Server Messages Have Valid Hash
Consume All Server.Pull Message Validate Message Hash

All Pages Contain Company Logo
Consume All PageCrawler.Next Page Page Contains Company Logo

Monday, December 6, 2010

Acceptance Test Driven Development with an internal customer

In my experience and what I hear about problems with Acceptance Driven Development (ATDD) practice, is that it's not easy to have the customer in the same room to create highest abstraction level Test Cases. This is of course a problem to business people and it might be a little bit hard to sell, if you don't have any experience of your own about the topic.

One of the easier way how a corporation can start to practice this is to try it out with internal customers. Usually there should be a situation where the whole product is not created in one place. These kind of relationships are eg. platform vs. application, where platform is created in one part of organization and application(s) in another. It's easier to create Test Cases and get people in the same meeting room when they are close to each others and there are no company barriers.

These activities aim to raise competence and good knowledge about practice inside the company. ATDD of course aims for communication with real customers, but this is a good way to get hands-on.

Monday, October 25, 2010

Robot framework training

I joined with Pekka Klärck and Ismo Aro to do my first Robot training and coaching sessions this October in Athens, Greece. It was a very nice way start coaching Robot usage with such an enthusiastic and eager to learn crowd. Many thanks to everybody who participated!

In the (generally very positive) feedback that we gathered from the sessions two main points of criticism stand out:

  1. Two days is a very short time to learn test automation with Robot (I don't think this is in any way Robot specific issue.)
  2. People prefer learning by doing exercises over listening to me going on about the theory. Also it was pointed out that it would be nice to have more time for the exercises that we have.
Planning the next training
The first issue is really no surprise. Although the basic syntax and usage of Robot is very easy to learn, learning how to do test automation well in general takes time. Also for learning the more exotic features of Robot Framework, a course of two days is just a too short of a time. When giving Robot training we do usually stay for a few days afterwards to coach and help clients with their real tests. This is a very important part of the training and should be considered a part of the course really. (Maybe next time, I will ask for the feedback after the coaching is done also...)

I do understand that the two day crash course into test automation with robot can be a bit like drinking from a fire hose. We have to think whether it would be better to give Robot training for example first one day, then coaching and some time for the people to try out what they learned and then after a week or so, to give a second day of training with more advanced concepts.

The second point about more hands on training forces us to rethink how to present the more advanced concepts and also what concepts are really necessary in a basic training. It is a lot easier to cover many advanced concepts in one day when you just read them through from slides. To actually let the people try them out, we have to give them some time and therefore also to skip some subjects from the training. But in the end, I guess it is better to teach few things well, than a lot of things too quickly.

This has been an important learning experience and we are looking forward to making the next training even better than this one.

Monday, October 18, 2010

Creating Robot Framework jar distribution

As of Robot Framework 2.5.2, it is also distributed as a single stand alone jar file.

The goal was to create a jar distribution with following properties:
  • Standalone executable jar file, i.e. java -jar robotframework.jar mystest.txt would suffice to run tests.
  • The exit code of the above command must be the same as if mytests.txt was executed with pybot.
  • There would also be a programmatic API to start Robot Framework test execution from any Java program
While there was a wealth of information about Jython-Java interaction available in the net, I could not find a single set of instructions describing all the necessary steps to create the required jar.  Since I was able to do it and since the process is general, I decided to write it down.

First requirement is the Jython standalone jar, which can be created with the Jython installer. Following the instructions in the Jython Book, I created three Java classes and one Python for the interaction. These classes implement the one-to-one Jython object factory described in the Jython book. Source code of these classes is available in Robot Framework source repository.

The java classes had to (of course) be compiled before inserting them into the jar file. Additionally, a MANIFEST.MF file with correct main-class had to be created. Once these were done, the files could be inserted into the Jython jar:
  • Robot Framework source code must be placed in Lib directory inside the jar
  • The java code must be inserted starting from the root of the and according to package structure
  • The MANIFEST.MF has be to in META-INF directory
That's pretty standard stuff expect for one gotcha: Zip file format (and jar files are Zip files) supports multiple entries with same path. Since the Jython jar already contains MANIFEST.MF and since Python's zipfile module does not support overriding or removing entries, the first released version of the jar distribution contained two manifest files. For reasons unknown to me, the one we inserted was effective when the jar file was executed with java, but adding files to the jar file with jar failed because of the duplicate manifest.

This was resolved by unpacking the Jython jar and replacing the MANIFEST.MF with our own on the file system before repackaging. .

All the Python source files were compiled with Jython's compileall module before they were inserted into the jar file. This presumably increases performance slightly.

I will probably do another post about how we finally got the jar distribution uploaded to Maven central, since that's an interesting story too.

Thursday, October 7, 2010

Implementing asynchronous Robot Framework keywords

Before tests can be run I have to start all the necessary systems (processes, servers, stuff and things). Let's imagine that there are multiple systems that need to be started. I would like to start them all at the same time and wait until they are all ready to rock 'n' roll before starting my tests (assume that it would take a lot longer if I started all the systems in sequence).

So how to do this with Robot? Basic idea is to have re-usable keywords for starting each system and a keyword for waiting until the systems are ready so that testing can begin (and we don't have to use ugly and unreliable sleeps). Doing this on Robot keyword level makes it possible to have different combinations of systems in different tests.

*** Settings ***
Documentation Example of using parallel things
Suite Setup StartSystems
Library SystemStarterLibrary.py

*** Test Cases ***
... Here should be my tests

*** Keywords ***
StartSystems
${SYSTEM1_STARTED}= Asynchronously Start System 1
${SYSTEM2_STARTED}= Asynchronously Start System 2
Wait until ${SYSTEM1_STARTED} ${SYSTEM2_STARTED}




The way I'm going to implement this is by using python decorator that executes the function that it decorates in a separate thread. The decorated function will return the thread object so that it can be used to implement the waiting functionality.

I'm using this little code for the decorator.

After I've imported that to my SystemStarterLibrary.py I can implement system starter functions as normal functions.

@run_async
def asynchronously_start_system_1():
.. do stuff to start system 1

@run_async
def asynchronously_start_system_2():
.. do stuff to start system 2


Now all I need to do is to implement Wait until.

def wait_until(*stuff):
for something in stuff :
something.join()



This is kind of OK but it will wait forever if starting of some system will take forever. So it is better to have some timeout that will tricker setup failure after the timeout.

*** Keywords ***
StartSystems
[Timeout] 5 minutes
${SYSTEM1_STARTED}= Asynch Start System 1
${SYSTEM2_STARTED}= Asynch Start System 2
Wait until ${SYSTEM1_STARTED} ${SYSTEM2_STARTED}


And that should do it.

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.

Installing Robot Framework on Ubuntu

Lately I've been learning to use the robot framework. These are my notes on how to install it.

Installing pybot - normal robot thing

First install python if it's not already installed.


sudo apt-get install python


Then install easy_install and robotframework.


sudo apt-get install python-setuptools
sudo easy_install robotframework


After this you should have pybot (normal robot thing) installed.


pybot --version
== Should output something like ==>
Robot Framework 2.5.4 (Python 2.6.5 on linux2)


Installing jybot - jython version of robot

I'll assume you have done all the things to install pybot so far (it also installed jybot and all you have to do now is to install correct version of jython).

First a word of warning: Ubuntu is still (you should check is this still valid point if your reading this in the future) using old version of Jython that doesn't work with current jybot.

So we have to first download Jython 2.5 (or later) from jython webpage. Follow jythons installation instructions.

Add JYTHON_HOME to PATH so that you can use it.

After this jybot should work.


jybot --version
== Should output something like ==>
Robot Framework 2.5.4 (Jython 2.5.1 on java1.6.0_20)

Monday, June 8, 2009

Comments to Robot Framework review by Gojko Adzic

Gojko Adzic organized Agile acceptance testing tools round-up on 27 May 2009 at Skills Matter in London. One of the tools he presented was Robot Framework and he published Robot Framework review on his blog afterwards.

Gojko's review is very well written, especially thinking that it is mainly based on the documentation on the project pages. The review is also pretty positive which obviously makes me happy. I had a change to see his text already before the presentation and some of my comments are included in the blog post. After re-reading the text I decided to add few more comments here. The comments below are organized into same sections as in the original review.

Keywords

It was great that Gojko spent some time to explain the keyword-driven concept behind Robot Framework and included my comment about how it makes the library API simple. I hope he had also shown that although this approach is simple, it's also very powerful and it is possible to create different kind of test cases using it. Robot Framework Quick Start Guide has very good examples of "normal" keyword driven tests, data-driven tests, and tests using the behavior-driven development (BDD) style.

Organising and editing tests

This is a good section about creating tests. Unfortunately the example, taken from the examples we use for explaining complex features, is pretty technical. For example the earlier mentioned Quick Start Guide has examples that are much better as tests. Normally when I talk how tests are organized into files and directories, I also mention how trivial it is to put them into a version control system. This is probably obvious to everyone reading the review, though.

Filtering

This section discusses tags and how they can be used for filtering tests and marking tests critical. Gojko's examples are very good, I especially like that they are from his own domain, and they illustrate these important features very well. The only thing I wish was mentioned too is how tags can be used to get statistics about passed and failed tests.

Compared to other tools

Gojko writes that Robot Framework is best suited for scripting tasks. Although I totally agree that RF suits very well for traditional scripted test automation, I'd like to highlight that creating also other kind of tests is possible. This is illustrated by the examples in the Quick Start Guide, and the executable requirements we created when developing RFDoc tool act as more realistic examples. In my opinion it is also a huge benefit that the same tool can be used for "normal" scripted testing, for creating BDD style executable specifications, and for constructing tabular examples with only input and output values.

One of the many points where I fully agree with Gojko is that Robot Framework can be used for creating domain specific languages. This can actually be done on many levels. For example SeleniumLibrary has its own web specific language with keywords like Click Link and Title Should Be, application specific language could have keywords like Input Password or Welcome Page Should Be Open, and finally on the specification level the language often sounds something like Given a user has logged in.

Reports and logs

The only bigger subject missing from the review was a section with this title. Reports and logs are something where Robot Framework is, at least in my opinion, ahead of other acceptance testing tools by a wide margin. The high-level report can be used for visualizing the overall status, detailed logs give accurate information about the test execution, and XML outputs can be easily integrated e.g. with CI systems and even combined to generate higher level reports.