Skip to main content

Robot Framework SchemathesisLibrary

Robot Framework SchemathesisLibrary is a library build top of the Schemathesis. Schemathesis automatically generates thousands of test cases from your OpenAPI or GraphQL schema and finds edge cases that break your API.

SchemathesisLibrary uses DataDriver to create test cases from the Schemathesis Case object.

Installation

Install with pip, uv or any package manager that supports PyPi

pip install robotframework-schemathesislibrary

Keyword documentation

See keyword documentation for more details. A link older keyword documentation can be found from versions page

Usage

Test are automatically generated based your API specification, SchemathesisLibrary uses DataDriver internally, but you need to create template suite, so that DataDriver is able to create needed test for your test suite.

SchemathesisLibrary must be imported by url or path argument, which tell where the API specification can obtained. As like with Datadriver, there must be Test Template setting defined. The template keyword must take one argument, usually referred as ${case} and the template keyword must call Call And Validate keyword with the ${case} argument.

Example test suite:

*** Settings ***
Library             SchemathesisLibrary    url=http://127.0.0.1/openapi.json

Test Template       Wrapper


*** Test Cases ***
All Tests   # This test is deleted by DataDriver
    Wrapper    test_case_1


*** Keywords ***
Wrapper
    [Arguments]    ${case}
    Call And Validate    ${case}

Authentication

Dynamic token authentication

Library currently supports Schemathesis dynamic token authentication by the library import auth argument. The dynamic token generation class should follow the Schemathesis documentation. The only addition is the import. Importing the class must follow the Robot Framework library import rules , example if importing with filename, filename much match to the class name. Example if test case looks like:

*** Settings ***
Library             SchemathesisLibrary    url=http://127.0.0.1/openapi.json    auth=${CURDIR}/AuthExtension.py
Test Template       Wrapper

*** Test Cases ***
All Tests
    Wrapper    test_case_1

*** Keywords ***
Wrapper
    [Arguments]    ${case}
    Call And Validate    ${case}

And AuthExtension.py looks like

from base64 import b64encode

import schemathesis
from robot.api import logger


@schemathesis.auth()
class AuthExtension:
    def get(self, case, ctx):
        # Instead of hard coding secrets to class, it is better to get them dynamically.
        # Jenkins or GitHub secrets, Azure keyvault, or from somewhere which is appropriate
        # for your needs.
        return b64encode("joulu:pukki".encode("utf-8")).decode("ascii")

    def set(self, case, data, ctx):
        case.headers = case.headers or {}
        case.headers["Authorization"] = f"Basic {data}"
        logger.debug(f"Updated headers for case: {case.operation.method} {case.operation.path}")

Then with all API calls, will have basic auth set in the headers for all calls made to your API endpoint.

Schemathesis hook support

Library supports extending Schemathesis by defining hooks. Hooks allows users to customize how Schemathesis generates test data, validates responses, and handles requests through hooks, custom checks, and data generation strategies. For more details about Schemathesis hooks, refer to Schemathesis extending documentation: https://schemathesis.readthedocs.io/en/stable/guides/extending/

Example if there need to add custom header in each request, then it is possible to import library with hook:

*** Settings ***
Variables           authentication.py
Library             SchemathesisLibrary
...                     url=http://127.0.0.1/openapi.json
...                     hook=${CURDIR}/hook_filter.py

Test Template       Wrapper


*** Test Cases ***
All Tests
    Wrapper    test_case_1


*** Keywords ***
Wrapper
    [Arguments]    ${case}
    Call And Validate    ${case}    auth=${BASIC_AUTH_TUPLE}

And when hook_filter.py looks like:

import schemathesis


global_count_count = 0


@schemathesis.hook
def filter_query(ctx, query) -> bool:
    method = ctx.operation.method.lower().strip()
    if method == "put":
        global global_count_count
        global_count_count += 1
        if global_count_count > 2:
            return False
    return True

Then only two test with PUT request are generated.

Pabot Support

Pabot is a parallel executor for Robot Framework tests, and SchemathesisLibrary supports it.

However, there's a crucial point to consider. Because SchemathesisLibrary uses DataDriver to generate tests dynamically, you cannot use Schemathesis's built-in parallel execution feature (--workers option).

When using Pabot, you are responsible for organizing your test suites to avoid generating the same tests in multiple parallel processes. A good strategy might be to split your test into different suites, where each suite targets a specific scenario.

For example, you could create separate suites for:

  • A user that is not found in the system.
  • A user that is found and has valid credentials.
  • A user that is found but has invalid credentials.

This approach ensures that each Pabot process works on a unique set of tests. Since every API and system is different, a universal rule for structuring suites is not possible, but this scenario-based division might be good starting point.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

robotframework_schemathesislibrary-2.5.0.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file robotframework_schemathesislibrary-2.5.0.tar.gz.

File metadata

  • Download URL: robotframework_schemathesislibrary-2.5.0.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for robotframework_schemathesislibrary-2.5.0.tar.gz
Algorithm Hash digest
SHA256 82e19e4fa8031a8beb1a2b0860d58bf6a32519c2bdd69c59b68b043d56b5ec18
MD5 91500702ecc5b29f82704a8d747d4bc7
BLAKE2b-256 3b61ad7d127026961f1dafea29f8f5b30ba1003790d86cec7efd5280e0aa3363

See more details on using hashes here.

File details

Details for the file robotframework_schemathesislibrary-2.5.0-py3-none-any.whl.

File metadata

  • Download URL: robotframework_schemathesislibrary-2.5.0-py3-none-any.whl
  • Upload date:
  • Size: 14.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for robotframework_schemathesislibrary-2.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 09c542d65b1af4cab921d5dd634b86c15c37733514ca6d936550112fe9e1775f
MD5 7ef513e5ad8cfbe1dbb2ab0f484cf134
BLAKE2b-256 41ebf445dc45a70ae95cdd1da4b6acb48bc34a32a47ec87567fdba34670f6c0f

See more details on using hashes here.

Release history Release notifications | RSS feed

2.7.0

2 files

2.6.0

2 files

This release

2.5.0 This release

2 files

2.4.0

2 files

2.3.3

2 files

2.3.2

2 files

2.3.1

2 files

2.3.0

2 files

2.2.0

2 files

2.1.0

2 files

2.0.0

2 files

1.2.0

2 files

1.1.2

2 files

1.1.1

2 files

1.1.0

2 files

1.0.0

2 files

0.53.0

2 files

0.52.0

2 files

0.51.0

2 files

0.50.0

2 files

0.49.0

2 files

0.48.0

2 files

0.47.0

2 files

0.46.0

2 files

0.45.0

2 files

0.44.0

2 files

0.43.0

2 files

0.42.0

2 files

0.41.0

2 files

0.40.0

2 files

0.39.0

2 files

0.38.0

2 files

0.37.0

2 files

0.36.0

2 files

0.35.0

2 files

0.34.0

2 files

0.33.0

2 files

0.32.0

2 files

0.31.0

2 files

0.30.0

2 files

0.29.0

2 files

0.28.0

2 files

0.27.0

2 files

0.26.0

2 files

0.25.0

2 files

0.24.0

2 files

0.23.0

2 files

0.22.0

2 files

0.21.0

2 files

0.20.0

2 files

0.19.0

2 files

0.18.0

2 files

0.17.0

2 files

0.16.0

2 files

0.15.0

2 files

0.14.0

2 files

0.13.0

2 files

0.12.0

2 files

0.11.0

2 files

0.10.0

2 files

0.9.0

2 files

0.8.0

2 files

0.7.0

2 files

0.6.0

2 files

0.5.0

2 files

0.3.0

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page