Skip to content

Latest commit

 

History

History
240 lines (141 loc) · 9.42 KB

STEPS.md

File metadata and controls

240 lines (141 loc) · 9.42 KB

Gauge Steps

An overview of how to write Gauge specifications can be found here.
The following Gauge steps are implemented in this module:

Overview

Response CSRF header <header>

* Response CSRF header "X-CSRF-TOKEN"

Define the response header name, that holds the CSRF token, which should be used in subsequent requests. A typical header for CSRF tokens is X-CSRF-TOKEN. Use this step together with Request CSRF header <header> to also specify the request header, that should be used with the token.

Request CSRF header <header>

* Request CSRF header "X-CSRF-TOKEN"

The CSRF token, that has previously been stored with the step Response CSRF header <header>, can be used to make calls with that token now. This step specifies the header name for requests. A typical header for CSRF tokens is X-CSRF-TOKEN.

Base64-encode <text> as <placeholder>

* Base64-encode "login-user" as "username64"

This will encode the string login-user to base64 and store it in the placeholder username64.

Base64-decode <text> as <placeholder>

* Base64-decode "bG9naW4tdXNlcg==" as "username"

This will decode the base64 encoded string bG9naW4tdXNlcg== back to login-user and save it in the placeholder username.

Store <key> <value>

* Store "url" "${domain}${path}"

Store a placeholder value for later use. This can also be used to concatenate other placeholders, like values from API responses.

Load from file <file> as <placeholder>

* Load from file "resources/request.json" as "request_body"

Loads the contents of the file "resources/request.json" into the placeholder request_body. The file must be a text file. This step does not support binary files.

Print <message>

* Print "custom debug: Using these headers in requests: ${_headers}"

Prints the specified text in the terminal output and into the report.

Pretty print <json>

* Pretty print "{\"key\": \"value\"}"

Pretty-prints the specified JSON value in the terminal output and into the report.

Print placeholders

* Print placeholders

Prints the comprehensive list of placeholders in the terminal output and into the report. This includes every property in the used *.env files and the system properties. This can be useful for debugging.

Print headers

* Print headers

Prints out all request and response headers.

Print status

* Print status

Prints out the HTTP status code.

Print body

* Print body

Prints out the response body. If the response is JSON, it will format it.

Append to <file>: <value>

* Append to "reports/users.csv": "${user_name},${user_phone}"

This writes the value to the specified text file. The file must be located inside of the Gauge project. The value is appended to the file, and does not overwrite it, even over multiple test runs. Each append ends with a newline '\n' character.

With header <header>: <value>

* With header "Authorization": "Basic dXNlcjpwYXNzd29yZA=="

Sets a custom HTTP header for the next request.

With body <body>

* With body "{\"request-data\": 5}"

Sets the body for the next request.

Simulate response body: <value>

* Simulate response body: "{\"request-data\": 5}"

Sets the response body for further assertion steps, without the need to make an actual request. This can be helpful during test development, when playing around with XPath or JSONPath expressions.

Request <method> <url>

* Request "GET" "http://localhost"

Execute the request to the server with the optionally previously defined headers and body.

Assert status <status_code>

* Assert status "200"

Make sure the response status matches the expected status.

Assert header <header>: <value>

* Assert header "content-type": "text/javascript"

Make sure that the defined header is present in the response.

Assert jsonpath <jsonpath> exists

* Assert jsonpath "$.resp[0].value" exists

Make sure that exactly one result has been found in the response body under the specified JSONPath.

Assert xpath <xpath> exists

* Assert xpath "//rsp[1]/elem[@color = 'green']" exists

Make sure that exactly one result has been found in the response body under the specified XPath.

Assert jsonpath <jsonpath> exists <expr>

* Assert jsonpath "$.resp[0].value" exists ">=3"

Make sure that the specified amount of results has been found under the specified JSONPath. The expr param allows simple expressions to compare the number of results. See Placeholders and Expressions.

Assert xpath <xpath> exists <expr>

* Assert xpath "//rsp[1]/elem[@color = 'green']" exists "=2"

Make sure that the specified amount of results has been found under the specified XPath. The expr param allows simple expressions to compare the number of results. See Placeholders and Expressions.

Assert jsonpath <jsonpath> contains <text>

* Assert jsonpath ".$fox.jumps" contains "fence"

Make sure that the specified text is contained somewhere under the specified JSONPath. This is not as fine-grained as the corresponding XPath-step.

Assert xpath <xpath> contains <text>

* Assert xpath "string(//fox/jumps)" contains "fence"

Make sure that the specified text is contained in the specified XPath. This differs slightly from the JSONPath version, as XPath allows finer expressions. Therefore, the XPath must return the specific element that includes the text or the text itself. Useful XPath functions in combination with this step are string() and text().

Assert jsonpath <jsonpath> does not contain <text>

* Assert jsonpath ".$fox.jumps" does not contain "dog"

Make sure that the specified text is not contained somewhere under the specified JSONPath. This is the inverted version of Assert jsonpath <jsonpath> contains <text>

Assert xpath <xpath> does not contain <text>

* Assert xpath "string(//fox/jumps)" does not contain "dog"

Make sure that the specified text is not contained somewhere under the specified XPath. This is the inverted version of Assert xpath <xpath> does not contain <text>

Assert jsonpath <jsonpath> = <json_value>

* Assert jsonpath ".$fox.jumps" = "{\"over\": \"fence\"}" * Assert jsonpath ".$fox.jumps.over" = "\"fence\""

Make sure, that the result of the JSONPath exactly matches the specified value. The value can be a simple type or a nested JSON structure.

Assert xpath <xpath> = <xml_value>

* Assert xpath "//fox/jumps" = "<over>fence</over>"

Make sure, that the result of the XPath exactly matches the specified value. The value can be a simple type or a nested XML structure.

Save jsonpath <jsonpath> as <key>

* Save jsonpath ".$fox.jumps" as "obstacle"

Saves the result as a placeholder variable with the given name. That placeholder can be used afterwards in the same scenario.

Save xpath <xpath> as <key>

* Save xpath "//fox/jumps" as "obstacle"

Saves the result as a placeholder variable with the given name. That placeholder can be used afterwards in the same scenario.

Save file <download>

* Save file "downloads/image.png"

Saves the response body as a file. The file must be inside the project directory.