Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a custom Python code library for the Robot Framework

I already have Python source files for some custom tasks. Can I create a custom library of these tasks as keywords and use in the Robot Framework?

like image 986
Narendra Petkar Avatar asked Nov 20 '14 11:11

Narendra Petkar


People also ask

Which Python library is used for robotics?

About: PyRobot is a Python library for benchmarking and running experiments in robot learning. It is a combination of two popular Python libraries, i.e. Requests and BeautifulSoup.

How do I customize my Robot Framework report?

One solution is to create your own report from scratch. The XML output is very easy to parse. You can turn off the generation of reports with command line options (eg: --log NONE and --report NONE ). Then, create a script that generates any type of report that you want.

How do I use Python keywords in Robot Framework?

In your python code you can get a reference to the BuiltIn library, and then use the Run Keyword keyword to run any keyword you want. Notice how the test case tells the call_keyword method to run the keyword Example Keyword . Of course, you don't have to pass in a keyword.


1 Answers

Yes, you can. This is all documented fairly extensively in the Robot Framework user guide, in the section titled Creating test libraries.

You have a couple of choices. You can use your module directly, which makes every method in the module available as a keyword. This is probably not what you want since the library probably wasn't designed to be used as a collection of keywords. Your second choice is to create a new library that imports your modules, and your new library provides keywords that call the functions in the other library.

As a simple example, let's say you have a module named MyLibrary.py with the following contents:

def join_two_strings(arg1, arg2):     return arg1 + " " + arg2 

You can use this directly in a test suite as in the following example, assuming that MyLibrary.py is in the same folder as the suite, or is in a folder in your PYTHONPATH:

*** Settings *** | Library | MyLibrary.py  *** Test Cases *** | Example that calls a Python keyword | | ${result}= | join two strings | hello | world | | Should be equal | ${result} | hello world 
like image 129
Bryan Oakley Avatar answered Sep 27 '22 20:09

Bryan Oakley