Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Standard REST steps

Given/And

...

SyntaxAction

the response status should be <value>

the response status is <value>

Will check the response status of a REST request against an integer <value>

the response location should be "<value>"

the response location is "<value>"

Will check if the response location of a REST request is equal to a given string

the response should contain "<value>"

the response contains "<value>"

Will check if the response contains a certain key

This step supports standard Spring Expression language as well as a dot notation and a square bracket notation (more info below)

the response should contain "<key>" with value "<value>"

the response contains "<key>" with value "<value>"

Will check if the response contains a certain key with a specific value

This step supports standard Spring Expression language as well as a dot notation and a square bracket notation (more info below)

the response should contain:

the response contains:

Will check if the response contains all keys with corresponding specific values

This step supports standard Spring Expression language as well as a dot notation and a square bracket notation (more info below)

the response should contain <number> entities

the response should contain at least <number> entities

the response should contain at most <number> entities

the response should contain more than <number> entities

the response should contain less than <number> entities

Will check if the number of results in the response matches the given number, depending on the comparison action specified.

Should contain can always be replaced by contains. Entities can also be the singular entity.

response entity "<name>" should contain <number> entities

response entity <number> should contain <number> entities

Will check if the number of child entities of the entity matches the given number. This step supports all comparison actions as the step above.

Should contain can always be replaced by contains. Entities can also be the singular entity.

response entity "<name>" should contain "<key>"

response entity "<name>" contains "<key>"

response entity <number> should contain "<key>"

response entity <number> contains "<key>"

Will check if the named or numbered (1-based) response entity contains a specific key.

This step will fail if the named entity is not present in the response.

This step supports standard Spring Expression language as well as a dot notation and a square bracket notation (more info below)

response entity "<name>" should contain "<key>" with value "<value>"

response entity "<name>" contains "<key>"with value "<value>"

response entity <number> should contain "<key>" with value "<value>"

response entity <number> contains "<key>"with value "<value>"

Will check if the named or numbered (1-based) response entity contains a specific key with a specific value.

This step will fail if the named entity or the specified key is not present in the response.

This step supports standard Spring Expression language as well as a dot notation and a square bracket notation (more info below)

response entity "<name>" should contain:

response entity "<name>" contains:

response entity <number> should contain:

response entity <number> contains:

 

Will check if the named or numbered (1-based) response entity contains a map of values.

This step will fail if the named entity or complete map is not found in the response.

This step supports standard Spring Expression language as well as a dot notation and a square bracket notation (more info below)

The map of values should be structured as a datastructure as follows:

Code Block
| <name1>    | <value1> |
| <name2>    | <value2> |
  

the response should not contain "<value>"

the response does not contain "<value>"

Will check if the response doesn't contain a specific key.

This step supports standard Spring Expression language as well as a dot notation and a square bracket notation (more info below)

the response should not contain "<key>" with value "<value>"

the response does not contain "<key>" with value "<value>"

Will check if the response doesn't contain a specific key with associated value.

This step will not fail if the value of the key is different.

This step supports standard Spring Expression language as well as a dot notation and a square bracket notation (more info below)

the response should not contain:

the response does not contain:

Will check if the response doesn't contain a map with specific keys and associated values.

This step will only fail if at least on of the key-value pairs is found in the response.

This step supports standard Spring Expression language as well as a dot notation and a square bracket notation (more info below)

response entity "<name>" should not contain "<key>"

response entity "<name>" does not contain "<key>"

response entity <number> should not contain "<key>"

response entity <number> does not contain "<key>"

Will check if the named or numbered (1-based) response entity does not a specific key.

This step will fail if the named entity is not present in the response.

This step supports standard Spring Expression language as well as a dot notation and a square bracket notation (more info below)

response entity "<name>" should not contain "<key>" with value "<value>"

response entity "<name>" does not contain "<key>"with value "<value>"

response entity <number> should not contain "<key>" with value "<value>"

response entity <number> does not contain "<key>"with value "<value>"

Will check if the named or numbered (1-based) response entity does not contain a specific key with a specific value.

This step will fail if the named entity is not present in the response, but not if the specified key is not present in the named entity.

This step supports standard Spring Expression language as well as a dot notation and a square bracket notation (more info below)

response entity "<name>" should not contain:

response entity "<name>" does not contain:

response entity <number> should not contain:

response entity <number> does not contain:

 

Will check if the named or numbered (1-based) response entity does not contain a map of values.

This step will fail if the named entity is not found in the response or one of the key-value pairs of the map is found in the response.

This step supports standard Spring Expression language as well as a dot notation and a square bracket notation (more info below)

The map of values should be structured as a datastructure as follows:

Code Block
| <name1>    | <value1> |
| <name2>    | <value2> |
  

the response headers should contain "<key>"

the response headers contain "<key>"

response headers should contain "<key>"

response headers contain "<key>"

Will check if the response headers contain a certain key.

This step supports standard Spring Expression language as well as a dot notation and a square bracket notation (more info below)

the response headers should contain "<key>" with value "<value>"

the response headers contain "<key>" with value "<value>"

response headers should contain "<key>" with value "<value>"

response headers contain "<key>" with value "<value>"

Will check if the response headers contain a certain key and specific value.

This step supports standard Spring Expression language as well as a dot notation and a square bracket notation (more info below)

the response headers should contain:

the response headers contain:

response headers should contain:

response headers contain:

Will check if the response headers contain a certain key and specific value.

This step supports standard Spring Expression language as well as a dot notation and a square bracket notation (more info below)

The map of values should be structured as a datastructure as follows:

Code Block
| <name1>    | <value1> |
| <name2>    | <value2> |

 

Authentication

...

(i) create <type> authentication as "<variable_name>" with parameters:

...

CWB has some built-in support for authenticating rest calls.  The variable rest.base.auth can contain an instance of {{com.foreach.cuke.rest.authentication.Authentication}}.  This authentication will then be applied to all REST requests.  It is also possible to save multiple authentication variables and specify which authentication to use for a particular request.

CWB comes with built-in support for basic and OAuth2 (token) authentication.

Authentication steps

SyntaxAction

(i) create <type> authentication as "<variable_name>" with parameters:

(i) create set <type> authentication as default "<variable_name>" with parameters:

(i) create <type> authentication as default with parameters:

(i) set <type> authentication as default with parameters:

This will create an authentication of type <type> (basic or oauth) and saves it to a variable on the context.

The default When using 'defaulf', the variable name is "rest.base.auth".

 

...

Authentication examples

Using default basic authentication

Code Block
# set the authentication instance
* basic authentication as default with parameters:
  | username | demo_client |
  | password | demo        |
# basic authentication will be sent along
* call get "http://somewhere"

Requesting an OAuth2 token and using the response as default authentication

Code Block
# set an authentication that will request a password grant using the url endpoint
# if url property is not present, "${rest.base.url}/oauth/token" is assumed 
* Given oauth2 authentication as default with parameters:
  | url           | /oauth/token |
  | client_id     | demo_client  |
  | client_secret | demo         |
  | grant_type    | password     |
  | scope         | full         |
  | username      | admin        |
  | password      | admin        |

Manual authentication using an access_token

Code Block
# retrieve a valid token from somewhere, and set it as OAuth2 bearer authorization
* call get "/api/retrieve-token"
* oauth2 authentication as default with parameters:
  | type         | manual           |
  | access_token | #{response.body} |

Using a specific authentication for a request

Specifying a specific named authentication can be done by adding an auth type parameter on the request.

Code Block
Scenario: Using a custom basic authentication for a request
  Given basic authentication as "my-authentication" with parameters:
    | username | demo_client |
    | password | demo        |
  When i call get "/webpage" with parameters:
    | type  | name       | value              |
    | auth  | -          | my-authentication  |

Anchor
notationsupport
notationsupport
Notation support

...