Forum Discussion
patilawaken
Occasional Contributor
Hi richie,
I am validating JSON schema of response to make sure response has all keys present by making all properties as required, also I can validate further to check the values have correct data types, formats, range and size etc, using single assertion I can assert many things in response.
Now since I am using data driven test where I am setting request body or parameters from data source, I have valid and invalid combinations in the loop.
When I get 200 status code it should validate the JSON schema
When it has 400 status code message should be specific, or may be multiple.
That's the reason I need to have status code assertions,
One way is to have conditional go-to to the assertion test step when response code is 200 and so on, or writing script assertion.
I am validating JSON schema of response to make sure response has all keys present by making all properties as required, also I can validate further to check the values have correct data types, formats, range and size etc, using single assertion I can assert many things in response.
Now since I am using data driven test where I am setting request body or parameters from data source, I have valid and invalid combinations in the loop.
When I get 200 status code it should validate the JSON schema
When it has 400 status code message should be specific, or may be multiple.
That's the reason I need to have status code assertions,
One way is to have conditional go-to to the assertion test step when response code is 200 and so on, or writing script assertion.
nmrao
6 years agoChampion Level 3
Not done this kind.
But you can try below approach, but it needs to be coded.
a. Have a script assertion
b. Extract status from the headers
c. Have a switch construct and do the validation/assertions based on that.
Another approach is (may be crude), define all the required assertions.
Use Events feature, SubmitListerner.afterSubmit method, disable the assertions which are not needed based on the status code.
This way it is not required to write the code for ourself all required assertions.
Not to forget to enable all the assertions back once the test is complete.
But you can try below approach, but it needs to be coded.
a. Have a script assertion
b. Extract status from the headers
c. Have a switch construct and do the validation/assertions based on that.
Another approach is (may be crude), define all the required assertions.
Use Events feature, SubmitListerner.afterSubmit method, disable the assertions which are not needed based on the status code.
This way it is not required to write the code for ourself all required assertions.
Not to forget to enable all the assertions back once the test is complete.
Related Content
- 2 years ago
- 9 months ago
- 4 years ago
Recent Discussions
- 5 days ago