DEV Community

Cover image for Validating HTTP Response Codes in Automated Testing Using Webship-js
webship.co
webship.co

Posted on • Edited on

3 1

Validating HTTP Response Codes in Automated Testing Using Webship-js

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

Top comments (0)

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay