Tests Snippets¶
- The interest of reusable tests
- factorize the test database
- reuse the tests
- limit scripting to design scenarios
These types of tests are to be used in test plan
mode.
Basics actions¶
Hold on a test¶
Important
path of the reusable test /Snippets/Do/01_Wait.tux
This reusable test allows you to wait for xx seconds while the test runs.
Parameter(s) to configure:
Parameters | Description |
DURATION | duration in seconds |
Stop a test¶
Important
path of the reusable test /Snippets/Do/02_Terminate.tux
This reusable test makes it possible to force the stopping of a scenario on error occurences.
Note
It is possible to customize the stop message by setting the variable STOP_TEST_MSG
.
Load test environment¶
Important
path of the reusable test /Snippets/Do/03_Initilize.tux
This reusable test is used to load the test environment data into the cache (ip addresses, server access account, etc.).
- An environment is described with 4 levels:
environment
cluster
node
instance
An environment
may consist of one or more clusters.
{
"PLATFORM": {
"NOM_CLUSTER_1": [ .. ],
"NOM_CLUSTER_2": [ .. ]
}
}
A cluster
consists of a list of nodes.
{
"NOM_CLUSTER_1": [
{ "NOM_NOEUD_1": { .. },
{ "NOM_NOEUD_2": { .. }
]
}
A node
consists of one or more instances.
{
"NOM_NOEUD_1": {
"COMMON": { ... },
"INSTANCES": {....}
}
}
An instance
is made up of several keys / values.
{
"INSTANCES": {
"TYPE_INSTANCE_1": {
"NOM_INSTANCE_1": { ...},
"NOM_INSTANCE_2": { ...}
},
"TYPE_INSTANCE_2": { ... }
}
}
Parameter(s) to configure:
Parameters | Description |
ENVIRONMENT | Link to a shared variable or directly contains JSON . |
Example of a test environment containing an http server with an instance of type rest.
After loading into the cache, the REST instance is accessible by using the NODE_HTTP_REST
key.
All keys in COMMON
are automatically copied to each instance.
{
"PLATFORM": {
"CLUSTER": [
{ "NODE": {
"COMMON": {
"HOSTNAME": "httpbin"
},
"INSTANCES": {
"HTTP": {
"REST": {
"HTTP_DEST_HOST": "httpbin.org",
"HTTP_DEST_PORT": 443,
"HTTP_DEST_SSL": true,
"HTTP_HOSTNAME": "httpbin.org",
"HTTP_AGENT_SUPPORT": false,
"HTTP_AGENT": null
}
}
}
}
}
]
},
"DATASET": [ ]
}
The DATASET
key can contain datasets.
Data Generators¶
Hash SHA¶
Important
path of the reusable test /Snippets/Generators/01_Gen_Sha.tux
This reusable test is used to generate a hash of a value and store it in the cache.
Parameter(s) to configure:
Parameters | Description |
DATA_IN | Hash character string |
CACHE_KEY | Key name |
SHA | Type of hash realize (sha1, sha256, sha512) |
Hash MD5¶
Important
path of the reusable test /Snippets/Generators/01_Gen_Md5.tux
This reusable test is used to generate md5 hash and store it in the cache.
Parameter(s) to configure:
Parameters | Description |
DATA_IN | Hash character string |
CACHE_KEY | Name of the key or the result will be saved in the cache |
UUID¶
Important
path of the reusable test /Snippets/Generators/01_Gen_Uuid.tux
This reusable test is used to generate an uuid and store it in the cache.
Parameter(s) to configure:
Paramètres | Description |
CACHE_KEY | Name of the key to save the result in the cache |
BASE64¶
Important
path of the reusable test /Snippets/Generators/01_Gen_Base64.tux
This reusable test is used to encode or decode a string and store the result in the cache.
Parameter(s) to configure:
Parameters | Description |
CACHE_KEY | Name of the key to save the result in the cache |
DECODE | Set to True to encode |
ENCODE | To set to True to decode |
URLSAFE | Set to True if the result after encoding is to be used in an url |
STR_BASE64 | Character string to encode / decode |
GZIP¶
Important
path of the reusable test /Snippets/Generators/01_Gen_Gzip.tux
This reusable test can compress or uncompress a string and store the result in the cache.
Parameter(s) to configure:
Parameters | Description |
CACHE_KEY | Key name |
COMPRESS | To set to True to compress |
UNCOMPRESS | Set to True to decompress |
STR_GZIP | Character string to compress / decompress |
Networks protocols¶
SSH¶
Important
path of the reusable test /Snippets/Protocols/01_Send_SSH.tsx
This reusable test is used to send a sequence of ssh commands.
It is used in conjunction with the reusable test /Snippets/Do/03_Initilize.tux
to load an environment into the cache.
Parameter(s) to configure:
Parameters | Description |
SERVERS | List of servers to contact |
COMMANDS | List of commands to run on the remote machine |
TIMEOUT_CONNECT | Max time to connect to the remote machine |
The COMMANDS parameter is waiting for one or more blocks of 4 lines. Each block must respect the following formalism:
- A comment explaining the action, this information is used to initialize the test step
- The command to execute
- The string expected on the screen, if the expected value is not found then the step will be in error. (optional line)
- empty
Warning
Each block will be executed even if the previous one is in error.
- The following example performs the following actions:
- Send 3 pings on the remote machine whose ip is stored in the
DEST_HOST
cache - Verification of having the message on the screen indicating that the 3 packets have been sent. Then the mddev value is stored in the cache with the
STATS
key - The second block clears the screen by sending the clear command.
- Finally the test is waiting to find the prompt on the screen
- Send 3 pings on the remote machine whose ip is stored in the
# send a ping
ping -c 3 [!CACHE:SVR:DEST_HOST:]
.*3 packets transmitted, 3 received, 0% packet loss.*mdev = [!CAPTURE:STATS:] ms.*
# clear the screen
clear
.*root@.*
Note
It is possible to run the test multiple times by providing a server list.
Note
By default, the test waits for a maximum of 20 seconds to find the expected string.
This value can be configured with the TIMEOUT
parameter.
Note
By default, the test waits 10 seconds to connect to the remote server.
This value can be configured with the TIMEOUT_CONNECT
parameter.
HTTP¶
Important
path of the reusable test /Snippets/Protocols/01_Send_HTTP.tsx
This reusable test makes it possible to send an HTTP request by checking the response received.
It is used in conjunction with the reusable test /Snippets/Do/03_Initilize.tux
which loads an environment into the cache.
Parameter (s) to configure to set the destination:
Parameters | Description |
SERVERS | List of servers to contact |
TIMEOUT_CONNECT | Max time to connect to the remote machine |
Parameter (s) to configure the HTTP request to send:
Parameter (s) to configure the expected HTTP response (and which will allow to consider the test as valid):
Parameters | Description |
HTTP_RSP_BODY | Body of the expected answer. |
HTTP_RSP_CODE | The expected HTTP code. 200 by default |
HTTP_RSP_HEADERS | List of expected headers |
HTTP_RSP_PHRASE | The expected HTTP sentence. OK by default |
HTTP_RSP_VERSION | The expected HTTP version. HTTP / 1. [0|1] default |
Note
The use of regular expressions is possible to check or save a value in the body of the answer or in the headers.
XML¶
Important
path of the reusable test /Snippets/Protocols/01_Send_XML.tsx
This snippet enable to send HTTP request with XML
in body. The response can be checked too.
This snippet should be used with /Snippets/Do/03_Initilize.tux
to load the test environment in the cache.
Parameter(s) to configure the remote destination:
Parameters | Description |
SERVERS | List of servers to test |
TIMEOUT_CONNECT | Timeout to connect on the remote machine |
Parameter (s) to configure the HTTP request to send:
Parameters | Description |
HTTP_REQ_BODY | Request body |
HTTP_REQ_HEADERS | List of headers to add |
HTTP_REQ_METHOD | HTTP method (GET, POST, etc..) |
HTTP_REQ_URI | URI |
Parameter(s) to configure the expected HTTP response (and the test will be pass in this case):
Parameters | Description |
HTTP_RSP_BODY | Xpaths to check |
HTTP_RSP_CODE | HTTP code expected. 200 by default |
HTTP_RSP_HEADERS | List of expected headers |
HTTP_RSP_NAMESPACES | List of namespaces |
HTTP_RSP_PHRASE | HTTP phrase expected. OK by default |
HTTP_RSP_VERSION | HTTP version expected. HTTP/1.[0|1] by default |
Warning
The test will be failed if the response does not content XML.
JSON¶
Important
path of the reusable test /Snippets/Protocols/01_Send_JSON.tsx
This snippet enable to send a HTTP request with JSON in body and to check the associated response.
This snippet should be used with /Snippets/Do/03_Initilize.tux
to load the test environment in the cache.
Parameter(s) to configure to set the remote machine:
Parameters | Description |
SERVERS | List of remote machine to reach |
TIMEOUT_CONNECT | Timeout of connection with the remote machine |
Parameter(s) to configure the request to send:
Parameters | Description |
HTTP_REQ_BODY | Request body |
HTTP_REQ_HEADERS | List of header to add |
HTTP_REQ_METHOD | HTTP method (GET, POST, etc..) |
HTTP_REQ_URI | URI to call |
Parameter(s) to configure the expected response (and the test will be pass in this case):
Parameters | Description |
HTTP_RSP_BODY | List of xpath to check |
HTTP_RSP_CODE | HTTP code expected. 200 by default |
HTTP_RSP_HEADERS | List of header expected |
HTTP_RSP_PHRASE | HTTP phrase expected. OK by default |
HTTP_RSP_VERSION | HTTP version expected. HTTP/1.[0|1] by default |
Warning
The test will be failed if the response does not content JSON.
User Interface¶
Open application in Windows¶
Important
path of the reusable test /Snippets/UI/01_Win_OpenApp.tux
This snippet enable to open a application on a Windows or Linux machine.
The parameter AGENT_GUI
must be configured with the agent to use.
Parameter(s) to configure:
Parameters | Description |
APP_PATH | Application path to open |
Close an application in Windows¶
Important
path of the reusable test /Snippets/UI/02_Win_CloseApp.tux
This snippet enable to close a application on a Windows or Linux machine.
The parameter AGENT_GUI
must be configured with the agent to use.
Parameter(s) to configure:
Parameters | Description |
APP_NAME | Name of the application to close |
Open a web browser¶
Important
path of the reusable test /Snippets/UI/03_OpenBrowser.tux
This snippet enable to open a browser on a Windows or Linux machine.
The parameter AGENT_GUI_BROWSER
must be configured with the agent to use.
Parameter(s) to configure:
Parameters | Description |
LOADING_URL | Website url to load |
- It’s possible to select the browser to user, the following browsers are supported:
- Firefox
- Chrome
- Internet Explorer
- Opera
- Edge
Note
the url must started with http://
or https://
Close a web browser¶
Important
path of the reusable test /Snippets/UI/03_CloseBrowser.tux
This snippet enable to close a browser on a Windows or linux machine.
The parameter AGENT_GUI_BROWSER
must be configured with the agent to use.
Checks¶
XML checks¶
Important
path of the reusable test /Snippets/Verify/01_Check_XML.tux
This snippet enable to check a XML content with xpath.
Parameter(s) to configure:
Parameters | Description |
XML_STR | raw XML to inspect |
XML_XPATH | xpath |
XML_NAMESPACES | namespaces definitions |
Example of value for the XML_STR
parameter:
<NewDataSet>
<Table>
<Country>France</Country>
<City>Le Touquet</City>
</Table>
<Table>
<Country>France</Country>
<City>Agen</City>
</Table>
<Table>
<Country>France</Country>
<City>Cazaux</City>
</Table>
<Table>
<Country>France</Country>
<City>Bordeaux / Merignac</City>
</Table>
<Table>
<Country>France</Country>
<City>Bergerac</City>
</Table>
</NewDataSet>
Example of value for the XML_XPATH
parameter.
(//NewDataSet/Table)[1]/City [!CAPTURE:CITY:]
The value will be accessible from the cache with the CITY
key.
JSON checks¶
Important
path of the reusable test /Snippets/Verify/01_Check_JSON.tux
This snippet enable to check JSON content with jsonpath
Parameter(s) to configure:
Parameters | Description |
JSON_STR | Json to inspect |
JSON_XPATH | jsonpath |
Example of value for the JSON_STR
parameter:
{
"args": {},
"headers": {
"Connection": "close",
"Host": "httpbin.org",
"User-Agent": "ExtensiveTesting"
},
"origin": "190.117.217.129",
"url": "https://httpbin.org/get"
}
Example of value for the JSON_XPATH
parameter.
headers.Connection [!CAPTURE:CX:]
The value will be accessible from the cache with the CX
key.