Robot Framework PythonLibCore

4.5.0 · active · verified Sat Apr 11

Robot Framework PythonLibCore (version 4.5.0) is a generic component designed to simplify the creation of larger, more flexible test libraries for Robot Framework using Python. It abstracts away the complexities of the Robot Framework's hybrid and dynamic library APIs, providing a streamlined interface. The library is actively maintained with frequent releases addressing bug fixes, performance enhancements, and compatibility with new Python and Robot Framework versions. It is widely used by other popular Robot Framework libraries like SeleniumLibrary and Browser library.

Warnings

Install

Imports

Quickstart

This example demonstrates creating a Robot Framework test library using `DynamicCore` from `robotlibcore`. It defines two separate classes (`LibraryComponent1`, `LibraryComponent2`) that contain keywords, decorated with `@keyword`. These components are then passed to the `DynamicCore`'s constructor in the main `MyLibrary` class. It also shows a keyword directly implemented in the main library class.

from robotlibcore import DynamicCore, keyword

class LibraryComponent1:
    @keyword
    def my_first_keyword(self, arg):
        print(f"Executing My First Keyword with: {arg}")
        return f"Processed: {arg}"

class LibraryComponent2:
    @keyword('Custom Name Keyword')
    def another_keyword(self, value):
        print(f"Executing Another Keyword with value: {value}")
        return f"Custom handled: {value}"

class MyLibrary(DynamicCore):
    """Example Robot Framework library using PythonLibCore."""

    ROBOT_LIBRARY_SCOPE = 'TEST SUITE'

    def __init__(self):
        # Pass instances of classes containing keywords to DynamicCore
        libraries = [LibraryComponent1(), LibraryComponent2()]
        DynamicCore.__init__(self, libraries)

    @keyword
    def keyword_in_main_library(self, data):
        """A keyword directly in the main library class."""
        print(f"Keyword in main library received: {data}")
        return data.upper()

# To use this library in Robot Framework:
# *** Settings ***
# Library    MyLibrary.py
#
# *** Test Cases ***
# Example Test
#     ${result1}=    My First Keyword    hello
#     Log To Console    ${result1}
#     ${result2}=    Custom Name Keyword    world
#     Log To Console    ${result2}
#     ${result3}=    Keyword In Main Library    pythonlibcore
#     Log To Console    ${result3}

view raw JSON →