Test Scripts
Dothttp provides flexibility of small tests in javascript/python in same file. writing tests are faily simple.
- javascript
- python (preferred)
#
Javascript#
MethodMethod | Parameters | Description |
---|---|---|
test | testName (string), func (function) | Creates a test with the name testName and body func. All tests are executed after the response handler script. |
assert | condition (boolean), message (string) | Checks that the specified condition is true; throws an exception otherwise. The optional message parameter serves as an exception message. |
log | text | Prints text to the response handler or test stdout and then terminates the line. func (function) |
#
PropertiesThe global properties storage, which is used for setting, retrieving, or removing properties.
In your HTTP requests, you can access a variable saved in client.global as variable_name by using the {{variable_name}} syntax.
Method | Parameters | Description |
---|---|---|
set | varName (string), varValue (string) | Saves the variable with the varName name to the storage and sets its value to varValue. |
get | varName (string) | Returns the value of the varName variable. |
isEmpty | Checks whether the global object has no variables defined. | |
clear | varName (string) | Removes the varName variable from the variables storage. |
clearAll | Removes all variables from the variables storage. |
For more information and examples visit jetbrains-client-reference we took inspiration from jetbrains-client reference.
#
HTTP Response referencePropert | Description |
---|---|
body (string or object) | Response content, which is a string or a JSON object if the response's content-type is application/json. |
headers (ResponseHeaders) | The response headers storage object. |
status (int) | Response status, for example, 200 or 404. |
contentType (ContentType) | The contentType object, which holds the data on the Content-Type response header value. |
#
HeadersThe ResponseHeaders object is used for retrieving the data about response headers' values.
Method | Parameters | Description |
---|---|---|
valueOf | headerName (string) | Retrieves the first value of the headerName response header or null if the headerName response header does not exist. |
valuesOf | headerName (string) | Retrieves the array containing all values of the headerName response header. Returns an empty array if the headerName response header does not exist. |
#
ExampleFor more examples visit https://www.jetbrains.com/help/idea/http-response-handling-examples.html
#
Python#
ExecutionExecution follows of request follows this order.
- Pre request script
- Property resolution (default properties in script)
- Dynamic Property resoluiton (
$randomStr
...) - Headers resolution
- Auth resolution
- Body resolution
- certificate (if exists)
- request completion
- test script
#
Availaible librariesHaving pre request scripts are completely sandboxed so not to harm. here are list of method libraires availabile.
- math
- hashlib
- faker
- unittest
- csv
- uuid
- base64
client
(dothttp client)request
(dothttp current executing request)headers
query
payload
data
(attribute/text exists if postdata is text)json
(attribute/(json/dict) exists if postdata is json )header
(attribute/text exists if posted data content-type is defined)filename
(attribute/text exists if postdata is to be read from file)files
(attribute/list exists if postdata is multipart)
response
(availaible for test scripts)properties
(pythondictionary
)set
(to update a property)clear
(to delete a property)clear_all
(to clear all properties)
#
Pre-request scriptPre request script runs before executing each request. Currently support is availabile only for python script. It opens up more possibilites.
Some of its uses
- Custom authentication
- Faking request data
- Some computation
#
WritingPre request scripts are nothing but methods prefixed with pre
defined in script section of dothttp request.
#
Test scriptTest scripts are unit test cases which will be executed. There are two types of writing test scripts
- methods prefixed with
test
. it should not accept any arguments - classes extending
unittest.TestCase
.
#
Writing/example#
Complete Example#
Limitations- failing pre request fails execution of request
- pre request script should not accept any arguments
import
andfilesystem
access is completely blocked and fails pre request.- All assignment on
client
andlibraries
are blocked and fails pre request.