Tools to ease creating larger test libraries for Robot Framework using Python.
Project description
Tools to ease creating larger test libraries for Robot Framework using Python. The Robot Framework hybrid and dynamic library API gives more flexibility for library than the static library API, but they also sets requirements for libraries which needs to be implemented in the library side. PythonLibCore eases the problem by providing simpler interface and handling all the requirements towards the Robot Framework library APIs.
Code is stable and version 1.0 is already used by SeleniumLibrary and WhiteLibrary. The version 2.0 support changes in the Robot Framework 3.2.
Usage
There are two ways to use PythonLibCore, either by HybridCore or by using DynamicCore. HybridCore provides support for the hybrid library API and DynamicCore provides support for dynamic library API. Consult the Robot Framework User Guide, for choosing the correct API for library.
Regardless which library API is chosen, both have similar requirements.
Library must inherit either the HybridCore or DynamicCore.
Library keywords must be decorated with Robot Framework @keyword decorator.
Provide a list of class instances implementing keywords to library_components argument in the HybridCore or DynamicCore __init__.
It is also possible implement keywords in the library main class, by marking method with @keyword as keywords. It is not requires pass main library instance in the library_components argument.
All keyword, also keywords implemented in the classes outside of the main library are available in the library instance as methods. This automatically publish library keywords in as methods in the Python public API.
The example in below demonstrates how the PythonLibCore can be used with a library.
Example
"""Main library."""
from robotlibcore import DynamicCore
from mystuff import Library1, Library2
class MyLibrary(DynamicCore):
"""General library documentation."""
def __init__(self):
libraries = [Library1(), Library2()]
DynamicCore.__init__(self, libraries)
@keyword
def keyword_in_main(self):
pass
"""Library components."""
from robotlibcore import keyword
class Library1(object):
@keyword
def example(self):
"""Keyword documentation."""
pass
@keyword
def another_example(self, arg1, arg2='default'):
pass
def not_keyword(self):
pass
class Library2(object):
@keyword('Custom name')
def this_name_is_not_used(self):
pass
@keyword(tags=['tag', 'another'])
def tags(self):
pass
Plugin API
It is possible to create plugin API to a library by using PythonLibCore. This allows extending library with external Python classes. Plugins can be imported during library import time, example by defining argumet in library __init__ which allows defining the plugins. It is possible to define multiple plugins, by seperating plugins with with comma. Also it is possible to provide arguments to plugin by seperating arguments with semicolon.
from robot.api.deco import keyword # noqa F401
from robotlibcore import DynamicCore, PluginParser
from mystuff import Library1, Library2
class PluginLib(DynamicCore):
def __init__(self, plugins):
plugin_parser = PluginParser()
libraries = [Library1(), Library2()]
parsed_plugins = plugin_parser.parse_plugins(plugins)
libraries.extend(parsed_plugins)
DynamicCore.__init__(self, libraries)
When plugin class can look like this:
class MyPlugi:
@keyword
def plugin_keyword(self):
return 123
Then Library can be imported in Robot Framework side like this:
Library ${CURDIR}/PluginLib.py plugins=${CURDIR}/MyPlugin.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file robotframework-pythonlibcore-4.1.2.tar.gz
.
File metadata
- Download URL: robotframework-pythonlibcore-4.1.2.tar.gz
- Upload date:
- Size: 10.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 308c0f4afeed51d913f4883cd9eb2b002f4459a20d76b9c942a42cae0296ea26 |
|
MD5 | dc4cdce6b6effdb06396b7b9070cf30a |
|
BLAKE2b-256 | a2f2a25d9dd39982dff049c95bee52b8fb0be7ef4f3542f4e398127f25a9e4a1 |
File details
Details for the file robotframework_pythonlibcore-4.1.2-py2.py3-none-any.whl
.
File metadata
- Download URL: robotframework_pythonlibcore-4.1.2-py2.py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b1c1bb7787d993e4c9643d2132302ff8a75cd7bdbefb5b3c293a179f2aaf17e |
|
MD5 | 6ac068c4eb5c6eee5456384106bacd99 |
|
BLAKE2b-256 | 0b50383c6c9ba3c0304be203ede077455cf1fca6f3e87d5db836c0c294bc327e |