send http request
Name | Description | Type | Modifier |
---|---|---|---|
uri | Uniform Resource Identifiers (URI) to identify a resource. | String | None |
method | An HTTP request method Possible values:
| Value Set | GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS |
timeout | (Optional) Amount of time to wait for an HTTP response from the server. (units: seconds) Default Value: 300 | String | None |
variable | (Optional) Variable to store the HTTP response. | String | None |
expected code | (Optional) Expected HTTP status code of the response (see ). | String | None |
response file | Full path of file location to which to save the returned response body on the test machine. | String | None |
Example - Case 1: Testing a given Google API to send a message to a recipient
Suppose that you'd like to test a given Google API to send a message to a recipient with the following information:
- API under test: Users.messages: send
- URI:
https://www.googleapis.com/gmail/v1/users/me/messages/send
- Authentication scheme:
OAuth 2.0
- Header fields:
Content-type: application/json
- In the request body, supply a Users.messages resource with the following property as the metadata.
Table 1. Request bodyProperty name Value Description raw bytes The entire email message in base64url encoded string. Tip:To encode a plain text string into a base64url encoded string, you can use the Online Base64URL encoder tool.- Raw body content:
To: logigearepgtest2@gmail.com Subject: This is a test mail   This is a test mail
- Base64url encoded body content:
VG86IGxvZ2lnZWFyZXBndGVzdDJAZ21haWwuY29tClN1YmplY3Q6IFRoaXMgaXMgdGVzdCBtYWlsCgpUaGlzIGlzIGEgdGVzdCBtYWls
- Request body declared in JSON format
{"raw":"base64url encoded string"}
- Raw body content:
setting value
setting max show length 1000000
 
name value
local variable access token ya29.Ci-fa76X0cjJXa2Lx0RM-fRyAQ6-6pboEX-iuT7PR-yYv6D-Rfbos7bs151wiL-O7w
local variable uri https://www.googleapis.com/gmail/v1/users/me/messages/send
local variable tm encoded mail content VG86IGxvZ2lnZWFyZXBndGVzdDJAZ21haWwuY29tClN1YmplY3Q6IFRoaXMgaXMgdGVzdCBtYWlsCgpUaGlzIGlzIGEgdGVzdCBtYWls
 
schema value
authenticate oauth 2 #access token
 
create http request
 
key value
add http header Content-type application/json
 
content
add http body # "{""raw"":""" & tm encoded mail content & """}"
 
uri method timeout variable expected code
send http request # uri POST 100 >>response 200
 
response status header body
parse http response # response >>status >>header >>body
Example - Case 2: Testing SOAP over HTTP-based web services
Suppose that you'd like to test a given API of the GlobalWeather web service to get all major cities by a specific country name.
- API under test: GetCitiesByCountry
- URI:
http://www.webservicex.com/globalweather.asmx
- Header fields:
Content-Type: text/xml
SOAPAction: http://www.webserviceX.NET/GetCitiesByCountry
- In the request body, get all major cities of Australia.
<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <GetCitiesByCountry xmlns="http://www.webserviceX.NET"> <CountryName>Australia</CountryName> </GetCitiesByCountry> </soap:Body> </soap:Envelope>
setting value
setting max show length 1000000
 
name value
local variable uri http://www.webservicex.com/globalweather.asmx
local variable soap body <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><GetCitiesByCountryxmlns="http://www.webserviceX.NET"><CountryName>Australia</CountryName></GetCitiesByCountry></soap:Body></soap:Envelope>
 
create http request
 
key value
add http header Content-Type text/xml
add http header SOAPAction http://www.webserviceX.NET/GetCitiesByCountry
 
content
add http body # soap body
 
uri method timeout variable expected code
send http request # uri POST 100 >>response 200
 
response status header body
parse http response # response >>status >>header >>body
Example - Case 3: Retrieving an attachment through returned response body
Suppose that you'd like to test a given API web service to return an image through an HTTP GET.
- Full path of file location to which to save the returned response body on the test machine: D:\TestData\tmp\testfile.png
create http request
 
key value
add http header scrFile D:\TestData\tmp\testfile.png
 
uri method variable response file
send http request # api download GET >> tm result D:\TestData\tmp\testfile.png
 
response status
parse http response # tm result >> tm status
 
value expected
check value # tm status 200
 
file
check file exists D:\TestData\tmp\testfile.png
- Supported web services:
- An HTTP request must be instantiated via create http request before calling this built-in action.
- variable argument:
- If the variable in argument variable has not been declared, the action creates it as a global.
- If the variable argument is left empty, TestArchitect supplies a global variable with the name _result.
- expected code argument:
- Enter an expected HTTP status of the response. For example, 200 means that the request was successfully received, understood, and accepted. For a full list of HTTP status code, refer to Status Code Definitions.
- When this value is provided, TestArchitect compares the returned status code against the expected status code. An automation error is generated, if these two values do not match each other.
response file argument: A full filename and extension must be declared. Otherwise, TestArchitect reports a warning automation and this argument is ignored.
Notes:- Network resources and mapping network drives are also supported.
- On Windows: In order to specify mapping network drives, please disable User Account Control (UAC).
- In order to see full result returned from this built-in action, set max show length to a higher value.
- This action supports the <ignore> modifier. If the string
<ignore>
is present as the value of any of the arguments, or any argument contains an expression that evaluates to<ignore>
, the action is skipped during execution.