send http request

Send an HTTP request to a given resource.
NameDescriptionTypeModifier
uri

Uniform Resource Identifiers (URI) to identify a resource.

StringNone
method

An HTTP request method

Possible values:

  • GET: Request data from a specified resource.
  • POST: Submit data to be processed to a specified resource.
  • PUT: Replace all the current representations of the target resource with the uploaded content.
  • DELETE: Remove all the current representations of the target resource given by URI.
  • PATCH: The PATCH method is used to apply partial modifications to a resource.
  • HEAD: The HEAD method asks for a response identical to that of a GET request, but without the response body.
  • OPTIONS: The OPTIONS method is used to describe the communication options for the target resource.

Value SetGET, 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
StringNone
variable

(Optional) Variable to store the HTTP response.

StringNone
expected code

(Optional) Expected HTTP status code of the response (see ).

StringNone
response file

Full path of file location to which to save the returned response body on the test machine.

StringNone
None
This action may be used within the following project items: test modules and user-defined actions.
The following settings are applicable to this action: remove double quotes from cells.
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 body
    Property nameValueDescription
    rawbytesThe 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: [email protected]
      Subject: This is a test mail
      &nbsp
      This is a test mail
                              
                          
    • Base64url encoded body content:
      VG86IGxvZ2lnZWFyZXBndGVzdDJAZ21haWwuY29tClN1YmplY3Q6IFRoaXMgaXMgdGVzdCBtYWlsCgpUaGlzIGlzIGEgdGVzdCBtYWls
    • Request body declared in JSON format {"raw":"base64url encoded string"}
        
        	setting	value			
setting	max show length	1000000			
&nbsp					
	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			
&nbsp					
	schema	value			
authenticate	oauth 2	#access token			
&nbsp					
create http request					
&nbsp					
	key	value			
add http header	Content-type	application/json			
&nbsp					
	content				
add http body	# "{""raw"":""" & tm encoded mail content & """}"				
&nbsp					
	uri	method	timeout	variable	expected code
send http request	# uri	POST	100	>>response	200
&nbsp					
	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			
&nbsp					
	name	value			
local variable	uri	http://www.webservicex.com/globalweather.asmx			
local variable	soap body	&lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;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/"&gt;&lt;soap:Body&gt;&lt;GetCitiesByCountryxmlns="http://www.webserviceX.NET"&gt;&lt;CountryName&gt;Australia&lt;/CountryName&gt;&lt;/GetCitiesByCountry&gt;&lt;/soap:Body&gt;&lt;/soap:Envelope&gt;			
&nbsp					
create http request					
&nbsp					
	key	value			
add http header	Content-Type	text/xml			
add http header	SOAPAction	http://www.webserviceX.NET/GetCitiesByCountry			
&nbsp					
	content				
add http body	# soap body				
&nbsp					
	uri	method	timeout	variable	expected code
send http request	# uri	POST	100	>>response	200
&nbsp					
	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				
&nbsp				
	key	value		
add http header	scrFile	D:\TestData\tmp\testfile.png		
&nbsp				
	uri	method	variable	response file
send http request	# api download	GET	>> tm result	D:\TestData\tmp\testfile.png
&nbsp				
	response	status		
parse http response	# tm result	>> tm status		
&nbsp				
	value	expected		
check value	# tm status	200		
&nbsp				
	file			
check file exists	D:\TestData\tmp\testfile.png			
        
    
  • Supported web services:
    • RESTful (Representational State Transfer architecture).
    • SOAP (Simple Object Access Protocol) over HTTP-based 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.

Copyright © 2024 LogiGear Corporation. All rights reserved. LogiGear is a registered trademark, and Action Based Testing and TestArchitect are trademarks of LogiGear Corporation. All other trademarks contained herein are the property of their respective owners.

LogiGear Corporation

1730 S. Amphlett Blvd. Suite 200, San Mateo, CA 94402

Tel: +1 (650) 572-1400