diff --git a/core-aam/aamtests/support/fixtures_a11y_api.py b/core-aam/aamtests/support/fixtures_a11y_api.py index b188c97e10e85b..4cf85804e8cfcd 100644 --- a/core-aam/aamtests/support/fixtures_a11y_api.py +++ b/core-aam/aamtests/support/fixtures_a11y_api.py @@ -10,6 +10,8 @@ def pid_from(capabilities): return capabilities["moz:processID"], "firefox" if "safari:processID" in capabilities: return capabilities["safari:processID"], capabilities["browserName"] + if capabilities["browserName"] == "MicrosoftEdge": + return capabilities["goog:processID"], "edge" return 0, capabilities["browserName"] diff --git a/core-aam/aamtests/support/ia2_wrapper.py b/core-aam/aamtests/support/ia2_wrapper.py index 140786d815a9c8..5f0273ac8939b0 100644 --- a/core-aam/aamtests/support/ia2_wrapper.py +++ b/core-aam/aamtests/support/ia2_wrapper.py @@ -4,7 +4,7 @@ import ctypes from ctypes import POINTER, byref -from ctypes.wintypes import BOOL, HWND, LPARAM +from ctypes.wintypes import BOOL, DWORD, HWND, LPARAM # Type aliases for COM interface pointers. # These are dynamically generated by comtypes at runtime. @@ -48,9 +48,20 @@ def name_from_hwnd(hwnd: HWND) -> str: return buffer.value -def get_browser_hwnd(product_name: str) -> HWND: +def get_browser_hwnd(product_name: str, pid: int) -> HWND: found: List[HWND] = [] + @ctypes.WINFUNCTYPE(BOOL, HWND, LPARAM) # type: ignore[attr-defined, misc] + def check_pid(hwnd: HWND, lParam: LPARAM) -> bool: # noqa: N803 + window_pid = DWORD() + user32.GetWindowThreadProcessId(hwnd, ctypes.byref(window_pid)) + if window_pid.value != pid: + # EnumWindows should continue enumerating + return True + found.append(hwnd) + # EnumWindows should stop enumerating (since we found the right window) + return False + @ctypes.WINFUNCTYPE(BOOL, HWND, LPARAM) # type: ignore[attr-defined, misc] def check_window_name(hwnd: HWND, lParam: LPARAM) -> bool: # noqa: N803 window_name = name_from_hwnd(hwnd) @@ -61,7 +72,11 @@ def check_window_name(hwnd: HWND, lParam: LPARAM) -> bool: # noqa: N803 # EnumWindows should stop enumerating (since we found the right window) return False - user32.EnumWindows(check_window_name, LPARAM(0)) + if pid: + user32.EnumWindows(check_pid, LPARAM(0)) + else: + user32.EnumWindows(check_window_name, LPARAM(0)) + if not found: raise LookupError(f"Couldn't find {product_name} HWND") return found[0] @@ -118,7 +133,7 @@ def _find_browser(self) -> Optional[IAccessible2Ptr]: :return: IAccessible2Ptr. """ - hwnd = get_browser_hwnd(self.product_name) + hwnd = get_browser_hwnd(self.product_name, self.pid) root = accessible_object_from_window(hwnd) return to_ia2(root)