In [1]:
import robottools
print(robottools.__version__)
In [2]:
print(robottools.__description__)
testlibrary() creates Dynamic Test LibrariesContextHandler][1.1] framework for testlibrary
to create switchable sets of different Keyword implementations.SessionHandler][1.2] framework for testlibrary
to auto-generate Keywords for session management.TestLibraryInspector][2].RemoteRobot][4], combining TestRobot
with external RobotRemoteServerToolsLibrary][5],
accompanying Robot Framework's standard Test Libraries.robotshell][6] extension for IPython.
In [3]:
# !pip install robotframework-tools
In [4]:
# !conda install -c userzimmermann robotframework-tools
Both automatically install requirements:
In [5]:
robottools.__requires__
Out[5]:
Python 2.7: robotframework>=2.8
Python 3.x: robotframework-python3>=2.8.4
RemoteRobot and robotshell have extra requirements:
In [6]:
robottools.__extras__
Out[6]:
Pip doesn't install them by default.
Just append any comma separated extra tags in [] brackets to the package name.
To install with all extra requirements:
In [7]:
# !pip install robotframework-tools[all]
This README.ipynb will also be installed. Just copy it:
In [8]:
# robottools.__notebook__.copy('path/name.ipynb')
In [9]:
from robottools import testlibrary
In [10]:
TestLibrary = testlibrary()
This generated Dynamic TestLibrary class
could now directly be imported in Robot Framework.
It features all the Dynamic API methods:
get_keyword_namesget_keyword_argumentsget_keyword_documentationrun_keywordThe TestLibrary has no Keywords so far...
To add some just use the TestLibrary.keyword decorator:
In [11]:
@TestLibrary.keyword
def some_keyword(self, arg, *rest):
pass
A keyword function can be defined anywhere in any scope.
The TestLibrary.keyword decorator
always links it to the TestLibrary
(but always returns the original function object).
And when called as a Keyword from Robot Framework
the self parameter will always get the TestLibrary instance.
You may want to define your keyword methods
at your Test Library class scope.
Just derive your actual Dynamic Test Library class from TestLibrary:
In [12]:
class SomeLibrary(TestLibrary):
def no_keyword(self, *args):
pass
@TestLibrary.keyword
def some_other_keyword(self, *args):
pass
To get a simple interactive SomeLibrary overview just instantiate it:
In [13]:
lib = SomeLibrary()
You can inspect all Keywords in Robot CamelCase style (and call them for testing):
In [14]:
lib.SomeKeyword
Out[14]:
By default the Keyword names and argument lists are auto-generated from the function definition. You can override that:
In [15]:
@TestLibrary.keyword(name='KEYword N@me', args=['f|r$t', 'se[ond'])
def function(self, *args):
pass
When you apply custom decorators to your Keyword functions
which don't return the original function objects,
you would have to take care of preserving the original argspec for Robot.
testlibrary can handle this for you:
In [16]:
def some_decorator(func):
def wrapper(self, *args):
return func(self, *args)
# You still have to take care of the function(-->Keyword) name:
wrapper.__name__ = func.__name__
return wrapper
TestLibrary = testlibrary(
register_keyword_options=[
# Either just:
some_decorator,
# Or with some other name:
('some_option', some_decorator),
],
)
@TestLibrary.keyword.some_option
def some_keyword_with_options(self, arg, *rest):
pass
There are predefined options. Currently:
unicode_to_str - Convert all unicode values (pybot's default) to str.You can specify default_keyword_options that will always be applied:
In [17]:
TestLibrary = testlibrary(
register_keyword_options=[
('some_option', some_decorator),
],
default_keyword_options=[
'unicode_to_str',
'some_option',
],
)
To bypass the default_keyword_options for single Keywords:
In [18]:
@TestLibrary.keyword.no_options
def some_keyword_without_options(self, arg, *rest):
pass
@TestLibrary.keyword.reset_options.some_option
def some_keyword_without_default_options(self, arg, *rest):
pass