Robot Framework is a generic open source test automation framework for acceptance testing, acceptance test-driven development (ATDD) and robotic process automation (RPA).
It has easy-to-use tabular test data syntax and it utilizes the keyword-driven testing approach. You can build the automated script by integrating all necessary built-in, third-party keywords and users can create new higher-level keywords from existing ones using the same syntax that is used for creating test cases.
But in some cases, you need to create customized keywords to enhance your testing libraries. The core Robot Framework is implemented using Python. However, your testing libraries may code in Java or C#.
This blog post will explain how to customize your Robot Framework libraries with the real examples.
The simplest approach is having a module or a class in Python with methods which map directly to keyword names. Keywords also take the same arguments as the methods implementing them. Keywords report failures with exceptions, log by writing to standard output and can return values using the return statement.
Give a name to your test library so that you can import it using the same name in your test case. Then define the methods and arguments like this:
Robot Framework attempts to keep test cases independent from each other that means each test case creates new instances of test libraries. However, sometimes test cases need to share a common library. The test libraries scope can be controlled by setting a class attribute ROBOT_LIBRARY_SCOPE. This attribute must be a string and it can have the following three values:
TEST CASE: A new instance is created for every test case.
TEST SUITE: A new instance is created for every test suite.
GLOBAL: Only one instance is created during the whole test execution.
You can specify the documentation format in the source code using ROBOT_LIBRARY_DOC_FORMAT attribute.
Now you can import test library into your test cases.
And you can search newly created keywords.
Check the test library works successfully.
Python for .NET (pythonnet) is the main package that gives Python programmers nearly seamless integration with the .NET 4.0+ Common Language Runtime (CLR) on Windows.
In Example below I’m using a fake shopping cart solution. The solution is simple: