From 677efb7d6abe18fe28772bc24ee00a1959982607 Mon Sep 17 00:00:00 2001 From: Paul Meyer Date: Thu, 20 Sep 2018 16:01:03 -0400 Subject: [PATCH 1/3] Add testdriver support for generate_test_report WebDriver command. Also adds Reporting API tests which utilize this command. --- reporting/bufferSize.html | 25 +++++++++++++++ reporting/disconnect.html | 24 ++++++++++++++ reporting/generateTestReport.html | 24 ++++++++++++++ reporting/nestedReport.html | 27 ++++++++++++++++ reporting/order.html | 31 +++++++++++++++++++ resources/testdriver.js | 25 +++++++++++++++ tools/wptrunner/wptrunner/executors/base.py | 13 +++++++- .../wptrunner/executors/executorwebdriver.py | 15 +++++++-- .../wptrunner/wptrunner/executors/protocol.py | 15 +++++++++ tools/wptrunner/wptrunner/testdriver-extra.js | 9 ++++++ 10 files changed, 205 insertions(+), 3 deletions(-) create mode 100644 reporting/bufferSize.html create mode 100644 reporting/disconnect.html create mode 100644 reporting/generateTestReport.html create mode 100644 reporting/nestedReport.html create mode 100644 reporting/order.html diff --git a/reporting/bufferSize.html b/reporting/bufferSize.html new file mode 100644 index 00000000000000..a91ef6cb2162c4 --- /dev/null +++ b/reporting/bufferSize.html @@ -0,0 +1,25 @@ + + +Reporting: Buffer size + + + + + diff --git a/reporting/disconnect.html b/reporting/disconnect.html new file mode 100644 index 00000000000000..3d79d2638856f5 --- /dev/null +++ b/reporting/disconnect.html @@ -0,0 +1,24 @@ + + +Reporting: Disconnect + + + + + diff --git a/reporting/generateTestReport.html b/reporting/generateTestReport.html new file mode 100644 index 00000000000000..b5deb39922cfc1 --- /dev/null +++ b/reporting/generateTestReport.html @@ -0,0 +1,24 @@ + + +Reporting: Generate Test Report + + + + + diff --git a/reporting/nestedReport.html b/reporting/nestedReport.html new file mode 100644 index 00000000000000..584e0df0c1b807 --- /dev/null +++ b/reporting/nestedReport.html @@ -0,0 +1,27 @@ + + +Reporting: Nested report + + + + + diff --git a/reporting/order.html b/reporting/order.html new file mode 100644 index 00000000000000..e65c64451ecaf0 --- /dev/null +++ b/reporting/order.html @@ -0,0 +1,31 @@ + + +Reporting: Order + + + + +

No error

+ + + diff --git a/resources/testdriver.js b/resources/testdriver.js index e328302e4f3451..031be1b7e55016 100644 --- a/resources/testdriver.js +++ b/resources/testdriver.js @@ -194,6 +194,20 @@ */ action_sequence: function(actions) { return window.test_driver_internal.action_sequence(actions); + }, + + /** + * Generates a test report on the current page + * + * The generate_test_report function generates a report (to be observed + * by ReportingObserver) for testing purposes, as described in + * {@link https://w3c.github.io/reporting/#generate-test-report-command} + * + * @returns {Promise} fulfilled after the report is generated, or + * rejected if the report generation fails + */ + generate_test_report: function(message) { + return window.test_driver_internal.generate_test_report(message); } }; @@ -281,6 +295,17 @@ */ action_sequence: function(actions) { return Promise.reject(new Error("unimplemented")); + }, + + /** + * Generates a test report on the current page + * + * @param {String} message - the message to be contained in the report + * @returns {Promise} fulfilled after the report is generated, or + * rejected if the report generation fails + */ + generate_test_report: function(message) { + return Promise.reject(new Error("unimplemented")); } }; })(); diff --git a/tools/wptrunner/wptrunner/executors/base.py b/tools/wptrunner/wptrunner/executors/base.py index 0e54eca778b3d6..41cf2c641d291b 100644 --- a/tools/wptrunner/wptrunner/executors/base.py +++ b/tools/wptrunner/wptrunner/executors/base.py @@ -509,7 +509,8 @@ def __init__(self, logger, protocol, test_window): self.actions = { "click": ClickAction(self.logger, self.protocol), "send_keys": SendKeysAction(self.logger, self.protocol), - "action_sequence": ActionSequenceAction(self.logger, self.protocol) + "action_sequence": ActionSequenceAction(self.logger, self.protocol), + "generate_test_report": GenerateTestReportAction(self.logger, self.protocol) } def __call__(self, result): @@ -593,3 +594,13 @@ def __call__(self, payload): def get_element(self, selector): element = self.protocol.select.element_by_selector(selector) return element + +class GenerateTestReportAction(object): + def __init__(self, logger, protocol): + self.logger = logger + self.protocol = protocol + + def __call__(self, payload): + message = payload["message"] + self.logger.debug("Generating test report: %s" % message) + self.protocol.generate_test_report.generate_test_report(message) diff --git a/tools/wptrunner/wptrunner/executors/executorwebdriver.py b/tools/wptrunner/wptrunner/executors/executorwebdriver.py index 3f8c2bb5a3f94a..f18e8c86e2c157 100644 --- a/tools/wptrunner/wptrunner/executors/executorwebdriver.py +++ b/tools/wptrunner/wptrunner/executors/executorwebdriver.py @@ -20,7 +20,8 @@ ClickProtocolPart, SendKeysProtocolPart, ActionSequenceProtocolPart, - TestDriverProtocolPart) + TestDriverProtocolPart, + GenerateTestReportProtocolPart) from ..testrunner import Stop import webdriver as client @@ -188,6 +189,15 @@ def send_message(self, message_type, status, message=None): self.webdriver.execute_script("window.postMessage(%s, '*')" % json.dumps(obj)) +class WebDriverGenerateTestReportProtocolPart(GenerateTestReportProtocolPart): + def setup(self): + self.webdriver = self.parent.webdriver + + def generate_test_report(self, message): + json_message = {"message": message} + self.webdriver.send_session_command("POST", "reporting/generate_test_report", json_message) + + class WebDriverProtocol(Protocol): implements = [WebDriverBaseProtocolPart, WebDriverTestharnessProtocolPart, @@ -195,7 +205,8 @@ class WebDriverProtocol(Protocol): WebDriverClickProtocolPart, WebDriverSendKeysProtocolPart, WebDriverActionSequenceProtocolPart, - WebDriverTestDriverProtocolPart] + WebDriverTestDriverProtocolPart, + WebDriverGenerateTestReportProtocolPart] def __init__(self, executor, browser, capabilities, **kwargs): super(WebDriverProtocol, self).__init__(executor, browser) diff --git a/tools/wptrunner/wptrunner/executors/protocol.py b/tools/wptrunner/wptrunner/executors/protocol.py index aa3565e5726a06..d08b74bfc36ae9 100644 --- a/tools/wptrunner/wptrunner/executors/protocol.py +++ b/tools/wptrunner/wptrunner/executors/protocol.py @@ -265,6 +265,7 @@ def element(self, element): :param element: A protocol-specific handle to an element.""" pass + class SendKeysProtocolPart(ProtocolPart): """Protocol part for performing trusted clicks""" __metaclass__ = ABCMeta @@ -280,6 +281,20 @@ def send_keys(self, element, keys): pass +class GenerateTestReportProtocolPart(ProtocolPart): + """Protocol part for generating test reports""" + __metaclass__ = ABCMeta + + name = "generate_test_report" + + @abstractmethod + def generate_test_report(self, message): + """Generate a test report. + + :param message: The message to be contained in the report.""" + pass + + class ActionSequenceProtocolPart(ProtocolPart): """Protocol part for performing trusted clicks""" __metaclass__ = ABCMeta diff --git a/tools/wptrunner/wptrunner/testdriver-extra.js b/tools/wptrunner/wptrunner/testdriver-extra.js index 6336d227db8d7d..09d7c290867122 100644 --- a/tools/wptrunner/wptrunner/testdriver-extra.js +++ b/tools/wptrunner/wptrunner/testdriver-extra.js @@ -90,4 +90,13 @@ window.__wptrunner_message_queue.push({"type": "action", "action": "action_sequence", "actions": actions}); return pending_promise; }; + + window.test_driver_internal.generate_test_report = function(message) { + const pending_promise = new Promise(function(resolve, reject) { + pending_resolve = resolve; + pending_reject = reject; + }); + window.__wptrunner_message_queue.push({"type": "action", "action": "generate_test_report", "message": message}); + return pending_promise; + }; })(); From 7ce82f8c401c8cb8c103691561c497320b6fd909 Mon Sep 17 00:00:00 2001 From: Paul Meyer Date: Tue, 19 Feb 2019 11:16:46 -0500 Subject: [PATCH 2/3] fix lint errors --- reporting/bufferSize.html | 1 + reporting/disconnect.html | 1 + reporting/generateTestReport.html | 1 + reporting/nestedReport.html | 1 + reporting/order.html | 1 + 5 files changed, 5 insertions(+) diff --git a/reporting/bufferSize.html b/reporting/bufferSize.html index a91ef6cb2162c4..7969fb023fd4ff 100644 --- a/reporting/bufferSize.html +++ b/reporting/bufferSize.html @@ -5,6 +5,7 @@ + + + + +

No error

diff --git a/reporting/nestedReport.html b/reporting/nestedReport.html index 3af951663a915f..156338ee74653b 100644 --- a/reporting/nestedReport.html +++ b/reporting/nestedReport.html @@ -7,6 +7,8 @@