Logo
2023.9.19

Script Operations

Abstract

InfoBe sure to read the article about the common features of operations.

HTTP/1

Executing HTTP/1 requests and receiving responses from the server. It can work with HTTPS traffic.

Loading...

.get (post, put, head, delete, patch, options)

Assigns the appropriate HTTP request method.

Parameters
path
:
string
- Relative path to the request endpoint. The root path is the connection url. At the end of the path after the "?" character you can specify query parameters.

.query

Adding a parameter to a request's query.

Parameters
name
value
:
:
string
any
- Parameter name
- Parameter value

Instead of multiple calls to this method, it is possible to make one call by passing an object with multiple query part as a parameter:

Loading...

.body

Adding a data to a request's body.

Parameters
value
:
string | object
- Body value. Objects are saved as json, and the Content-type: application/json header is automatically set

Response

The result of executing the request is placed in a special "response" object.

Loading...

This object contains several methods and properties for getting data:

.statusCode

This property returns the response code from the server.

.statusLine

This property returns the status string of the response. For example "HTTP/1.1 200 OK"

.header

This method returns the header by name. In case of multiple headers with the same name, the first one is returned.

Parameters
name
:
string
- Name of header

.body

This property returns the body object of the response which contains several properties for getting data:

.size

This property returns the size of the body data in bytes.

.asText

This property returns the raw text of the response. By default, UTF-8 encoding is used.

.asObject

This property returns the js object received from the json response. If the json is invalid, an exception will be thrown.

свойство возвращает значение по хпаф выражению из json или xml

.asBytes

This property returns the raw body data as array of bytes.

.regex

This property returns the value by regexp expression.

Parameters
expression
group
occurrence
:
:
:
string | regexp
number
number
- Regular expression.
- Index of group in the expression. Default value equal to 0.
- Index of occurrence of the expression in the text. Default value equal to 0.

.xPath

This property returns the value by xPath expression from json or xml. If the json or xml is invalid, an exception will be thrown.

Parameters
expression
:
string
- xPath expression

.auth

Sets the authorization type and required credentials to perform automatic authorization.
This method exists in two variants:

Parameters
value
token
:
:
Enum
String
- Type of authorization.
- Authorization token.
and
Parameters
value
login
password
:
:
:
Enum
String
String
- Type of authorization.
- User's login.
- Password string.
InfoParameterization of usernames and passwords is better implemented using data sources. It is more convenient and secure.
Types of authorization
Basic
Bearer
:
:

HTTP/2

Executing HTTP/2 requests and receiving responses from the server. It can work only with HTTPS traffic.

Loading...
InfoThe basic functionality is identical to the HTTP/1 protocol.

Other methods

Coming soon...

WebSocket

Sending and receive WebSocket messages to and from the server. It can work with HTTPS traffic.

Loading...

.sendText

Sending a text message without waiting for a response.

Parameters
text
:
string
- Text of message

.sendArray

Sending a message with an array of bytes without waiting for a response.

Parameters
text
:
number[]
- Byte array

.receiveText

Waiting for and receiving an incoming text message.

.receiveArray

Waiting for and receiving an incoming byte array message.

Swagger

Executing API call using a Swagger definition.

Loading...

.show

Print a loaded definition to console

InfoThe list of other available methods and their parameters is determined by the loaded definition.

Assert

Checking values outside the request chains. In case of a failed check, a message is posted to the blog.

Loading...

.check

Checking the result of the expression for truth.

Parameters
result
message
:
:
boolean
string
- The result of the expression being checked.
- A message about a failed check.

.equal

Checking the equality of the actual and expected values.

Parameters
actual
expected
message
:
:
:
any
any
string
- The actual value being checked.
- Expected value.
- A message about a failed check.

Log

An object for optional actions with the project execution log.

Loading...

.message

Adding an informational message without changing the final status of the test.

.warning

Adding a warning to the project execution log. If the current final status is better than "Warning", then it changes to "Warning".

.error

Adding a error to the project execution log. If the current final status is better than "Error", then it changes to "Error".

pause

To simulate pauses between the actions of a real user or client application, the pause operation is used.
The delay duration of this operation is equal to a random value in the range between the two parameters of this operation.

InfoDo not use any other methods of organizing execution delays, because this may reduce the performance of the test or distort its results.
Loading...
Parameters
min
max
:
:
string
string
- Minimum delay.
- Maximum delay. Default value equal to minimum delay.

© House of Geeks 2024
Telegram