Action Executor
Overview
The Action Executor is a powerful engine that maps command strings to callable functions. It allows you to define automation scripts as JSON action lists, enabling data-driven automation workflows.
The executor also includes all Python built-in functions, so you can call print, len, etc. from action lists.
Action Format
Each action is a list with the command name and optional parameters:
["command_name"] # No parameters
["command_name", {"key": "value"}] # Keyword arguments
["command_name", [arg1, arg2]] # Positional arguments
Basic Usage
from je_web_runner import execute_action
actions = [
["WR_get_webdriver_manager", {"webdriver_name": "chrome"}],
["WR_to_url", {"url": "https://www.google.com"}],
["WR_implicitly_wait", {"time_to_wait": 2}],
["WR_SaveTestObject", {"test_object_name": "q", "object_type": "name"}],
["WR_find_element", {"element_name": "q"}],
["WR_click_element"],
["WR_input_to_element", {"input_value": "WebRunner"}],
["WR_quit"]
]
result = execute_action(actions)
The execute_action() function returns a dict mapping each action to its return value.
Available Commands
WebDriver Manager:
Command |
Description |
|---|---|
|
Create a new WebDriver (params: |
|
Switch to a WebDriver by index |
|
Quit all WebDrivers |
|
Quit the current single WebDriver |
Navigation:
Command |
Description |
|---|---|
|
Navigate to URL (param: |
|
Go forward |
|
Go back |
|
Refresh the page |
Element Finding:
Command |
Description |
|---|---|
|
Find single element by saved test object name (param: |
|
Find multiple elements by saved test object name |
Wait:
Command |
Description |
|---|---|
|
Set implicit wait (param: |
|
Explicit wait with condition |
|
Set script timeout |
|
Set page load timeout |
Mouse Actions:
Command |
Description |
|---|---|
|
Left click (on saved test object or current position) |
|
Right click |
|
Double click |
|
Click and hold |
|
Release held button |
|
Drag from source to target (test object names) |
|
Drag to offset |
|
Hover over element (test object name) |
|
Hover with offset |
|
Move mouse by offset |
Keyboard:
Command |
Description |
|---|---|
|
Press a key |
|
Release a key |
|
Send keys globally |
|
Send keys to saved test object |
Action Chain:
Command |
Description |
|---|---|
|
Execute queued actions |
|
Clear action queue |
|
Pause in chain |
|
Scroll page |
Cookies:
Command |
Description |
|---|---|
|
Get all cookies |
|
Get a specific cookie |
|
Add a cookie |
|
Delete a cookie |
|
Delete all cookies |
JavaScript:
Command |
Description |
|---|---|
|
Execute JavaScript |
|
Execute script |
|
Execute async script |
Window:
Command |
Description |
|---|---|
|
Maximize window |
|
Minimize window |
|
Full screen |
|
Set window size |
|
Set window position |
|
Get window position |
|
Get window rect |
|
Set window rect |
Screenshot & Logging:
Command |
Description |
|---|---|
|
Get screenshot as PNG bytes |
|
Get screenshot as base64 |
|
Get browser logs |
Element Interaction:
Command |
Description |
|---|---|
|
Click the current element |
|
Type text into element |
|
Clear element content |
|
Submit form |
|
Get element attribute |
|
Get element property |
|
Get DOM attribute |
|
Check if element is visible |
|
Check if element is enabled |
|
Check if element is selected |
|
Get CSS property |
|
Take element screenshot |
|
Switch active element |
|
Validate element properties |
|
Get Select for dropdown |
Test Object:
Command |
Description |
|---|---|
|
Save a test object (params: |
|
Clear all saved test objects |
Report:
Command |
Description |
|---|---|
|
Generate HTML report string |
|
Save HTML report to file |
|
Generate JSON report dicts |
|
Save JSON report to file |
|
Generate XML report |
|
Save XML report to file |
Other:
Command |
Description |
|---|---|
|
Switch context (frame, window, alert) |
|
Validate WebDriver properties |
|
Enable/disable test recording |
|
Nested execute action list |
|
Execute from JSON files |
|
Add a Python package to executor |
|
Add a Python package to callback executor |
Execute from JSON Files
from je_web_runner import execute_files
# Execute actions from multiple JSON files
results = execute_files(["actions1.json", "actions2.json"])
JSON file format:
[
["WR_get_webdriver_manager", {"webdriver_name": "chrome"}],
["WR_to_url", {"url": "https://example.com"}],
["WR_quit"]
]
Dict Format Input
The executor also accepts a dict with a "webdriver_wrapper" key:
execute_action({
"webdriver_wrapper": [
["WR_get_webdriver_manager", {"webdriver_name": "chrome"}],
["WR_quit"]
]
})
Add Custom Commands
Register your own functions as executor commands:
from je_web_runner import add_command_to_executor
def my_custom_function(param1, param2):
print(f"Custom: {param1}, {param2}")
add_command_to_executor({"my_command": my_custom_function})
# Now use it in action lists
execute_action([
["my_command", {"param1": "hello", "param2": "world"}]
])
Note
Only types.MethodType and types.FunctionType are accepted.
Passing other callable types will raise WebRunnerAddCommandException.