Analyze Responses¶
An HTTP Response can be analyzed by reading content such as its headers and status line. This tutorial will demonstrate how to create one last test case to do this.
1. Create Steps File¶
Right click on the Steps folder -> New
-> Steps
.
Write AnalyzingHttpResponse
in the File name field and click OK
.
Replace the Stepdef and Model templates with the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | stepdef "execute response analyzer" request := Http.get("http://httpbin.org/html") .build() response := Http.executeHttpRequest(request) statusLineString := response.getStatusLine().toString() println("Status Line = " + statusLineString) if not statusLineString.contains("200 OK") then assert false ! "error, status code != 200 (OK)" end httpEntity := response.getEntity() println("ResponseEntity = " + httpEntity) httpProtocol := response.getProtocolVersion() println("ProtocolVersion = " + httpProtocol) httpConnectionHeader := response.getFirstHeader("Connection") println("Connection Header = " + httpConnectionHeader) httpAllHeaders := response.getAllHeaders() println("All Headers:") for header in httpAllHeaders println(header) end end |
2. Create Feature File¶
Right click on the features folder -> New
-> Feature
.
Write AnalyzingHttpResponse
in the File name field, Analyzing HTTP Response
in the Scenario name and click OK
.
Replace the Feature File template with the following text:
1 2 3 4 | Feature: AnalyzingHttpResponse Scenario: Analyzing HTTP Response # Execution And execute response analyzer |
Execute the Feature File by right-clicking on the Feature File -> Run...
, and the step execution output should contain output similar to the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | [INFO]: Status Line = HTTP/1.1 200 OK [INFO]: ResponseEntity = ResponseEntityProxy{[Content-Type: text/html; charset=utf-8,Content-Length: 3741,Chunked: false]} [INFO]: ProtocolVersion = HTTP/1.1 [INFO]: Connection Header = Connection: keep-alive [INFO]: All Headers: [INFO]: Connection: keep-alive [INFO]: Server: meinheld/0.6.1 [INFO]: Date: Thu, 22 Feb 2018 13:58:54 GMT [INFO]: Content-Type: text/html; charset=utf-8 [INFO]: Content-Length: 3741 [INFO]: Access-Control-Allow-Origin: * [INFO]: Access-Control-Allow-Credentials: true [INFO]: X-Powered-By: Flask [INFO]: X-Processed-Time: 0 [INFO]: Via: 1.1 vegur |