diff --git a/browser_env/actions.py b/browser_env/actions.py index 6dbc21c..1f9db76 100644 --- a/browser_env/actions.py +++ b/browser_env/actions.py @@ -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) diff --git a/tests/test_browser_env/test_action_functionalities.py b/tests/test_browser_env/test_action_functionalities.py index 6452fa7..0bdfc0d 100644 --- a/tests/test_browser_env/test_action_functionalities.py +++ b/tests/test_browser_env/test_action_functionalities.py @@ -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() @@ -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")) @@ -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 @@ -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)