How to Validate Response Status Line?
The first line returned in the Response from Server is called Status Line. Status line is composed of three sub strings
- Http protocol version
- Status Code
- Status Code’s string value
During a success scenario a status line will look something like this “HTTP/1.1 200 OK”. First part is Http protocol (HTTP/1.1). Second is Status Code (200). Third is the Status message (OK).
Just as we go the Status Code in the line above, we can get the Status Line as well. To get the Status line we will simply call the Response.getStatusLine() method. Here is the code to do that.
1 2 3 4 5 6 7 8 9 10 11 | @Test public void GetWeatherStatusLine() { RestAssured.baseURI = "http://restapi.demoqa.com/utilities/weather/city"; RequestSpecification httpRequest = RestAssured.given(); Response response = httpRequest.get("/Hyderabad"); // Get the status line from the Response and store it in a variable called statusLine String statusLine = response.getStatusLine(); Assert.assertEquals(statusLine /*actual value*/, "HTTP/1.1 200 OK" /*expected value*/, "Correct status code returned"); } |
Last modified: Monday, 27 January 2020, 12:19 PM