From 53ec65b0e97248debc3d151faa6a7803a3626c6f Mon Sep 17 00:00:00 2001 From: James Craig Date: Mon, 6 Mar 2023 10:49:24 -0800 Subject: [PATCH] Update testdriver to support computedrole/computedlabel (#38758) Closes https://github.com/web-platform-tests/interop-2023-accessibility-testing/issues/5 Includes basic explicit and implcit role/label tests each for accname (in /accname) and aria role computation (in /aria/role) --- accname/basic.html | 22 ++++++++++++ docs/writing-tests/testdriver.md | 7 ++++ resources/testdriver.js | 34 +++++++++++++++++++ tools/webdriver/webdriver/client.py | 8 +++++ .../wptrunner/wptrunner/executors/actions.py | 30 ++++++++++++++++ .../wptrunner/executors/executorwebdriver.py | 13 +++++++ .../wptrunner/wptrunner/executors/protocol.py | 21 ++++++++++++ tools/wptrunner/wptrunner/testdriver-extra.js | 12 +++++++ wai-aria/role/basic.html | 23 +++++++++++++ 9 files changed, 170 insertions(+) create mode 100644 accname/basic.html create mode 100644 wai-aria/role/basic.html diff --git a/accname/basic.html b/accname/basic.html new file mode 100644 index 00000000000000..0df93c87996d1c --- /dev/null +++ b/accname/basic.html @@ -0,0 +1,22 @@ + + + + + + + +
+

test heading

+ diff --git a/docs/writing-tests/testdriver.md b/docs/writing-tests/testdriver.md index 11193b147f038f..24159e82cc8ec3 100644 --- a/docs/writing-tests/testdriver.md +++ b/docs/writing-tests/testdriver.md @@ -87,6 +87,13 @@ the global scope. ``` +### Accessibility ### +```eval_rst +.. js:autofunction:: test_driver.get_computed_label +.. js:autofunction:: test_driver.get_computed_role + +``` + ### Seure Payment Confirmation ### ```eval_rst .. js:autofunction:: test_driver.set_spc_transaction_mode diff --git a/resources/testdriver.js b/resources/testdriver.js index 8836d1b8aae0fd..cbb20a7d2a1740 100644 --- a/resources/testdriver.js +++ b/resources/testdriver.js @@ -220,6 +220,40 @@ return cookie; }, + /** + * Get Computed Label for an element. + * + * This matches the behaviour of the + * `Get Computed Label + * `_ + * WebDriver command. + * + * @param {Element} element + * @returns {Promise} fulfilled after the computed label is returned, or + * rejected in the cases the WebDriver command errors + */ + get_computed_label: async function(element) { + let label = await window.test_driver_internal.get_computed_label(element); + return label; + }, + + /** + * Get Computed Role for an element. + * + * This matches the behaviour of the + * `Get Computed Label + * `_ + * WebDriver command. + * + * @param {Element} element + * @returns {Promise} fulfilled after the computed role is returned, or + * rejected in the cases the WebDriver command errors + */ + get_computed_role: async function(element) { + let role = await window.test_driver_internal.get_computed_role(element); + return role; + }, + /** * Send keys to an element. * diff --git a/tools/webdriver/webdriver/client.py b/tools/webdriver/webdriver/client.py index 030e3fc56bede6..ba01e1fe8668de 100644 --- a/tools/webdriver/webdriver/client.py +++ b/tools/webdriver/webdriver/client.py @@ -893,6 +893,14 @@ def shadow_root(self): def attribute(self, name): return self.send_element_command("GET", "attribute/%s" % name) + @command + def get_computed_label(self): + return self.send_element_command("GET", "computedlabel") + + @command + def get_computed_role(self): + return self.send_element_command("GET", "computedrole") + # This MUST come last because otherwise @property decorators above # will be overridden by this. @command diff --git a/tools/wptrunner/wptrunner/executors/actions.py b/tools/wptrunner/wptrunner/executors/actions.py index a4b689ba921777..6a4a0b889e4ce0 100644 --- a/tools/wptrunner/wptrunner/executors/actions.py +++ b/tools/wptrunner/wptrunner/executors/actions.py @@ -38,6 +38,34 @@ def __call__(self, payload): return self.protocol.cookies.get_all_cookies() +class GetComputedLabelAction: + name = "get_computed_label" + + def __init__(self, logger, protocol): + self.logger = logger + self.protocol = protocol + + def __call__(self, payload): + selector = payload["selector"] + element = self.protocol.select.element_by_selector(selector) + self.logger.debug("Getting computed label for element: %s" % element) + return self.protocol.accessibility.get_computed_label(element) + + +class GetComputedRoleAction: + name = "get_computed_role" + + def __init__(self, logger, protocol): + self.logger = logger + self.protocol = protocol + + def __call__(self, payload): + selector = payload["selector"] + element = self.protocol.select.element_by_selector(selector) + self.logger.debug("Getting computed role for element: %s" % element) + return self.protocol.accessibility.get_computed_role(element) + + class GetNamedCookieAction: name = "get_named_cookie" @@ -253,6 +281,8 @@ def __call__(self, payload): DeleteAllCookiesAction, GetAllCookiesAction, GetNamedCookieAction, + GetComputedLabelAction, + GetComputedRoleAction, SendKeysAction, MinimizeWindowAction, SetWindowRectAction, diff --git a/tools/wptrunner/wptrunner/executors/executorwebdriver.py b/tools/wptrunner/wptrunner/executors/executorwebdriver.py index 54a571799995b4..829eca0deb51fd 100644 --- a/tools/wptrunner/wptrunner/executors/executorwebdriver.py +++ b/tools/wptrunner/wptrunner/executors/executorwebdriver.py @@ -20,6 +20,7 @@ TestharnessProtocolPart, Protocol, SelectorProtocolPart, + AccessibilityProtocolPart, ClickProtocolPart, CookiesProtocolPart, SendKeysProtocolPart, @@ -186,6 +187,17 @@ def elements_by_selector(self, selector): return self.webdriver.find.css(selector) +class WebDriverAccessibilityProtocolPart(AccessibilityProtocolPart): + def setup(self): + self.webdriver = self.parent.webdriver + + def get_computed_label(self, element): + return element.get_computed_label() + + def get_computed_role(self, element): + return element.get_computed_role() + + class WebDriverClickProtocolPart(ClickProtocolPart): def setup(self): self.webdriver = self.parent.webdriver @@ -342,6 +354,7 @@ class WebDriverProtocol(Protocol): implements = [WebDriverBaseProtocolPart, WebDriverTestharnessProtocolPart, WebDriverSelectorProtocolPart, + WebDriverAccessibilityProtocolPart, WebDriverClickProtocolPart, WebDriverCookiesProtocolPart, WebDriverSendKeysProtocolPart, diff --git a/tools/wptrunner/wptrunner/executors/protocol.py b/tools/wptrunner/wptrunner/executors/protocol.py index 75e113c71d3f3b..af64cc855e2126 100644 --- a/tools/wptrunner/wptrunner/executors/protocol.py +++ b/tools/wptrunner/wptrunner/executors/protocol.py @@ -299,6 +299,27 @@ def element(self, element): pass + +class AccessibilityProtocolPart(ProtocolPart): + """Protocol part for accessibility introspection""" + __metaclass__ = ABCMeta + + name = "accessibility" + + @abstractmethod + def get_computed_label(self, element): + """Return the computed accessibility label for a specific element. + + :param element: A protocol-specific handle to an element.""" + pass + + def get_computed_role(self, element): + """Return the computed accessibility role for a specific element. + + :param element: A protocol-specific handle to an element.""" + pass + + class CookiesProtocolPart(ProtocolPart): """Protocol part for managing cookies""" __metaclass__ = ABCMeta diff --git a/tools/wptrunner/wptrunner/testdriver-extra.js b/tools/wptrunner/wptrunner/testdriver-extra.js index 94a9a97125625e..716da040bbc508 100644 --- a/tools/wptrunner/wptrunner/testdriver-extra.js +++ b/tools/wptrunner/wptrunner/testdriver-extra.js @@ -180,6 +180,18 @@ return create_action("get_all_cookies", {context}); }; + window.test_driver_internal.get_computed_label = function(element) { + const selector = get_selector(element); + const context = get_context(element); + return create_action("get_computed_label", {selector, context}); + }; + + window.test_driver_internal.get_computed_role = function(element) { + const selector = get_selector(element); + const context = get_context(element); + return create_action("get_computed_role", {selector, context}); + }; + window.test_driver_internal.get_named_cookie = function(name, context=null) { return create_action("get_named_cookie", {name, context}); }; diff --git a/wai-aria/role/basic.html b/wai-aria/role/basic.html new file mode 100644 index 00000000000000..d371aa72dcba64 --- /dev/null +++ b/wai-aria/role/basic.html @@ -0,0 +1,23 @@ + + + + + + + +
+

test heading

+