Additional Actions

ScreenPy Playwright adds many additional Actions. For the base Action list, see ScreenPy’s Actions API reference.

Click

class Click(target: Target)

Click on an element!

Abilities Required:

BrowseTheWebSynchronously

Examples:

the_actor.attempts_to(Click.on_the(LOG_IN_BUTTON))
static on_the(target: Target) Click

Specify the element on which to click.

Enter

class Enter(text: str, *, mask: bool = False)

Enter text into an input field.

Abilities Required:

BrowseTheWebSynchronously

Examples:

the_actor.attempts_to(Enter("Hello!").into_the(GREETING_INPUT))

the_actor.attempts_to(Enter.the_text("eggs").into_the(GROCERY_FIELD))

the_actor.attempts_to(Enter.the_secret("12345").into_the(PASSWORD_FIELD))
static the_text(text: str) Enter

Provide the text to enter into the field.

Args:

text: the text to enter into the field.

Returns:

A new instance of Enter, with mask et to False.

static the_secret(text: str) Enter

Provide the SECRET text to enter into the field.

The text will be masked, and appear as “[CENSORED]”.

Returns:

A new instance of Enter, with mask set to True.

static the_password(text: str) Enter

Provide the SECRET text to enter into the field.

The text will be masked, and appear as “[CENSORED]”.

Returns:

A new instance of Enter, with mask set to True.

into_the(target: Target) Enter

Target the element to enter text into.

Args:

target: the Target which describes the element to enter text into.

Returns:

self

into(target: Target) Enter

Target the element to enter text into.

Args:

target: the Target which describes the element to enter text into.

Returns:

self

Open

Aliases: Visit

class Open(location: str | PageObject)

Go to a specific URL!

This Action supports using the BASE_URL environment variable to set a base URL. If you set BASE_URL, the url passed in to this Action will be appended to the end of it. For example, if you have BASE_URL=http://localhost, then Open("/home") will send your browser to “http://localhost/home”.

If you pass in an object, make sure the object has a url property that can be referenced by this Action.

Abilities Required:

BrowseTheWebSynchronously

Examples:

the_actor.attempts_to(Open("https://www.nintendo.com/"))

SaveScreenshot

class SaveScreenshot(path: str)

Save a screenshot of the Actor’s current page.

Use the and_attach_it() method to indicate that this screenshot should be attached to all reports through the Narrator’s adapters. This method also accepts any keyword arguments those adapters might require.

Abilities Required:

BrowseTheWebSynchronously

Examples:

the_actor.attempts_to(SaveScreenshot("screenshot.png"))

the_actor.attempts_to(SaveScreenshot.as_(filepath))

# attach file to the Narrator's reports (behavior depends on adapter).
the_actor.attempts_to(SaveScreenshot.as_(filepath).and_attach_it())

# using screenpy_adapter_allure plugin!
from allure_commons.types import AttachmentTypes
the_actor.attempts_to(
    SaveScreenshot.as_(filepath).and_attach_it_with(
        attachment_type=AttachmentTypes.PNG,
    ),
)
classmethod as_(path: str) Self

Supply the name and/or filepath for the screenshot.

If only a name is supplied, the screenshot will appear in the current working directory.

Args:

path: The filepath for the screenshot, including its name.

Returns:

Self

and_attach_it(**kwargs: Any) Self

Indicate the screenshot should be attached to any reports.

This method accepts any additional keywords needed by any adapters attached for Narration.

Args:

kwargs: keyword arguments for the adapters used by the narrator.

Returns:

Self

and_attach_it_with(**kwargs: Any) Self

Indicate the screenshot should be attached to any reports.

This method accepts any additional keywords needed by any adapters attached for Narration.

Args:

kwargs: keyword arguments for the adapters used by the narrator.

Returns:

Self