Optics Class¶
The main entry point for the Optics Framework. This class provides a unified interface for both programmatic use and Robot Framework integration.
optics_framework.optics.Optics ¶
A lightweight interface to interact with the Optics Framework. Provides direct access to app management, action, and verification keywords with a single setup method. Supports Robot Framework as a library when Robot Framework is installed.
__enter__() ¶
Support for context manager to ensure cleanup.
__exit__(exc_type, exc_value, traceback) ¶
Clean up on context exit.
__init__(config=None) ¶
Initialize the Optics instance. Call setup() to configure the driver and sources.
add_api(api_data) ¶
Add or update an API definition in the current session by fully replacing session.apis.
add_element(name, value) ¶
Add or update an element in the current session.
add_module(module_name, module_def) ¶
Add or update a module in the current session.
add_testcase(testcase) ¶
Add or update a testcase in the current session.
assert_presence(elements, timeout='60', rule='any', event_name=None) ¶
Assert the presence of elements.
capture_pagesource() ¶
Capture the page source of the current screen.
capture_screenshot() ¶
Capture a screenshot of the current screen.
clear_element_text(element, event_name=None) ¶
Clear text from an element.
close_and_terminate_app() ¶
Close and terminate an application.
condition(*args) ¶
Evaluate conditions and execute corresponding targets.
date_evaluate(param1, param2, param3, param4='%d %B') ¶
Evaluate a date expression and store the result in session elements.
detect_and_press(element, timeout='10', event_name=None) ¶
Detect and press an element.
discover_templates(project_path) ¶
Discover all image templates in the project directory.
:param project_path: The path to the project directory. :type project_path: str
:return: TemplateData containing image name to path mappings. :rtype: TemplateData
enter_number(element, number, event_name=None) ¶
Enter a number into an element.
enter_text(element, text, event_name=None) ¶
Enter text into an element. Supports element fallback for any param of the form ${...}.
enter_text_direct(text, event_name=None) ¶
Enter text using the keyboard.
enter_text_using_keyboard(text_input, event_name=None) ¶
Enter text or press a special key.
evaluate(param1, param2) ¶
Evaluate an expression and store the result in session elements.
execute_script(script_or_json, event_name=None) ¶
Execute JavaScript/script in the current context.
:param script_or_json: The JavaScript code/script command, or a JSON string containing {"script": "...", "args": {...}} or {"script": "..."}. Examples: - "mobile:pressKey" (plain script) - '{"script": "mobile:pressKey", "args": {"keycode": 3}}' (JSON with args) :param event_name: Optional event name for tracking. :return: The result of the script execution.
force_terminate_app(app_name, event_name=None) ¶
Forcefully terminate the specified application.
:param app_name: The name of the application to terminate. :param event_name: The event triggering the forced termination, if any.
get_app_version() ¶
Get the application version.
get_driver_session_id() ¶
Get the current Appium session ID for the active driver.
get_element_value(name) ¶
Get the value of an element by name from the current session.
get_interactive_elements(filter_config=None) ¶
Get interactive elements on the screen.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filter_config | Optional[List[str]] | Optional list of filter types. Valid values: - "all": Show all elements (default when None or empty) - "interactive": Only interactive elements - "buttons": Only button elements - "inputs": Only input/text field elements - "images": Only image elements - "text": Only text elements Can be combined: ["buttons", "inputs"] | None |
get_text(element) ¶
Get text from an element.
invoke_api(api) ¶
Invoke a REST API endpoint.
launch_app(app_identifier=None, app_activity=None, event_name=None) ¶
Launch the application.
launch_other_app(bundleid) ¶
Launch another application.
press_by_coordinates(coor_x, coor_y, repeat='1', event_name=None) ¶
Press at absolute coordinates.
press_by_percentage(percent_x, percent_y, repeat='1', event_name=None) ¶
Press at percentage coordinates.
press_element(element, repeat='1', offset_x='0', offset_y='0', index='0', aoi_x=None, aoi_y=None, aoi_width=None, aoi_height=None, event_name=None) ¶
Press an element with specified parameters and optional Area of Interest. Supports fallback for any param as a list or single string. All parameters: str or List[str].
press_element_with_index(element, index='0', event_name=None) ¶
Press an element at a specific index.
press_keycode(keycode, event_name=None) ¶
Press a keycode.
quit() ¶
Clean up session resources and terminate the session.
read_data(element, source, query='') ¶
Read data from a specified source.
run_loop(target, *args) ¶
Run a loop over a target module, by count or with variables.
scroll(direction='down', event_name=None) ¶
Perform a scroll gesture.
scroll_from_element(element, direction='down', scroll_length='100', event_name=None) ¶
Scroll starting from an element.
scroll_until_element_appears(element, direction='down', timeout='30', event_name=None) ¶
Scroll until an element appears.
setup(config=None, driver_sources=None, elements_sources=None, image_detection=None, text_detection=None, execution_output_path_param=None) ¶
Configure the Optics Framework with required driver and element source settings.
setup_from_file(config_file_path) ¶
Configure the Optics Framework from a JSON or YAML configuration file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_file_path | str | Path to the configuration file (JSON or YAML). | required |
Raises:
| Type | Description |
|---|---|
ValueError | If the file cannot be read or parsed. |
FileNotFoundError | If the configuration file doesn't exist. |
sleep(duration) ¶
Sleep for a specified duration.
start_appium_session(event_name=None) ¶
Start an Appium session.
swipe(coor_x, coor_y, direction='right', swipe_length='50', event_name=None) ¶
Perform a swipe gesture.
swipe_from_element(element, direction='right', swipe_length='50', event_name=None) ¶
Swipe starting from an element.
swipe_until_element_appears(element, direction='down', timeout='30', event_name=None) ¶
Swipe until an element appears.
validate_element(element, timeout='10', rule='all', event_name=None) ¶
Validate an element's presence.
validate_screen(elements, timeout='30', rule='any', event_name=None) ¶
Validate a screen by checking element presence.