Checking HTTP response codes is essential for web reliability. These codes indicate server status, helping to identify issues like broken links or unauthorized access, ensuring optimal performance and a better user experience.
In this blog, we will test HTTP response codes using the World Meteorological Organization website (https://wmo.int/
) as an example.
We need step definitions to create the scenarios required for testing, such as:
Then the response status code should be {number}
This step definition is used after making a request to the web service under test. Once the response is received, this step definition asserts HTTP status code returned by the server matches the expected code.
Example:
Then the response status code should be 200
The status code 200 refers to a successful request. Meaning that the server has processed the request and returned the appropriate response.
Example:
Then the response status code should not be 404
The status code 404 refers to that the requested resource not found on the server. Meaning a possible error or invalid URL. So that it should not be 404.
You can see more step definitions: https://webship.co/docs
See the full article: https://webship.co/blog/validating-http-response-codes-automated-testing-using-webship-js
The above is the detailed content of Validating HTTP Response Codes in Automated Testing Using Webship-js. For more information, please follow other related articles on the PHP Chinese website!