Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -8,6 +8,8 @@ def pid_from(capabilities):
return capabilities["goog:processID"], "chrome"
if capabilities["browserName"] == "firefox":
return capabilities["moz:processID"], "firefox"
if capabilities["browserName"] == "MicrosoftEdge":
return capabilities["goog:processID"], "MicrosoftEdge"
return 0, capabilities["browserName"]


Expand Down
13 changes: 7 additions & 6 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 @@ -46,20 +46,21 @@ 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_window_name(hwnd: HWND, lParam: LPARAM) -> bool: # noqa: N803
window_name = name_from_hwnd(hwnd)
if product_name not in window_name.lower():
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

user32.EnumWindows(check_window_name, LPARAM(0))
user32.EnumWindows(check_pid, LPARAM(0))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of deleting/replacing check_window_name, can we instead:

Suggested change
user32.EnumWindows(check_pid, LPARAM(0))
if pid:
user32.EnumWindows(check_pid, LPARAM(0))
else:
user32.EnumWindows(check_window_name, LPARAM(0))

If someone wants to test a different browser on windows (see all the browsers that WPT supports: https://github.com/web-platform-tests/wpt/tree/master/tools/wptrunner/wptrunner/browsers) -- they might need to find the browser by name, if their webdriver implementation does not return PID. So it would be nice to leave this fall back :)

@yezhizhen yezhizhen Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense! Done in 22c48f0

if not found:
raise LookupError(f"Couldn't find {product_name} HWND")
return found[0]
Expand Down
Loading