Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 133 additions & 0 deletions docs/source/En/doc/callback/callback_doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
Callback Executor
=================

The ``CallbackFunctionExecutor`` allows chaining a trigger function with a callback function.
This is useful for post-test workflows — for example, run a test, then automatically
generate a report.

Basic Usage
-----------

.. code-block:: python

from je_load_density import callback_executor

def after_test():
print("Test finished, generating report...")

callback_executor.callback_function(
trigger_function_name="user_test",
callback_function=after_test,
user_detail_dict={"user": "fast_http_user"},
user_count=10,
spawn_rate=5,
test_time=5,
tasks={"get": {"request_url": "http://httpbin.org/get"}},
)

How It Works
------------

1. The ``trigger_function_name`` is looked up in the executor's ``event_dict``
2. The trigger function is executed with the provided ``**kwargs``
3. After the trigger function completes, the ``callback_function`` is called
4. The return value of the trigger function is returned

Available Trigger Functions
---------------------------

.. list-table::
:header-rows: 1
:widths: 30 70

* - Trigger Name
- Function
* - ``user_test``
- ``start_test()`` — Run a load test
* - ``LD_generate_html``
- ``generate_html()`` — Generate HTML fragments
* - ``LD_generate_html_report``
- ``generate_html_report()`` — Generate HTML report file
* - ``LD_generate_json``
- ``generate_json()`` — Generate JSON data
* - ``LD_generate_json_report``
- ``generate_json_report()`` — Generate JSON report files
* - ``LD_generate_xml``
- ``generate_xml()`` — Generate XML strings
* - ``LD_generate_xml_report``
- ``generate_xml_report()`` — Generate XML report files

Passing Parameters to Callbacks
---------------------------------

With keyword arguments (default):

.. code-block:: python

def my_callback(report_name, format_type):
print(f"Generating {format_type} report: {report_name}")

callback_executor.callback_function(
trigger_function_name="user_test",
callback_function=my_callback,
callback_function_param={"report_name": "final", "format_type": "html"},
callback_param_method="kwargs",
user_detail_dict={"user": "fast_http_user"},
user_count=10,
spawn_rate=5,
test_time=5,
tasks={"get": {"request_url": "http://httpbin.org/get"}},
)

With positional arguments:

.. code-block:: python

def my_callback(arg1, arg2):
print(f"Args: {arg1}, {arg2}")

callback_executor.callback_function(
trigger_function_name="user_test",
callback_function=my_callback,
callback_function_param=["value1", "value2"],
callback_param_method="args",
user_detail_dict={"user": "fast_http_user"},
user_count=10,
spawn_rate=5,
test_time=5,
tasks={"get": {"request_url": "http://httpbin.org/get"}},
)

Parameters
----------

.. list-table::
:header-rows: 1
:widths: 25 15 60

* - Parameter
- Type
- Description
* - ``trigger_function_name``
- ``str``
- Name of function in ``event_dict`` to trigger
* - ``callback_function``
- ``Callable``
- Callback function to execute after the trigger
* - ``callback_function_param``
- ``dict`` or ``list`` or ``None``
- Parameters for the callback (dict for kwargs, list for args)
* - ``callback_param_method``
- ``str``
- ``"kwargs"`` (default) or ``"args"``
* - ``**kwargs``
- —
- Parameters passed to the trigger function

Error Handling
--------------

* ``CallbackExecutorException`` is raised if:

* ``trigger_function_name`` is not found in ``event_dict``
* ``callback_param_method`` is not ``"kwargs"`` or ``"args"``
107 changes: 97 additions & 10 deletions docs/source/En/doc/cli/cli_doc.rst
Original file line number Diff line number Diff line change
@@ -1,19 +1,106 @@
CLI
----
CLI (Command Line Interface)
============================

We can use the CLI mode to execute the keyword.
json file or execute the folder containing the Keyword.json files.
LoadDensity provides a full command-line interface via ``python -m je_load_density``.

The following example is to execute the specified path of the keyword JSON file.
CLI Arguments
-------------

.. code-block::
.. list-table::
:header-rows: 1
:widths: 25 10 65

python je_load_density --execute_file "your_file_path"
* - Argument
- Short
- Description
* - ``--execute_file``
- ``-e``
- Execute a single JSON script file
* - ``--execute_dir``
- ``-d``
- Execute all JSON files in a directory
* - ``--execute_str``
- —
- Execute an inline JSON string
* - ``--create_project``
- ``-c``
- Scaffold a new project with templates

Execute a Single JSON File
--------------------------

Run a test defined in a single JSON keyword file:

The following example is to run all keyword JSON files in a specified folder:
.. code-block:: bash

.. code-block::
python -m je_load_density -e test_scenario.json

python je_load_density --execute_dir "your_dir_path"
The JSON file should follow the action list format:

.. code-block:: json

[
["LD_start_test", {
"user_detail_dict": {"user": "fast_http_user"},
"user_count": 50,
"spawn_rate": 10,
"test_time": 5,
"tasks": {
"get": {"request_url": "http://httpbin.org/get"},
"post": {"request_url": "http://httpbin.org/post"}
}
}]
]

Execute All JSON Files in a Directory
-------------------------------------

Run all JSON keyword files in a specified directory recursively:

.. code-block:: bash

python -m je_load_density -d ./test_scripts/

This scans the directory for all ``.json`` files and executes each one sequentially.

Execute an Inline JSON String
-----------------------------

Execute a JSON action list directly as a string:

.. code-block:: bash

python -m je_load_density --execute_str '[["LD_start_test", {"user_detail_dict": {"user": "fast_http_user"}, "user_count": 10, "spawn_rate": 5, "test_time": 5, "tasks": {"get": {"request_url": "http://httpbin.org/get"}}}]]'

.. note::

On **Windows**, inline JSON strings are automatically double-parsed due to shell
escaping differences. The CLI handles this transparently.

Create a Project
----------------

Scaffold a new project with keyword templates and executor scripts:

.. code-block:: bash

python -m je_load_density -c MyProject

This generates a project directory structure:

.. code-block:: text

MyProject/
└── LoadDensity/
├── keyword/
│ ├── keyword1.json
│ └── keyword2.json
└── executor/
├── executor_one_file.py
└── executor_folder.py

Error Handling
--------------

If no valid argument is provided, the CLI raises a ``LoadDensityTestExecuteException``
and exits with code 1. All errors are printed to stderr.
Loading
Loading