Wiki

Clone wiki

CDemo / Home

Introduction

This simple example demonstrates how to use C language from Robot Framework test libraries. The example uses Python's standard ctypes module, which requires that the C code is compiled into a shared library. This version is implemented and tested on Linux, but adapting it to other operating systems would require only changing compilation and name of the produced shared library.

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

Downloading demo package

The latest demo package is available on the project downloads as robotframework-c-example-<date>.zip. After downloading and unzipping the package, you should have all the files in a directory robotframework-c-example.

System under test

The demo application is a very simple login system (login.c), that validates the given user name and password and returns the status. There are two valid username password combinations: demo/mode and john/long.

Before running the demo, you need to compile the demo application by simply running make in the directory that was created when you extracted the demo package. This will create shared library liblogin.so.

Test library

LoginLibrary.py is a simple test library that can interact with the system under test using the ctypes module. The library provides only one keyword Check User.

The if __name__ == '__main__' block in LoginLibrary.py is not used by the executed tests, but it allows using the library code as a tool for manual testing. You can test this handy behavior on the command line:

python LoginLibrary.py demo mode
python LoginLibrary.py demo invalid

Test cases

login_tests.robot test suite contains all tests for this project. It contains separate tests for valid and invalid login.

Notice that although the file has a fancy .robot extension, it is actually a normal plain text file. The extension could be changed to .txt and Robot Framework would still be able to run it.

Running tests

A precondition for running the tests is having Robot Framework installed. Installation instructions cover that in detail, but for pip users its enough to run:

pip install robotframework

When Robot Freamework is installed, the demo can be executed using pybot command:

pybot login_tests.robot

All the test should pass.

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:

Updated