Other Commands - TestlumFramework/Testlum GitHub Wiki

๐Ÿ” Other Commands

Testlum provides powerful tools for working with ElasticSearch and executing Shell scripts as part of your testing scenarios.

Supported Commands

  • ๐Ÿ”Ž ElasticSearch
  • ๐Ÿ’ป Shell
ElasticSearch

๐Ÿ” 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.

โš™๏ธ General Parameters

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)

๐Ÿ› ๏ธ Inside Elasticsearch Methods

Each Elasticsearch method block (<post>, <get>, <put>, <delete>, <head>) may contain the following sections:

๐Ÿ“ Endpoint

<post endpoint="/news/_doc/1">
  • endpoint โ€” API path to the Elasticsearch document or index.

๐Ÿ“ฉ Response Validation

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>

๐Ÿ“‘ Headers (Request)

Parameter Description
name Header name (e.g., Content-Type)
data Header value (e.g., application/json)
<header name="Content-Type" data="application/json"/>

๐Ÿ“ Body

You can define a body in several ways depending on the method:

1. From File

<body>
  <from file="request_2.json"/>
</body>
  • Load JSON content from file stored at the same folder with scenario.xml.

2. Raw Inline Body

<body>
  <raw>
    {
      "title": "New Document",
      "content": "This is a test."
    }
  </raw>
</body>
  • Directly define raw JSON inside the scenario.

3. Body Parameters (param)

Parameter Description
name Parameter name (e.g., title)
data Parameter value (e.g., Test)

Useful when constructing simple dynamic request bodies.

4. Multipart Body

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.

๐Ÿง  Execution Sequence Reminder

Inside Elasticsearch methods, always follow this sequence:

  1. response
  2. header
  3. body (from, raw, param, multipart)
  4. param (URL params)

โœ… Following this ensures clean and predictable request execution!

๐Ÿงช Real Example

<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>

โณ Important Note on Timing!

If you immediately execute a get request after post, delete, or put,
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:
Use headers and response validation to make your Elasticsearch queries not only functional but fully testable within Testlum!

Shell

๐Ÿ’ป Shell Command

๐Ÿ“– Overview

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.

โš™๏ธ Command: <shell>

The <shell> tag allows you to run shell scripts or specific shell commands as a part of your Testlum scenario.

โš™๏ธ Parameters

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)

๐Ÿงฉ Example Usage โ€” Shell Command

<shell comment="Execute a shell script" file="expected_1.json">
    <shellFile>shell-1.sh</shellFile>
    <shellCommand>echo "Response:"</shellCommand>
    <shellCommand>echo "$response"</shellCommand>
</shell>

โœ… Tips:

  • You can either use shellFile to run a complete script or shellCommand for individual commands within the script.
  • Make sure your shell script or commands are executable by the system's shell.
โš ๏ธ **GitHub.com Fallback** โš ๏ธ