Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

34 os agnostic select all #43

Merged
merged 8 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions browser_env/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -802,12 +802,18 @@ async def aexecute_scroll(direction: str, page: APage) -> None:
@beartype
def execute_key_press(key: str, page: Page) -> None:
"""Press a key."""
if "Meta" in key and "Mac" not in page.evaluate("navigator.platform"):
key = key.replace("Meta", "Control")
page.keyboard.press(key)


@beartype
async def aexecute_key_press(key: str, page: APage) -> None:
"""Press a key."""
if "Meta" in key and "Mac" not in await page.evaluate(
"navigator.platform"
):
key = key.replace("Meta", "Control")
await page.keyboard.press(key)


Expand Down
62 changes: 60 additions & 2 deletions tests/test_browser_env/test_action_functionalities.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ def test_xpath(script_browser_env: ScriptBrowserEnv) -> None:
assert success


def test_inter_page_actions(script_browser_env: ScriptBrowserEnv) -> None:
def test_inter_page_actions(
script_browser_env: ScriptBrowserEnv,
) -> None:
env = script_browser_env
seq = """page.goto("https://demo.playwright.dev/todomvc/")
browser.new_tab()
Expand All @@ -113,7 +115,9 @@ def test_inter_page_actions(script_browser_env: ScriptBrowserEnv) -> None:
assert "https://demo.playwright.dev/todomvc" in info["page"].url


def test_scroll(current_viewport_script_browser_env: ScriptBrowserEnv) -> None:
def test_scroll(
current_viewport_script_browser_env: ScriptBrowserEnv,
) -> None:
env = current_viewport_script_browser_env
env.reset()
_, success, _, _, _ = env.step(create_scroll_action("down"))
Expand Down Expand Up @@ -212,6 +216,15 @@ def test_key_press(

assert success
expect(env.page.get_by_label("Full name")).to_be_focused()
expect(env.page.get_by_label("Full name")).to_have_value(s)

obs, success, _, _, info = env.step(
create_id_based_action("press [meta+a]")
)
assert success

env.page.get_by_label("Full name").type(s)
expect(env.page.get_by_label("Full name")).to_have_value(s)

obs, success, _, _, info = env.step(create_key_press_action("Enter"))
assert success
Expand Down Expand Up @@ -271,3 +284,48 @@ def test_e2e_id_based_actions(
x[-1]["page"].url
== "https://russmaxdesign.github.io/exercise/#link-one"
)


def test_id_delete_input(
accessibility_tree_current_viewport_script_browser_env: ScriptBrowserEnv,
) -> None:
env = accessibility_tree_current_viewport_script_browser_env
env.reset()
obs, success, _, _, info = env.step(
create_playwright_action(
'page.goto("https://russmaxdesign.github.io/exercise/")'
)
)
assert success
assert "textbox 'Full name'" in obs["text"]
s = "My Name IS XYZ"
element_id = re.search(r"\[(\d+)\] textbox 'Full name'", obs["text"]).group(1) # type: ignore

obs, success, _, _, info = env.step(
create_id_based_action(f"type [{element_id}] [{s}]")
)
assert success
locator = env.page.get_by_label("Full name")
expect(locator).to_have_value(s)

obs, success, _, _, info = env.step(
create_id_based_action(f"click [{element_id}]")
)
assert success

obs, success, _, _, info = env.step(
create_id_based_action(f"press [Meta+a]")
)
assert success

obs, success, _, _, info = env.step(
create_id_based_action("press [backspace]")
)
assert success

new_s = "NEW"
obs, success, _, _, info = env.step(
create_id_based_action(f"type [{element_id}] [{new_s}]")
)
locator = env.page.get_by_label("Full name")
expect(locator).to_have_value(new_s)