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.
If you are mainly interested to learn how to create tests cases for Robot Framework or how to extend it with custom libraries, you should probably study other documentation and demo projects instead.
The latest demo package is available on the project downloads as CDemo-<date>.zip. After downloading and unzipping the package, you should have all the files in a directory CDemo.
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.
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
The login_tests.robot test case file contains all tests for this demo. It contains separate tests for valid and invalid login.
pip install robotframework
Robot Framework 3.0 and newer support Python 3 in addition to Python 2. Also this demo project is nowadays Python 3 compatible.
After Robot Framework is installed, the demo can be executed using the robot command:
Run robot --help for more information about the command line usage and see Robot Framework User Guide for more details about test execution and Robot Framework in general.
If you are using Robot Framework 2.9 or earlier, you need to use the pybot command instead.