Other Commands - TestlumFramework/Testlum GitHub Wiki
Testlum provides powerful tools for working with ElasticSearch and executing Shell scripts as part of your testing scenarios.
- ๐
ElasticSearch
- ๐ป
Shell
ElasticSearch
The elasticsearch
command allows you to perform operations on an Elasticsearch cluster, such as POST
, GET
, PUT
, DELETE
, and HEAD
, inside your test scenarios.
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
comment |
String | โ | - | Description of the Elasticsearch operation |
alias |
String | โ | - | Unique name from your integration.xml setup |
condition |
Boolean Expression | โ | - | Condition to execute this step |
threshold |
Integer (ms) | โ | - | Max allowed time for execution (failure if exceeded) |
Each Elasticsearch method block (<post>
, <get>
, <put>
, <delete>
, <head>
) may contain the following sections:
<post endpoint="/news/_doc/1">
-
endpoint
โ API path to the Elasticsearch document or index.
Parameter | Description |
---|---|
code |
Expected HTTP response code (e.g., 200, 201) |
file |
File with expected response data for validation |
header |
Name and expected value for response header validation |
<response code="201" file="expected_2.json"> <header name="content-length" data="152"/> </response>
Parameter | Description |
---|---|
name |
Header name (e.g., Content-Type ) |
data |
Header value (e.g., application/json ) |
<header name="Content-Type" data="application/json"/>
You can define a body in several ways depending on the method:
<body> <from file="request_2.json"/> </body>
- Load JSON content from file stored at the same folder with
scenario.xml
.
<body> <raw> { "title": "New Document", "content": "This is a test." } </raw> </body>
- Directly define raw JSON inside the scenario.
Parameter | Description |
---|---|
name |
Parameter name (e.g., title ) |
data |
Parameter value (e.g., Test ) |
Useful when constructing simple dynamic request bodies.
Parameter | Description |
---|---|
file |
Path to the file |
name |
Form field key name |
fileName |
File name to upload as |
contentType |
MIME type (e.g., application/json ) |
For uploading files or sending multipart data formats.
Inside Elasticsearch methods, always follow this sequence:
- response
- header
- body (from, raw, param, multipart)
- param (URL params)
โ Following this ensures clean and predictable request execution!
<elasticsearch comment="Execute elasticsearch command post" alias="MY_ELASTICSEARCH"> <post endpoint="/news/_doc/1"> <header name="content-type" data="application/json"/> <response code="201" file="expected_2.json"> <header name="content-length" data="152"/> </response> <body> <from file="request_2.json"/> </body> </post> </elasticsearch>
If you immediately execute a
get
request afterpost
,delete
, orput
,
add a small<wait>
(1โ3 seconds) between them to ensure the document becomes available for retrieval.<wait comment="Wait for document availability" time="2" unit="seconds"/>
๐ Tip:
Useheaders
andresponse validation
to make your Elasticsearch queries not only functional but fully testable within Testlum!
Shell
Description:
The<shell>
command is used to execute shell scripts or individual shell commands within your Testlum scenarios. This command interacts with the system's shell (e.g., Bash, Zsh) to run commands or scripts that perform actions directly on the system.
The <shell>
tag allows you to run shell scripts or specific shell commands as a part of your Testlum scenario.
Parameter | Type | Required | Description |
---|---|---|---|
comment |
String | โ | Description of the shell command or script action |
file |
String | โ | Expected file containing results or output for the shell command |
shellFile |
String | โ | Name of the shell script file to execute |
shellCommand |
String | โ | List of individual shell commands to execute |
condition |
Boolean | โ | Condition to determine if this step should be executed |
threshold |
Integer (ms) | โ | Maximum allowed execution time (in milliseconds) |
<shell comment="Execute a shell script" file="expected_1.json"> <shellFile>shell-1.sh</shellFile> <shellCommand>echo "Response:"</shellCommand> <shellCommand>echo "$response"</shellCommand> </shell>
- You can either use
shellFile
to run a complete script orshellCommand
for individual commands within the script.- Make sure your shell script or commands are executable by the system's shell.