webdriver.extensions.flutter_integration package

Submodules

webdriver.extensions.flutter_integration.flutter_commands module

class FlutterCommand(driver: WebDriver)

Bases: object

activate_injected_image(image_id: str) None

Activates an injected image with image ID.

Parameters:

image_id (str) – The ID of the injected image to activate.

Return type:

None

execute_flutter_command(scriptName: str, params: dict) Any

Executes a Flutter command by sending a script and parameters to the flutter integration driver.

Parameters:
  • scriptName (str) – The name of the Flutter command to execute. This will be prefixed with ‘flutter:’ when passed to the driver.

  • params (dict) – A dictionary of parameters to be passed along with the Flutter command.

Returns:

The result of the command execution. The return value depends on the specific Flutter command being executed.

Return type:

Any

get_render_tree(widget_type: str | None = None, key: str | None = None, text: str | None = None) List[Dict | None]

Returns the render tree of the root widget.

Parameters:
  • widget_type (Optional[str]) – The type of the widget to primary filter by.

  • key (Optional[str]) – The key of the widget to filter by.

  • text (Optional[str]) – The text of the widget to filter by.

Returns:

A list of dictionaries or None values representing the render tree.

The result is a nested list of dictionaries representing each widget and its properties, such as type, key, size, attribute, state, visual information, and hierarchy.

The example widget includes the following code, which is rendered as part of the widget tree:

Semantics(
    key: const Key('add_activity_semantics'),
    label: 'add_activity_button',
    button: true,
    child: FloatingActionButton.small(
        key: const Key('add_activity_button'),
        tooltip: 'add_activity_button',
        heroTag: 'add',
        backgroundColor: const Color(0xFF2E2E3A),
        onPressed: null,
        child: Icon(
        Icons.add,
        size: 16,
        color: Colors.amber.shade200.withOpacity(0.5),
        semanticLabel: 'Add icon',
        ),
    ),
)

Return type:

List[Optional[Dict]]

Example execute command:

>>> flutter_command = FlutterCommand(driver)  # noqa
>>> flutter_command.get_render_tree(widget_type='Semantics', key='add_activity_semantics')
output >> [
            {
                "type": "Semantics",
                "elementType": "SingleChildRenderObjectElement",
                "description": "Semantics-[<'add_activity_semantics'>]",
                "depth": 0,
                "key": "[<'add_activity_semantics'>]",
                "attributes": {
                    "semanticsLabel": "add_activity_button"
                },
                "visual": {},
                "state": {},
                "rect": {
                    "x": 0,
                    "y": 0,
                    "width": 48,
                    "height": 48
                },
                "children": [
                    {
                        "type": "FloatingActionButton",
                        "elementType": "StatelessElement",
                        "description": "FloatingActionButton-[<'add_activity_button'>]",
                        "depth": 1,
                        "key": "[<'add_activity_button'>]",
                        "attributes": {},
                        "visual": {},
                        "state": {},
                        "rect": {
                            "x": 0,
                            "y": 0,
                            "width": 48,
                            "height": 48
                        },
                        "children": [
                            {...},
                                "children": [...]
                            }
                        ]
                    }
                ]
            }
        ]
inject_mock_image(value: str) str

Injects a mock image to the device. The input can be a file path or a base64-encoded string.

Parameters:

value (str) – The file path of the image or a base64-encoded string.

Returns:

Image ID of the injected image.

Return type:

str

perform_double_click(element: WebElement, offset: Tuple[int, int] | None = None) None

Performs a double-click on the given element, with an optional offset.

Parameters:
  • element (WebElement) – The element to double-click on. This parameter is required.

  • offset (Optional[Tuple[int, int]]) – The x and y offsets from the element to click at. If not specified, the click is performed at the element’s center.

Return type:

None

perform_drag_and_drop(source: WebElement, target: WebElement) None

Performs a drag-and-drop operation from a source element to a target element.

Parameters:
  • source (WebElement) – The element to drag from.

  • target (WebElement) – The element to drop onto.

Return type:

None

perform_long_press(element: WebElement, offset: Tuple[int, int] | None = None) None

Performs a long press on the given element, with an optional offset.

Parameters:
  • element (WebElement) – The element to perform the long press on. This parameter is required.

  • offset (Optional[Tuple[int, int]]) – The x and y offsets from the element to perform the long press at. If not specified, the long press is performed at the element’s center.

Return type:

None

scroll_till_visible(scroll_to: FlutterFinder, scroll_direction: ScrollDirection = ScrollDirection.DOWN, **opts: Any) WebElement

Scrolls until the specified element becomes visible.

Parameters:
  • scroll_to (FlutterFinder) – The Flutter element to scroll to.

  • scroll_direction (ScrollDirection) – The direction to scroll up or down. Defaults to ScrollDirection.DOWN.

KeywordArgs:

scrollView (str): The view of the scroll. Default value is ‘Scrollable’ delta (int): delta for the scroll. Default value is 64 maxScrolls (int): Max times to scroll. Default value is 15 settleBetweenScrollsTimeout (float): settle timeout in milliseconds. Default value is 5000 dragDuration (float): time gap between each scroll in milliseconds. Default value is 100

Returns:

scrolled element

Return type:

Webelement

wait_for_invisible(locator: WebElement | FlutterFinder, timeout: float | None = None) None

Waits for a element to become invisible.

Parameters:
  • locator (Union[WebElement, FlutterFinder]) – The element to wait for; can be a WebElement or a FlutterFinder.

  • timeout (Optional[float]) – Maximum wait time in seconds. Defaults to a predefined timeout if not specified.

Return type:

None

wait_for_visible(locator: WebElement | FlutterFinder, timeout: float | None = None) None

Waits for a element to become visible.

Parameters:
  • locator (Union[WebElement, FlutterFinder]) – The element to wait for; can be a WebElement or a FlutterFinder.

  • timeout (Optional[float]) – Maximum wait time in seconds. Defaults to a predefined timeout if not specified.

Returns:

None

webdriver.extensions.flutter_integration.flutter_finder module

class FlutterFinder(using: Literal['id', 'xpath', 'link text', 'partial link text', 'name', 'tag name', 'class name', 'css selector', '-ios predicate string', '-ios class chain', '-android uiautomator', '-android viewtag', '-android datamatcher', '-android viewmatcher', 'accessibility id', '-image', '-custom', '-flutter semantics label', '-flutter type', '-flutter key', '-flutter text containing'], value: str)

Bases: object

as_args() Tuple[str, str]
static by_key(value: str) FlutterFinder
static by_semantics_label(value: str) FlutterFinder
static by_text(value: str) FlutterFinder
static by_text_containing(value: str) FlutterFinder
static by_type(value: str) FlutterFinder
to_dict() dict

webdriver.extensions.flutter_integration.scroll_directions module

class ScrollDirection(*values)

Bases: Enum

DOWN = 'down'
UP = 'up'

Module contents