In order to define a variable and assign it with a constant value or a variable value use :
* define [^\d]\S+ = \S+
* define codigo = 7000
So that you need to call the previously defined variable, use double brackets :
For example
Given body body_request_1700.json
* define codigo = 7000
When execute method POST
Then the status code should be 400
And response should be $.code = {{codigo}}
alternatively you could use the value obtained from a response :
Given body body_request_1700.json
When execute method POST
Then the status code should be 200
And response should be $.code = 7114
* define codigo = $.code
You can reference a json file created in the default location (jsons/bodies folder) :
####If the body doesn't need modification of any attribute or value, then this step is all that's required.
Given body \S+
For example
Version 3.3.0.0
Version 3.3.0.1 or newer
Given body name_file.json
Given body jsons/bodies/name_file.json
Or you can create a new folder inside it :
Version 3.3.0.0
Version 3.3.0.1 or newer
Given body new_folder/name_file.json
Given body jsons/bodies/new_folder/name_file.json
I. SET
If you need to modify the value of any attribute in the body, you can use the Step "set value of key in body ".
We don't need the Step "body \S+" in our scenario because this step accesses the entire JSON file and also makes the necessary modifications.
In this case, it requires three parameters: the value to be assigned, the name of the attribute that will take the value of the first parameter, and the path with the name of the JSON file.
For example
And set value 15 of key tags[1].id in body jsons/bodies/body2.json
II. DELETE
####Now, if you need to remove an attribute from the body, you can use Step "delete keyValue in body ", This one requires only two parameters: the attribute name and the name of the JSON file containing the request.
For example
And delete keyValue tags[0].id in body jsons/bodies/body2.json
HTTP Method
The HTTP Methods supported by steps are : GET | POST | PUT | PATCH | DELETE
For example
When execute method POST
Assertions
I. Status Code
The step to assert the HTTP response code is as follows :
the status code should be <number>
For example
Then the status code should be 200
If the HTTP response code is anything other than what is expected, this assertion will result in the test failing.
II. JSON
You can make assertions on any attribute of the obtained response, whether it's integer, float, double, string, or boolean value by referencing it by its name :
For example
And response should be name = Rick Sanchez
Another way to reference it is by prepending "$." before the attribute name :
And response should be $.status = Alive
The following step, allows for validations based on equality or containing a value that matches the response obtained based on the provided parameter.
And verify the response [^\s].+ 'equals' [^\s].*
And verify the response [^\s].+ 'contains' [^\s].*