Keyword Usage¶
This document outlines the available keywords for the Optics Framework, which can be used in the test_modules.csv file to define test steps. Keywords are derived from the framework's Python API, with method names converted to a space-separated format (e.g., press_element becomes Press Element). Each keyword corresponds to a specific action, verification, or control flow operation. Below, each keyword includes detailed parameter explanations to guide their usage.
Keyword data sources¶
- Element-based keywords (Press Element, Assert Elements, Type Text, Validate Element, etc.) use element data from element files (CSV with columns such as
element_name/element_id, or YAML with anelementskey). Element names in test steps refer to these definitions. - Invoke API uses API definition data from API YAML files (top-level
apiorapis). It does not use element files. You reference an API by the identifiercollection.api_name.
Action Keywords¶
These keywords handle interactions with the application, such as clicking, swiping, and text input.
Press Element¶
Presses a specified element on the screen.
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
element | Required | The target to press. Can be: • Text: A string to locate via text detection (e.g., "Home", ${Home_text})• XPath: An XPath expression for Appium/Selenium (e.g., //android.widget.Button[@resource-id="id"])• Image: A filename of an image in input_templates/ (e.g., "home.png", ${Home_image}) | - |
repeat | Optional | Number of times to press the element (integer) | 1 |
offset_x | Optional | Horizontal offset in pixels from the element's center (integer) | 0 |
offset_y | Optional | Vertical offset in pixels from the element's center (integer) | 0 |
index | Optional | Index of the element if multiple matches are found (integer, 0-based) | 0 |
aoi_x | Optional | X percentage of Area of Interest top-left corner (0-100, float) | 0 |
aoi_y | Optional | Y percentage of Area of Interest top-left corner (0-100, float) | 0 |
aoi_width | Optional | Width percentage of Area of Interest (0-100, float) | 100 |
aoi_height | Optional | Height percentage of Area of Interest (0-100, float) | 100 |
event_name | Optional | A string identifier for logging or triggering events (e.g., "click_home") | - |
Example:
Press By Percentage¶
Presses at percentage-based coordinates on the screen.
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
percent_x | Required | X-coordinate as a percentage of screen width (float, 0.0 to 1.0, e.g., 0.5 for 50%) | - |
percent_y | Required | Y-coordinate as a percentage of screen height (float, 0.0 to 1.0) | - |
repeat | Optional | Number of times to press (integer) | 1 |
event_name | Optional | A string identifier for the press event (e.g., "center_press") | - |
Example:
Press By Coordinates¶
Presses at absolute coordinates on the screen.
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
coor_x | Required | X-coordinate in pixels (integer, e.g., 500) | - |
coor_y | Required | Y-coordinate in pixels (integer, e.g., 800) | - |
repeat | Optional | Number of times to press (integer) | 1 |
event_name | Optional | A string identifier for the press event (e.g., "tap_event") | - |
Example:
Detect And Press¶
Detects a specified element and presses it if found.
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
element | Required | The element to detect and press (Image template, OCR template, or XPath) | - |
timeout | Optional | Timeout for the detection operation in seconds (integer) | 30 |
event_name | Optional | A string identifier for the press event | - |
Example:
Swipe¶
Performs a swipe action in a specified direction from given coordinates.
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
coor_x | Required | X coordinate of the swipe starting point (integer) | - |
coor_y | Required | Y coordinate of the swipe starting point (integer) | - |
direction | Optional | The swipe direction: up, down, left, or right | right |
swipe_length | Optional | The length of the swipe in pixels (integer) | 50 |
event_name | Optional | A string identifier for the swipe event | - |
Example:
Swipe Until Element Appears¶
Swipes in a specified direction until an element appears.
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
element | Required | The target element to find (Image template, OCR template, or XPath) | - |
direction | Required | The swipe direction: up, down, left, or right | - |
timeout | Required | Timeout in seconds until element search is performed (integer) | - |
event_name | Optional | A string identifier for the swipe event | - |
Example:
Swipe From Element¶
Performs a swipe action starting from a specified element.
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
element | Required | The element to swipe from (Image template, OCR template, or XPath) | - |
direction | Required | The swipe direction: up, down, left, or right | - |
swipe_length | Required | The length of the swipe in pixels (integer) | - |
aoi_x | Optional | X percentage of Area of Interest top-left corner (0-100, float) | 0 |
aoi_y | Optional | Y percentage of Area of Interest top-left corner (0-100, float) | 0 |
aoi_width | Optional | Width percentage of Area of Interest (0-100, float) | 100 |
aoi_height | Optional | Height percentage of Area of Interest (0-100, float) | 100 |
event_name | Optional | A string identifier for the swipe event | - |
Example:
Scroll¶
Performs a scroll action in a specified direction.
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
direction | Required | The scroll direction: up, down, left, or right | - |
event_name | Optional | A string identifier for the scroll event | - |
Example:
Scroll Until Element Appears¶
Scrolls in a specified direction until an element appears.
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
element | Required | The target element to find (Image template, OCR template, or XPath) | - |
direction | Required | The scroll direction: up, down, left, or right | - |
timeout | Required | Timeout in seconds for the scroll operation (integer) | - |
event_name | Optional | A string identifier for the scroll event | - |
Example:
Scroll From Element¶
Performs a scroll action starting from a specified element.
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
element | Required | The element to scroll from (Image template, OCR template, or XPath) | - |
direction | Required | The scroll direction: up, down, left, or right | - |
scroll_length | Required | The length of the scroll in pixels (integer) | - |
aoi_x | Optional | X percentage of Area of Interest top-left corner (0-100, float) | 0 |
aoi_y | Optional | Y percentage of Area of Interest top-left corner (0-100, float) | 0 |
aoi_width | Optional | Width percentage of Area of Interest (0-100, float) | 100 |
aoi_height | Optional | Height percentage of Area of Interest (0-100, float) | 100 |
event_name | Optional | A string identifier for the scroll event | - |
Example:
Enter Text¶
Enters text into a specified element.
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
element | Required | The target element (Image template, OCR template, or XPath) | - |
text | Required | The text to be entered | - |
aoi_x | Optional | X percentage of Area of Interest top-left corner (0-100, float) | 0 |
aoi_y | Optional | Y percentage of Area of Interest top-left corner (0-100, float) | 0 |
aoi_width | Optional | Width percentage of Area of Interest (0-100, float) | 100 |
aoi_height | Optional | Height percentage of Area of Interest (0-100, float) | 100 |
event_name | Optional | A string identifier for the input event | - |
Example:
Enter Text Direct¶
Enters text directly using the keyboard without targeting a specific element.
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
text | Required | The text to be entered | - |
event_name | Optional | A string identifier for the input event | - |
Example:
Enter Text Using Keyboard¶
Enters text or presses a special key using the keyboard. Supports special keys like <enter>, <tab>, etc.
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
text_input | Required | The text or special key identifier to send (e.g., "hello" or " | - |
event_name | Optional | A string identifier for the keyboard event | - |
Example:
Enter Number¶
Enters a specified number into an element.
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
element | Required | The target element (Image template, OCR template, or XPath) | - |
number | Required | The number to be entered | - |
aoi_x | Optional | X percentage of Area of Interest top-left corner (0-100, float) | 0 |
aoi_y | Optional | Y percentage of Area of Interest top-left corner (0-100, float) | 0 |
aoi_width | Optional | Width percentage of Area of Interest (0-100, float) | 100 |
aoi_height | Optional | Height percentage of Area of Interest (0-100, float) | 100 |
event_name | Optional | A string identifier for the input event | - |
Example:
Press Keycode¶
Presses a specified keycode (useful for Android keycodes like BACK, HOME, etc.).
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
keycode | Required | The keycode to be pressed (e.g., "4" for BACK, "3" for HOME) | - |
event_name | Optional | A string identifier for the keycode event | - |
Example:
Clear Element Text¶
Clears text from a specified element.
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
element | Required | The target element (Image template, OCR template, or XPath) | - |
aoi_x | Optional | X percentage of Area of Interest top-left corner (0-100, float) | 0 |
aoi_y | Optional | Y percentage of Area of Interest top-left corner (0-100, float) | 0 |
aoi_width | Optional | Width percentage of Area of Interest (0-100, float) | 100 |
aoi_height | Optional | Height percentage of Area of Interest (0-100, float) | 100 |
event_name | Optional | A string identifier for the clear event | - |
Example:
Get Text¶
Gets the text from a specified element. Currently supports XPath and Text-based elements with Appium.
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
element | Required | The target element (Text or XPath) | - |
Example:
Note: This keyword returns text but does not store it in CSV format. Use with flow control keywords to store results.
Sleep¶
Sleeps for a specified duration.
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
duration | Required | The duration of the sleep in seconds (integer) | - |
Example:
Execute Script¶
Executes JavaScript/script in the current context. Supports both plain script strings and JSON format with arguments.
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
script_or_json | Required | The JavaScript code/script command, or a JSON string containing {"script": "...", "args": {...}} or {"script": "..."} | - |
event_name | Optional | A string identifier for the script execution event | - |
Example:
Verification Keywords¶
These keywords handle verification and validation operations.
Validate Element¶
Verifies the specified element is present on the screen.
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
element | Required | The element to be verified (Image template, OCR template, or XPath) | - |
timeout | Optional | The time to wait for verification in seconds (integer) | 10 |
rule | Optional | The rule used for verification: all or any | all |
event_name | Optional | The name of the event associated with the verification | - |
Example:
Assert Presence¶
Asserts the presence of elements. Can check multiple elements with pipe separator (|).
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
elements | Required | Comma-separated or pipe-separated string of elements to check (e.g., "button1.png|button2.png") | - |
timeout_str | Optional | The time to wait for the elements in seconds (integer) | 30 |
rule | Optional | The rule for verification: any (at least one) or all (all must be present) | any |
event_name | Optional | The name of the event associated with the assertion | - |
Example:
Validate Screen¶
Verifies the specified screen by checking element presence. Similar to Assert Presence but does not fail if elements are not found.
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
elements | Required | Comma-separated or pipe-separated string of elements to verify | - |
timeout | Optional | The time to wait for verification in seconds (integer) | 30 |
rule | Optional | The rule for verification: any or all | any |
event_name | Optional | The name of the event associated with the verification | - |
Example:
Capture Screenshot¶
Captures a screenshot of the current screen.
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
event_name | Optional | The name of the event associated with the screenshot capture | - |
Example:
Capture Page Source¶
Captures the page source of the current screen.
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
event_name | Optional | The name of the event associated with the page source capture | - |
Example:
Get Interactive Elements¶
Retrieves a list of interactive elements on the current screen.
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
filter_config | Optional | Optional list of filter types (e.g., "buttons,inputs") | - |
Example:
App Management Keywords¶
These keywords handle application lifecycle operations.
Launch App¶
Launches the specified application.
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
app_identifier | Optional | The app identifier (package name for Android, bundle ID for iOS) | - |
app_activity | Optional | The app activity (Android only) | - |
event_name | Optional | The event triggering the app launch | - |
Example:
Start Appium Session¶
Starts an Appium session. This is typically called automatically during setup.
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
event_name | Optional | The event triggering the session start | - |
Example:
Launch Other App¶
Starts another application.
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
app_name | Required | The package name or bundle ID of the application | - |
event_name | Optional | The event triggering the app start | - |
Example:
Close And Terminate App¶
Closes and terminates the current application.
Parameters:
None
Example:
Force Terminate App¶
Forcefully terminates the specified application.
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
app_name | Required | The name of the application to terminate | - |
event_name | Optional | The event triggering the forced termination | - |
Example:
Get App Version¶
Gets the version of the application.
Parameters:
None
Example:
Get Driver Session Id¶
Returns the current driver session ID, if available.
Parameters:
None
Example:
Flow Control Keywords¶
These keywords handle control flow operations like loops, conditions, and data manipulation. Module execution is performed by the runner when it runs test-case steps; the Optics API does not expose user-facing "Initialise Setup" or "Execute Module" keywords.
Run Loop¶
Runs a loop over a target module, either by count or with variables.
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
target | Required | The module name to execute in the loop | - |
args | Variable | Either a count (integer) or variable-iterable pairs: • Count: ["5"] - runs 5 times• Variables: ["${var1}", "value1\|value2\|value3", "${var2}", "a\|b\|c"] - iterates over values | - |
Example (by count):
Example (with variables):
Condition¶
Evaluates conditions and executes corresponding targets. Supports both module-based and expression-based conditions.
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
args | Variable | Condition-target pairs, optionally ending with an else target: • ["condition1", "target1", "condition2", "target2", "else_target"]• Conditions can be module names (prefixed with ! to invert) or expressions | - |
Example (module condition):
Example (expression condition):
Example (with else):
Read Data¶
Reads tabular data from a CSV file, JSON file, environment variable, or a 2D list, applies optional filtering and column selection, and stores the result in the session's elements.
For the programmatic API and full parameter details, see Flow Control in the API reference.
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
input_element | Required | The variable name where data will be stored. Prefer the form ${name} (e.g. ${data}). If another form is used, the value is still stored under that name (a warning may be logged). | - |
file_path | Required | The data source. One of: • File path: Path to a .csv or .json file (relative paths are resolved from the project path). Only these extensions are supported.• Environment variable: Use the prefix ENV: followed by the variable name. Example: ENV:APP_CONFIG reads the env var APP_CONFIG. The value is interpreted as: (1) if it looks like JSON (starts with [, {, or "), it is parsed as JSON and objects/arrays are normalized to a table; (2) otherwise it is parsed as CSV if valid; (3) otherwise the whole value is stored as a single string.• 2D list: Only when using the Python API: a list whose first row is headers and following rows are data (e.g. [["col1","col2"],["a","b"]]). Not passable as a literal in CSV test steps; see Library Usage for programmatic use. | - |
query | Optional | Semicolon-separated parts. Each part is either: • Column selection: select=col1,col2,... (comma-separated column names).• Filter: A pandas-style expression, e.g. status=='active', count>10. Multiple filter parts are combined with and.Any ${varname} in the query is replaced from session.elements before evaluation (e.g. role=='${expected_role}'). | "" |
Example (CSV file):
Example (with filter):
Example (environment variable):
Example (query with variable):
Note: Inline list data (e.g. a 2D list) is supported only when calling the Python API; see Library Usage for examples.
Evaluate¶
Evaluates an expression and stores the result in session.elements.
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
param1 | Required | The variable name where the result will be stored (e.g., ${result}) | - |
param2 | Required | The expression to evaluate (can use variables like ${var1} + ${var2}) | - |
Example:
Example (with comparison):
Date Evaluate¶
Evaluates a date expression based on an input date and stores the result in session.elements.
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
param1 | Required | The variable name where the evaluated date result will be stored (e.g., ${tomorrow}) | - |
param2 | Required | The input date string (e.g., "04/25/2025" or "2025-04-25"). Format is auto-detected | - |
param3 | Required | The date expression to evaluate, such as "+1 day", "-2 days", or "today" | - |
param4 | Optional | The output format for the evaluated date (default is "%d %B", e.g., "26 April") | %d %B |
Example:
Example (with custom format):
Add API¶
Adds or updates API definitions in the current session by loading from a file path or a dictionary. Use this when not using the runner's auto-discovery (e.g. when driving the framework programmatically). The supplied data replaces the session's API data.
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
api_data | Required | Either a path to an API YAML file, or a dictionary with the same structure (top-level api key with collections, etc.) | - |
Example (file path):
Example (programmatic): Pass a dict with an api key holding the collection/endpoint definitions. Relative paths are resolved against the project path when a string is given.
Invoke API¶
Invokes an API call based on a definition from the session's API data.
Parameters:
| Parameter | Type | Description | Default |
|---|---|---|---|
api_identifier | Required | The API identifier in format collection.api_name | - |
Example:
Data source: API definition YAML
Invoke API does not use element files. It uses API definition YAML files only. The format is different from element CSV/YAML: definitions live under a top-level api (or apis) key, with collections → each collection has base_url, global_headers, and apis → each API has endpoint, request (e.g. method, headers, body), and optionally expected_result, extract, and so on.
How API definitions reach the session:
- CLI/runner: YAML files under the project that contain a top-level
apiorapiskey are auto-discovered and loaded as API data. - Programmatic: The Add API keyword can load from a file path or a dict to set or replace session API data.