Home

Web testing with Robot Framework and Selenium2Library

Robot Framework is a generic open source test automation framework and Selenium2Library is one of the many test libraries that can be used with it. In addition to showing how they can be used together for web testing, this demo introduces the basic Robot Framework test data syntax, how tests are executed, and how logs and reports look like.

See also Robot Framework Demo and Acceptance Test Driven Development with Robot Framework projects.

Downloading demo package

To get the demo, you can either download and extract the latest WebDemo-<date>.zip package from the download page or checkout the source code directly. As a result you get WebDemo directory with demoapp and login_tests sub directories.

Example test cases and generated results are available also online. There is thus no need to get the demo if are not interested in running it yourself.

Demo application

The demo application is a very simple login page shown below. With user name demo and password mode you get into a welcome page, and otherwise you end up to an error page. How to start and stop the application yourself is explained in Starting demo application section.

demoapp.png

Test cases

Test case files and a resource file used by them are located in login_test directory. Click file names below to see the latest versions online.

valid_login.txt

A test suite with a single test for valid login.

This test has a workflow that is created using keywords in the imported resource file.

invalid_login.txt

A test suite containing tests related to invalid login.

These tests are data-driven by their nature. They use a single keyword, specified with Test Template setting, that is called with different arguments to cover different scenarios.

This suite also demonstrates using setups and teardowns in different levels.

gherkin_login.txt

A test suite with a single Gherkin style test.

This test is functionally identical to the example in valid_login.txt file.

resource.txt

A resource file with reusable keywords and variables.

The system specific keywords created here form our own domain specific language. They utilize keywords provided by the imported Selenium2Library.

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:

Running demo

Preconditions

A precondition for running the tests is having Robot Framework and Selenium2Library installed, and they in turn require Python. Robot Framework installation instructions cover both Robot and Python installations, and Selenium2Library has its own installation instructions.

In practice it is easiest to install Robot Framework and Selenium2Library along with its dependencies using pip package manager. Once you have pip installed, all you need to do is running these commands:

pip install robotframework
pip install robotframework-selenium2library

Starting demo application

Running tests requires the demo application located under demoapp directory to be running. It can be started either by double clicking demoapp/server.py file in a file manager or by executing it from the command line:

python demoapp/server.py

After the demo application is started, it is be available in URL http://localhost:7272. You can test it manually, valid credentials are demo/mode, and it needs to be running while executing the automated tests.

If the application was started by double-clicking demoapp/server.py file, it can be shut down by closing the opened window. If it was executed from the command line, using Ctrl-C is enough.

Running tests

The test cases are located in login_tests directory. To execute them all use:

pybot login_tests

You can also run an individual test case file and use various command line options supported by Robot Framework:

pybot login_tests/valid_login.txt
pybot --test InvalidUserName --loglevel DEBUG login_tests

Run pybot --help for more information about the command line usage.

Using different browsers

The browser that is used is controlled by ${BROWSER} variable defined in resource.txt resource file. Firefox browser is used by default, but that can be easily overridden from the command line:

pybot --variable BROWSER:Chrome login_tests
pybot --variable BROWSER:IE login_tests

Consult Selenium2Library documentation about supported browsers. Notice also that some browsers, most notable Chrome and Internet Explorer, require separate drivers to be installed before they can be used.

Updated

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.