Skip to content

Step

conatus.utils.browser.step

Step module for a page.

This module is used in conjunction with the Page module. Each time a page does some navigation, a new step is created. Think of it like visiting a new URL, or clicking a button, etc.

Step

Step(
    pw_page: Page,
    config: BrowserConfig,
    last_step_n: int = -1,
    *,
    async_init: bool = False
)

Step module for a page.

ATTRIBUTE DESCRIPTION
step_n

The step number.

TYPE: int

input_elements

Input elements in the web page.

TYPE: dict[int, DOMNode]

clickable_elements

Clickable elements in the web page.

TYPE: dict[int, DOMNode]

nodes

Nodes in the web page.

TYPE: list[DOMNode]

title

Title of the web page.

TYPE: list[DOMNode]

url

URL of the web page.

TYPE: list[DOMNode]

artifacts

Step-related artifacts.

TYPE: StepArtifacts

config

The browser configuration.

TYPE: BrowserConfig

pw_page

The Playwright page.

TYPE: Page

last_step_n

The number of the last step.

TYPE: int

input_click_nodes

Input and clickable nodes in the web page.

TYPE: dict[int, NodeInputClick]

PARAMETER DESCRIPTION
pw_page

The Playwright page.

TYPE: Page

config

The browser configuration.

TYPE: BrowserConfig

last_step_n

The number of the last step.

TYPE: int DEFAULT: -1

async_init

Whether this function is called in an async context. Users should not set this parameter. Defaults to False.

TYPE: bool DEFAULT: False

Source code in conatus/utils/browser/step.py
def __init__(
    self,
    pw_page: PWPage,
    config: BrowserConfig,
    last_step_n: int = -1,
    *,
    async_init: bool = False,
) -> None:
    """Initialize the step.

    Args:
        pw_page: The Playwright page.
        config: The browser configuration.
        last_step_n: The number of the last step.
        async_init: Whether this function is called in an async context.
            Users should not set this parameter. Defaults to False.
    """
    self.pw_page = pw_page
    self.config = config
    self.last_step_n = last_step_n
    if not async_init:
        run_async(self._finish_init(), loop=pw_page._loop)  # noqa: SLF001 # pyright: ignore[reportPrivateUsage, reportAny]

init_async async classmethod

init_async(
    pw_page: Page,
    config: BrowserConfig,
    last_step_n: int = -1,
) -> Step

Create a step in async mode.

PARAMETER DESCRIPTION
pw_page

The Playwright page.

TYPE: Page

config

The browser configuration.

TYPE: BrowserConfig

last_step_n

The number of the last step.

TYPE: int DEFAULT: -1

RETURNS DESCRIPTION
Step

The Step object.

Source code in conatus/utils/browser/step.py
@classmethod
async def init_async(
    cls,
    pw_page: PWPage,
    config: BrowserConfig,
    last_step_n: int = -1,
) -> "Step":
    """Create a step in async mode.

    Args:
        pw_page: The Playwright page.
        config: The browser configuration.
        last_step_n: The number of the last step.

    Returns:
        The `Step` object.
    """
    step = cls(pw_page, config, last_step_n, async_init=True)
    await step._finish_init()
    return step