Robot Framework Demo

2013-04-10  张林 

Robot Framework Demo Robot Framework Demo

Robot Framework is a generic open source test automation framework. In addition to introducing Robot Framework test data syntax, this demo shows how to execute test cases, how generated reports and logs look like, and how to extend the framework with custom test libraries.

See also Web testing with Robot Framework and Selenium2Library and Acceptance Test Driven Development with Robot Framework demo projects.

Downloading demo package

To get the demo, you can either download and extract the latest RobotDemo-<date>.zip package from the download page or checkout the source code directly. As a result you get RobotDemo directory with several files.

Example test cases, test library used by them, and generated results are available also online. Therefore, you do not need to download the demo to see it if you are not interested in running it yourself.

Demo application

The demo application is a very simple calculator implemented with Python (calculator.py). It contains only business logic and no user interface. You cannot really run the calculator manually.

Test cases

The demo contains three different test case files illustrating three different approaches for creating test cases with Robot Framework. Click file names below to see the latest versions online.

keyword_driven.txt

Example test cases using the keyword-driven testing approach.

All tests contain a workflow constructed from keywords in CalculatorLibrary. Creating new tests or editing existing is easy even for people without programming skills.

This kind of style works well for normal test automation. If also business people need to understand tests, using gherkin style may work better.

data_driven.txt

Example test cases using the data-driven testing approach.

Tests use Calculate keyword created in this file, that in turn uses keywords in CalculatorLibrary. An exception is the last test that has a custom template keyword.

The data-driven style works well when you need to repeat the same workflow multiple times.

gherkin.txt

Example test case using the gherkin syntax.

This test has a workflow similar to the keyword-driven examples. The difference is that the keywords use higher abstraction level and their arguments are embedded into the keyword names.

This kind of gherkin syntax has been made popular by Cucumber. It works well especially when tests act as examples that need to be easily understood also by the business people.

As you can see, creating test cases with Robot Framework is very easy. See Robot Framework User Guide for details about the test data syntax.

Test library

All test cases interact with the calculator using a custom test library named CalculatorLibrary.py. In practice the library is just a Python class with methods that create the keywords used by the test cases.

Generated library documentation makes it easy to see what keywords the library provides. This documentation is created with Libdoc tool integrated with the framework.

As you can see, Robot Framework's test library API is very simple. See Robot Framework User Guide for more information about creating test libraries, using Libdoc, and so on.

Generated results

After running tests, you will get report and log in HTML format. Example files are also visible online in case you are not interested in running the demo yourself. Notice that one of the test has failed on purpose to show how failures look like.

Running demo
Preconditions

A precondition for running the tests is having Robot Framework installed. It is most commonly used on Python but it works also with Jython (JVM) and IronPython (.NET). Robot Framework installation instructions cover installation procedure in detail. People already familiar with installing Python packages and having pip package manager installed, can simply run the following command:

pip install robotframework
Running tests

Test cases are typically executed with pybot command that runs Robot Framework on Python. With other interpreters the start-up command is different. To execute a single test case file, just give it as an argument to the start-up command:

pybot keyword_driven.txt

To execute all test case files in a directory recursively, just give the directory as an argument. You can also give multiple files or directories in one go and use various command line options supported by Robot Framework. The results available online were created using the following command:

pybot --name Robot --loglevel DEBUG keyword_driven.txt data_driven.txt gherkin.txt

Run pybot --help for more information about the command line usage and see Robot Framework User Guide for more details.

http://robotframework.org/

Robot Framework Plugin

https://wiki.jenkins-ci.org/display/JENKINS/Robot+Framework+Plugin

578°/5782 人阅读/0 条评论 发表评论

登录 后发表评论