Execute the async action on the ChromeDriver.
(
action: Action, page: APage, browser_ctx: ABrowserContext
)
| 1388 | |
| 1389 | |
| 1390 | async def aexecute_action( |
| 1391 | action: Action, page: APage, browser_ctx: ABrowserContext |
| 1392 | ) -> APage: |
| 1393 | """Execute the async action on the ChromeDriver.""" |
| 1394 | action_type = action["action_type"] |
| 1395 | match action_type: |
| 1396 | case ActionTypes.NONE: |
| 1397 | pass |
| 1398 | case ActionTypes.SCROLL: |
| 1399 | direction = "up" if "up" in action["direction"] else "down" |
| 1400 | await aexecute_scroll(direction, page) |
| 1401 | case ActionTypes.KEY_PRESS: |
| 1402 | keys = action["key_comb"] |
| 1403 | await aexecute_key_press(keys, page) |
| 1404 | |
| 1405 | case ActionTypes.MOUSE_CLICK: |
| 1406 | await aexecute_mouse_click( |
| 1407 | action["coords"][0], action["coords"][1], page |
| 1408 | ) |
| 1409 | case ActionTypes.MOUSE_HOVER: |
| 1410 | await aexecute_mouse_hover( |
| 1411 | action["coords"][0], action["coords"][1], page |
| 1412 | ) |
| 1413 | case ActionTypes.KEYBOARD_TYPE: |
| 1414 | await aexecute_type(action["text"], page) |
| 1415 | |
| 1416 | case ActionTypes.CLICK: |
| 1417 | # check each kind of locator in order |
| 1418 | # TODO[shuyanzh]: order is temp now |
| 1419 | if action["element_id"]: |
| 1420 | raise NotImplementedError |
| 1421 | elif action["element_role"] and action["element_name"]: |
| 1422 | element_role = int(action["element_role"]) |
| 1423 | element_name = action["element_name"] |
| 1424 | nth = action["nth"] |
| 1425 | await aexecute_focus(element_role, element_name, nth, page) |
| 1426 | await aexecute_click_current(page) |
| 1427 | elif action["pw_code"]: |
| 1428 | parsed_code = parse_playwright_code(action["pw_code"]) |
| 1429 | locator_code = parsed_code[:-1] |
| 1430 | # [shuyanzh], don't support action args and kwargs now |
| 1431 | await aexecute_playwright_click( |
| 1432 | locator_code=locator_code, page=page |
| 1433 | ) |
| 1434 | else: |
| 1435 | raise ValueError("No proper locator found for click action") |
| 1436 | case ActionTypes.HOVER: |
| 1437 | if action["element_id"]: |
| 1438 | raise NotImplementedError |
| 1439 | elif action["element_role"] and action["element_name"]: |
| 1440 | element_role = int(action["element_role"]) |
| 1441 | element_name = action["element_name"] |
| 1442 | nth = action["nth"] |
| 1443 | await aexecute_focus(element_role, element_name, nth, page) |
| 1444 | elif action["pw_code"]: |
| 1445 | parsed_code = parse_playwright_code(action["pw_code"]) |
| 1446 | locator_code = parsed_code[:-1] |
| 1447 | # [shuyanzh], don't support action args and kwargs now |
no test coverage detected