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}

Strict mode

Not every operation in a schema can be turned into test cases. Schemathesis skips an operation it can not parse, for example one that refers to a component that does not exist in the schema, and that operation is never tested.

By default the library raises an error that names every operation it could not parse, and the suite does not run. Import the library with strict=False to skip those operations instead, test the rest of the schema, and get a warning in the log that names what was skipped:

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

Use strict=False knowingly. The skipped operations are not tested, the suite still passes, and the only sign that your coverage shrank is a warning in the log.

Regardless of strict, the library always raises an error when the schema produces no test cases at all, because a suite without test cases passes without testing anything.

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.6.0.tar.gz (18.3 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.6.0.tar.gz.

File metadata

  • Download URL: robotframework_schemathesislibrary-2.6.0.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","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.6.0.tar.gz
Algorithm Hash digest
SHA256 d0515d4509bd78d3065a7314c4d87df7c2e99a620e20dd01e5441da28f29ab99
MD5 6c50b78aa06dbb35b2b2f1b2a30e8021
BLAKE2b-256 35ecbb4a9fe481e7f78c54c63be4b2f81a71a39dbeb0da5b3fee1b6494647246

See more details on using hashes here.

File details

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

File metadata

  • Download URL: robotframework_schemathesislibrary-2.6.0-py3-none-any.whl
  • Upload date:
  • Size: 17.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","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.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 df3f1f80c01c503f8b92b2bf90acf03adc9a8bab4c1a0f406aa4f45769a7881d
MD5 46fcc33aaa67ad401d8e0cc88bdd85ba
BLAKE2b-256 b3fe2765de8c0f948258b5da26e9efb7b308f88efcdd95c9b4818fb2d9422aaa

See more details on using hashes here.

Release history Release notifications | RSS feed

2.7.0

2 files

This release

2.6.0 This release

2 files

2.5.0

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