Skip to main content

Provides steps for a Gauge project, that runs tests against APIs

Project description

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.

  • Install this module
  • Find out the path to this module after installation:
    echo $( python -m site --user-site )/gauge_api_steps
    
  • Add that path to the property STEP_IMPL_DIR inside the test project file env/default/python.properties. Paths to multiple modules are comma separated.
    Example on a Mac:
    STEP_IMPL_DIR = /Users/<user>/Library/Python/3.10/lib/python/site-packages/gauge_api_steps, step_impl
    
  • Reload Visual Studio Code
  • Write a new scenario in specs/example.spec. VSC offers auto-completion

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:

  • UUID generation: !{uuid}
  • Time: !{time}, !{time:%Y-%m-%d} - The time format is optional. If omitted, ISO format will be used. The time format pattern is described in the Python language documentation.
  • Encode Base64: !{base64:${user}:${password}} - Encodes the given value into Base64.
  • Encode Base64 in URL-safe mode: !{base64urlsafe:${value}} - Encodes the given value into Base64 with + and / replaced by - and _.
  • Decode Base64: !{base64decode:dXNlcjpwYXNz} - Decodes Base64 back to a string. It can handle standard and URL-safe variants and accepts input without padding.
  • URL-Encode: !{urlencode:?param one/two?} - URL-encodes the given value. Spaces will be replaced with +.
  • URL-Decode: !{urldecode:%3Fparam%20one%2Ftwo%3F} - URL-decodes the given value. +-signs will be replaced with spaces.
  • Load content from text file: !{file:resources/file.json} - The File must be inside the project directory.
  • Load graphQL from file: !{gql:resources/file.gql} or !{graphql:resources/file.gql} - This will automatically generate the JSON format, that can be used in the request body.

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}"

* Print "!{base64:user:password}"

* Print "!{base64urlsafe:param one}"

* Print "!{base64decode:dXNlcjpwYXNz}"

* Print "!{urlencode:?param one/two?}"

* Print "!{urldecode:%3Fparam%20one%2Ftwo%3F}"

* 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:

  • _opener
  • _response_csrf_header
  • _request_csrf_header
  • _csrf_value
  • _body
  • _response
  • _headers

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

Project details


Download files

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

Source Distribution

gauge-api-steps-0.24.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

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

gauge_api_steps-0.24-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file gauge-api-steps-0.24.tar.gz.

File metadata

  • Download URL: gauge-api-steps-0.24.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.11

File hashes

Hashes for gauge-api-steps-0.24.tar.gz
Algorithm Hash digest
SHA256 c3c5a84e01d698d81891d11a56351e5135a698ea26d33b81b5edf1ad156e3cb8
MD5 7b72fa90d53c1c14294a02c5b465f0f8
BLAKE2b-256 6f19e0a857bcad28e3f7f5d20eadea9e4a9ada01f5d4965354656dcf6d01a586

See more details on using hashes here.

File details

Details for the file gauge_api_steps-0.24-py3-none-any.whl.

File metadata

  • Download URL: gauge_api_steps-0.24-py3-none-any.whl
  • Upload date:
  • Size: 14.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.11

File hashes

Hashes for gauge_api_steps-0.24-py3-none-any.whl
Algorithm Hash digest
SHA256 a0987da8c81ee47682f3684e9299d4556a75c785b3d1d47e04ea1a488e030315
MD5 430fdbcbd71b23d6d76490debcfa2d06
BLAKE2b-256 46de13224bab5f1ba9827b90c319df8f785def7b3c308567256ddc72d5c7ef87

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page