Form Complex Requests¶
In this tutorial, we will demonstrate using an HTTP request with special context where we can set cookies and HTTP requests with additional Configuration for redirections and connection timeouts.
1. Create Steps Language File¶
Right click on the Steps folder -> New
-> Steps
.
Write ComplexGetRequest
in the File name field and click `OK resulting in a new window with a Stepdef and Model template.
Replace the text 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 29 30 31 32 33 34 | stepdef "execute cookie-get request" cookieStore := Http.newCookieStore() // create cookie and add to store cookie := Http.newCookie("MyName", "MyAge") cookie.setDomain("httpbin.org") // without protocol `http` or `https` cookie.setPath("/cookies") // exact slashes are required cookieStore.addCookie(cookie) // create client client := Http.newClient() clientContext := Http.newHttpClientContext() clientContext.setCookieStore(cookieStore) request := Http.get("https://httpbin.org/cookies") .build() // execute request with given context response := client.execute(request, clientContext) response.writeToFile(File.fromProject("cookie-get-response.txt")) end stepdef "execute no redirect request" // build no redirect configuration requestConfiguration := Http.configure() .setRedirectsEnabled(false) // set true to see HTTP/1.1 200 .setConnectTimeout(100000) .build() request := Http.get("https://httpbin.org/redirect/6") .setConfig(requestConfiguration) .build() response := Http.executeHttpRequest(request) println(response.getStatusLine()) response.writeToFile(File.fromProject("no-redirect-response.txt")) end |
Note |
---|
This time our file contains two Stepdefs. |
2. Create Feature File¶
Right click on the features folder -> New
-> Feature
.
Write ComplexGetRequest
in the File name field, Complex Get Request
in the Scenario name and click OK
.
Replace the Feature File template with the following text:
1 2 3 4 5 | Feature: ComplexGetRequests Scenario: Complex Get Requests # Execution And execute cookie-get request And execute no redirect request |
Execute the Feature File by right-clicking on the Feature file -> Run...
, which will create a file called cookie-get-response.txt
in the project root directory.
The file will contain the following:
1 2 3 4 5 | { "cookies": { "MyName": "MyAge" } } |
Another file called no-redirect-response.txt
will also be located in the project root directory after the execution:
1 2 3 4 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <title>Redirecting...</title> <h1>Redirecting...</h1> <p>You should be redirected automatically to target URL: <a href="/relative-redirect/5">/relative-redirect/5</a>. If not click the link. |
Look for HTTP/1.1 302 FOUND
in the execution output at the bottom of intaQt Studio.
Your project structure should now look like this: