IBM / gauge-api-steps

A Python module providing reusable Gauge steps for API testing
MIT License
6 stars 2 forks source link

Gauge API Steps

License: MIT Python 3.10 Gauge XPath JSONPath OpenSSF Scorecard

A Python module, that provides re-usable steps for testing APIs with the Gauge framework.

Description

This is an extensible and flexible test-automation library for Gauge. It enables users with and without programming knowledge to create end-to-end test scenarios in Markdown syntax. Developers can still easily extend their test scenarios with custom code. Python's urllib is used to make requests against APIs. XML and JSON are supported and API responses can be validated with XPath and JSONPath.

Gauge Step Overview

Find the documentation on all Gauge steps of this project in the overview:

Gauge Step Overview

Quick Start

This is a library for the Gauge framework, so Gauge+Python must be installed first.

It is useful to understand the basic workings of Gauge first. The documentation is excellent.

Installation

This module can be installed from source:

cd path/to/gauge-api-steps
pip install --user .

Or the latest package can be downloaded and installed from PyPi:

pip install gauge-api-steps --user --upgrade

Development

When coding on this project, unit tests can be executed like this:

python -m unittest discover -v -s tests/ -p 'test_*.py'

Contributions are welcome.

Expressions in Parameters

Property Placeholders

Step parameters allow the use of placeholders, that can be defined in the Gauge environment properties files. Some steps also allow to set a placeholder value manually. Property keys act as placeholders, they are defined like ${key}. They will be replaced by its value if such a property key/value pair exists in any env/*/*.properties file or within the execution scope.

Mathematical Expressions

Mathematical expressions can also be evaluated. For example: #{5 + 5 * 5} is evaluated to 30.

It is possible to combine the two features. Placeholder substitution takes place before mathematical expression evaluation.

Functional Expressions

Functional expressions will generate a result during step execution. There are different expressions:

Expression Examples

Note that the property expressions start with $, mathematical expressions with #, and functional expressions with !.

The property "homepage_url" can be defined in env/default/test.properties like this:

homepage_url = https://my-app.net

* Request "GET" "\${homepage_url}/home"

* Print "5 + 6 = #{5 + 6}"

It is also possible to define a property in a step:

* Store "addend" "5"

* Print "5 + 5 5 = #{$addend + 5 5}"

And also to create new properties from old:

* Store "new_url" "${base_url}/id=!{uuid}&created=!{time}"

* Print "!{uuid}"

* Print "!{time}"

* Print "!{time:%Y-%m-%d}"

* With body "!{file:resources/request.json}"

* With body "!{file:resources/request.xml}"

* With body "!{gql:resources/request.gql}"

Internal Placeholders

Following placeholders are used internally to store data over multiple steps:

It is possible to access and manipulate them with certain steps.

Configuration

The Configuration follows the Gauge configuration approach. Some behaviour can be determined with properties.

Configuration Overview

Maintainers

Maintainers