Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 2 additions & 0 deletions core-aam/aamtests/support/fixtures_a11y_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"], "MicrosoftEdge"
return 0, capabilities["browserName"]


Expand Down
23 changes: 19 additions & 4 deletions core-aam/aamtests/support/ia2_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand All @@ -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]
Expand Down Expand Up @@ -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)

Expand Down
Loading