Logo
2023.9.19

Common Items of Operations

Abstract

GeekLoad contains many different operations to simulate client applications. Each of these operations, in addition to a number of unique properties and functions, has a set of common features.

Request operation usage

Connections

To start working with the request, you need to get the connection object by specifying the server URL or the URL of the base API path.
The presence of a slash at the end of the URL connection does not matter in all cases.

Loading...

When creating a connection object, the connection to the server does not occur.
You can make the connection explicitly. In this case, you will receive the duration of the request separately from the duration of the connection in all reports:

Loading...

In any case, with further actions with the connection object, a connection to the server will be made, if this has not already been done.

InfoBy default, connections within the lifecycle of a single virtual user are cached.

To disable automatic caching, use the following code:

Loading...

Single call

All operations executing requests work according to the same algorithm:

Loading...

A request build can consist of one or more calls to builder methods.

InfoWhen calling any request builder method, the request is not called directly. The sync\async methods are designed for this.

Chained operation calls

Calls of request operations can be collected in chains. In this case, the assembly of the next request should be started instead of the sync\async methods.

All requests in the chain are executed sequentially and synchronously relative to each other, regardless of the method of starting the chain (sync or async). To save data and transfer it to the following requests in the chain, use Session object.

Loading...

Asynchronous requests

Operations can be performed asynchronously using the async() method and standard JavaScript syntax.

Loading...

then

Generates a sequence of actions to be performed after the successful execution of the operation.
There are tree types of actions: custom code, checking and saving in a special storage object.

InfoThe result of what will be executed inside "then" method will be associated with the corresponding request.

Custom code

To perform checks of any complexity, you can specify a custom handler that returns a Boolean with the result of the check.
If an exception occurs when executing this code, the status of the corresponding operation will be changed to erroneous and execution will continue.

Loading...

You can also simply execute the code without returning the result:

Loading...

Checks

All checks work according to the same algorithm:

Loading...

Any check begins with specifying the source of the data being checked. Then you must specify a comparison expression and, optionally, a custom error message.

Sources

.text

Returns the response body as utf-8 encoded text.

.xPath

Returns the value from the response body selected using XPath.

Parameters
expression
:
string
- xPath expression

.regex

Returns the value obtained using a regular expression.

Parameters
expression
group
index
:
:
:
string | RegExp
number
number
- Regular expression.
- The index of the regular expression group from which the value will be derived. Default value is 0.
- Index of occurrence. By default it is 1.

Expressions

.not

Inverts the expression.

.exists

Checks the existence of the value.

Parameters
name
:
string
- The name of the desired value.

.equal

Checks that the received value is equal to the reference value.

Parameters
value
:
any
- The reference value.

.less

Checks that the received value is less than the reference value.

Parameters
value
:
any
- The reference value.

.great

Checks that the received value is great than the reference value.

Parameters
value
:
any
- The reference value.

.contains

Checks that the received value contains the reference value.

If the received value is a string, then the occurrence of the string is checked.
If the received value is an array, then the equality of the reference value to one of the array elements is checked.

Parameters
value
:
any
- The reference value.

.isContained

Checks that the reference value contains the received value.

If the received value is a string, then the occurrence of the string is checked.
If the received value is an array, then the equality of the reference value to one of the array elements is checked.

Parameters
value
:
any
- The reference value.

.message

Sets a optional custom error message for a failed check.Sets a custom error message for a failed check.

Parameters
message
:
string
- Custom message.

Session object

To transfer values between requests, you can use not only global variables, but also a specialized Session object. It is available in all scripts of the project:

Loading...

.store

Saving the value in the Session object.

Parameters
name
:
string
- The name of the property in the Session object in which the stored value will be available.

.sync

Starting the synchronous execution of the request and returning the response.

.async

Asynchronous execution of the operation starts and returns a promise that returns the result of the operation.

.name

Setting a custom name for the operation. This name is used in detailed operation reports and for SLA control.

Parameters
name
:
String
- Custom name of operation
InfoIt is possible to set the same name for several operations, in this case these operations will be combined into one group when calculating aggregated metrics.

.pause

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

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