Chaining
Chaining is a way to continue another test that was previously executed
This is the mechanism on how to chain scenarios for Autokin. Let us say that you want to Login the user then use the session token to retrieve user information.
1
POST https://www.autokinjs.com/login
2
Headers:
3
Content-Type: application/json
4
{
5
"username": "juan",
6
"password": "p3dr0"
7
}
8
9
Response:
10
{
11
"sessionId": "2AA21boNhOM5zR3Xgn96qw=="
12
}
13
14
GET https://www.autokinjs.com/user/1001
15
Headers:
16
Content-Type: application/json
17
SessionId: 2AA21boNhOM5zR3Xgn96qw==
18
19
Response:
20
{
21
"id": 1001,
22
"name": "Juan Pedro",
23
"age": 30
24
}
Copied!
So having that we can have this Feature definition:
1
@chaining
2
Feature: My Chaining Feature
3
As Autokin tester
4
I want to verify that all API are working as they should
5
6
Scenario: Login to the system
7
Given that a secure endpoint is up at www.autokinjs.com
8
Given I set Content-Type header to application/json
9
Given I set the JSON body to
10
"""
11
{
12
"username": "juan",
13
"password": "p3dr0"
14
}
15
"""
16
When I POST /login
17
Then response status code should be 200
18
Then I keep the value of body path "$.sessionId" as "userSessionToken"
19
20
Scenario: Get user information
21
Given that a secure endpoint is up at www.autokinjs.com
22
Given I set Content-Type header to application/json
23
Given I set SessionId header from "userSessionToken"
24
When I GET /user/1001
25
Then response status code should be 200
Copied!
As you see in the above example, we login then we store the session token to a variable userSessionToken, the variable name can be anything as long as a one word. Following to our next scenario, as needed by our API, we set the header SessionId to the value of the previously stored data by specifying that we are getting the stored value from the variable userSessionToken.
Last modified 8mo ago
Copy link