From c4e03792d8157cf12d0cd00e0a7e4645d14b706d Mon Sep 17 00:00:00 2001 From: Lan Wei Date: Sat, 22 Jun 2019 01:23:59 -0400 Subject: [PATCH 01/12] create frame --- tools/wptrunner/wptrunner/executors/base.py | 6 ++-- tools/wptrunner/wptrunner/testdriver-extra.js | 30 +++++++++++++++++-- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/tools/wptrunner/wptrunner/executors/base.py b/tools/wptrunner/wptrunner/executors/base.py index d1c123a3ef39c0..54f8f9438b5da8 100644 --- a/tools/wptrunner/wptrunner/executors/base.py +++ b/tools/wptrunner/wptrunner/executors/base.py @@ -669,11 +669,11 @@ def __call__(self, payload): for action in actionSequence["actions"]: if (action["type"] == "pointerMove" and isinstance(action["origin"], dict)): - action["origin"] = self.get_element(action["origin"]["selector"]) + action["origin"] = self.get_element(action["origin"]["selector"], action["frame"]["frame"]) self.protocol.action_sequence.send_actions({"actions": actions}) - def get_element(self, selector): - element = self.protocol.select.element_by_selector(selector) + def get_element(self, element_selector, frame): + element = self.protocol.select.element_by_selector(element_selector) return element class GenerateTestReportAction(object): diff --git a/tools/wptrunner/wptrunner/testdriver-extra.js b/tools/wptrunner/wptrunner/testdriver-extra.js index 09d7c290867122..edd172ac080622 100644 --- a/tools/wptrunner/wptrunner/testdriver-extra.js +++ b/tools/wptrunner/wptrunner/testdriver-extra.js @@ -21,10 +21,26 @@ } }); + const get_frame = function(element, frame) { + let foundFrame = frame; + let frameDocument = frame == window ? window.document : frame.contentDocument; + if (!frameDocument.contains(element)) { + foundFrame = null; + let frames = document.getElementsByTagName("iframe"); + for (let i = 0; i < frames.length; i++) { + if (get_frame(element, frames[i])) { + foundFrame = frames[i]; + break; + } + } + } + return foundFrame; + }; + const get_selector = function(element) { let selector; - if (element.id && document.getElementById(element.id) === element) { + if (element.id) { const id = element.id; selector = "#"; @@ -81,8 +97,16 @@ for (let actionSequence of actions) { if (actionSequence.type == "pointer") { for (let action of actionSequence.actions) { - if (action.type == "pointerMove" && action.origin instanceof Element) { - action.origin = {selector: get_selector(action.origin)}; + // The origin of each action can only be an element or a string of a value "viewport" or "pointer". + if (action.type == "pointerMove" && typeof(action.origin) != 'string') { + let frame = get_frame(action.origin, window); + if (frame != null) { + if (frame == window) + action.frame = {frame: "window"}; + else + action.frame = {frame: frame}; + action.origin = {selector: get_selector(action.origin)}; + } } } } From ee5c88b854af399acd1fa24a5c1a9e76db8326c0 Mon Sep 17 00:00:00 2001 From: Lan Wei Date: Sun, 23 Jun 2019 01:11:46 -0400 Subject: [PATCH 02/12] create frame --- tools/wptrunner/wptrunner/executors/protocol.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/wptrunner/wptrunner/executors/protocol.py b/tools/wptrunner/wptrunner/executors/protocol.py index d08b74bfc36ae9..bf7d263ee476ab 100644 --- a/tools/wptrunner/wptrunner/executors/protocol.py +++ b/tools/wptrunner/wptrunner/executors/protocol.py @@ -235,12 +235,12 @@ class SelectorProtocolPart(ProtocolPart): name = "select" - def element_by_selector(self, selector): - elements = self.elements_by_selector(selector) + def element_by_selector(self, element_selector, frame="window"): + elements = self.elements_by_selector(element_selector) if len(elements) == 0: - raise ValueError("Selector '%s' matches no elements" % selector) + raise ValueError("Selector '%s' matches no elements" % element_selector) elif len(elements) > 1: - raise ValueError("Selector '%s' matches multiple elements" % selector) + raise ValueError("Selector '%s' matches multiple elements" % element_selector) return elements[0] @abstractmethod From 80f05c6de697e708a74a223d04fcc40789710ab0 Mon Sep 17 00:00:00 2001 From: Lan Wei Date: Sun, 23 Jun 2019 01:35:46 -0400 Subject: [PATCH 03/12] create frame --- .../wptrunner/executors/executormarionette.py | 3 +++ .../wptrunner/wptrunner/executors/executorselenium.py | 3 +++ .../wptrunner/wptrunner/executors/executorwebdriver.py | 3 +++ tools/wptrunner/wptrunner/executors/protocol.py | 10 +++++++++- 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/tools/wptrunner/wptrunner/executors/executormarionette.py b/tools/wptrunner/wptrunner/executors/executormarionette.py index 7ab701879ff1c0..c46571bd544927 100644 --- a/tools/wptrunner/wptrunner/executors/executormarionette.py +++ b/tools/wptrunner/wptrunner/executors/executormarionette.py @@ -386,6 +386,9 @@ def setup(self): def elements_by_selector(self, selector): return self.marionette.find_elements("css selector", selector) + def elements_by_selector_and_frame(self, element_selector, frame): + return self.marionette.find_elements("css selector", element_selector) + class MarionetteClickProtocolPart(ClickProtocolPart): def setup(self): diff --git a/tools/wptrunner/wptrunner/executors/executorselenium.py b/tools/wptrunner/wptrunner/executors/executorselenium.py index e7b9f45dc81d5f..9a2d223f649535 100644 --- a/tools/wptrunner/wptrunner/executors/executorselenium.py +++ b/tools/wptrunner/wptrunner/executors/executorselenium.py @@ -149,6 +149,9 @@ def setup(self): def elements_by_selector(self, selector): return self.webdriver.find_elements_by_css_selector(selector) + def elements_by_selector_and_frame(self, element_selector, frame): + return self.webdriver.find_elements_by_css_selector(element_selector) + class SeleniumClickProtocolPart(ClickProtocolPart): def setup(self): diff --git a/tools/wptrunner/wptrunner/executors/executorwebdriver.py b/tools/wptrunner/wptrunner/executors/executorwebdriver.py index 65938a7678b1ae..ce7691c4d565ac 100644 --- a/tools/wptrunner/wptrunner/executors/executorwebdriver.py +++ b/tools/wptrunner/wptrunner/executors/executorwebdriver.py @@ -142,6 +142,9 @@ def setup(self): def elements_by_selector(self, selector): return self.webdriver.find.css(selector) + def elements_by_selector_and_frame(self, element_selector, frame): + return self.webdriver.find.css(element_selector, frame) + class WebDriverClickProtocolPart(ClickProtocolPart): def setup(self): diff --git a/tools/wptrunner/wptrunner/executors/protocol.py b/tools/wptrunner/wptrunner/executors/protocol.py index bf7d263ee476ab..41e016f8837127 100644 --- a/tools/wptrunner/wptrunner/executors/protocol.py +++ b/tools/wptrunner/wptrunner/executors/protocol.py @@ -236,7 +236,7 @@ class SelectorProtocolPart(ProtocolPart): name = "select" def element_by_selector(self, element_selector, frame="window"): - elements = self.elements_by_selector(element_selector) + elements = self.elements_by_selector_and_frame(element_selector, frame) if len(elements) == 0: raise ValueError("Selector '%s' matches no elements" % element_selector) elif len(elements) > 1: @@ -251,6 +251,14 @@ def elements_by_selector(self, selector): :returns: A list of protocol-specific handles to elements""" pass + @abstractmethod + def elements_by_selector_and_frame(self, element_selector, frame): + """Select elements matching a CSS selector + + :param str selector: The CSS selector + :returns: A list of protocol-specific handles to elements""" + pass + class ClickProtocolPart(ProtocolPart): """Protocol part for performing trusted clicks""" From 1b7ec0e2a39eab67e162eed2283e5be9756651a7 Mon Sep 17 00:00:00 2001 From: Lan Wei Date: Sun, 23 Jun 2019 01:45:00 -0400 Subject: [PATCH 04/12] create frame --- tools/wptrunner/wptrunner/executors/protocol.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/wptrunner/wptrunner/executors/protocol.py b/tools/wptrunner/wptrunner/executors/protocol.py index 41e016f8837127..3aaf367dd4d946 100644 --- a/tools/wptrunner/wptrunner/executors/protocol.py +++ b/tools/wptrunner/wptrunner/executors/protocol.py @@ -251,13 +251,13 @@ def elements_by_selector(self, selector): :returns: A list of protocol-specific handles to elements""" pass - @abstractmethod + @abstractmethod def elements_by_selector_and_frame(self, element_selector, frame): """Select elements matching a CSS selector :param str selector: The CSS selector :returns: A list of protocol-specific handles to elements""" - pass + pass class ClickProtocolPart(ProtocolPart): From 48fe0cd9880ef624c92fc74b398d4969246c0354 Mon Sep 17 00:00:00 2001 From: Lan Wei Date: Mon, 24 Jun 2019 11:07:53 -0400 Subject: [PATCH 05/12] create frame --- tools/webdriver/webdriver/client.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tools/webdriver/webdriver/client.py b/tools/webdriver/webdriver/client.py index 52ebc95e84aaea..d47bcc7acb1537 100644 --- a/tools/webdriver/webdriver/client.py +++ b/tools/webdriver/webdriver/client.py @@ -218,7 +218,9 @@ def perform(self, actions=None): ``ActionSequence.dict``. """ body = {"actions": [] if actions is None else actions} - return self.session.send_session_command("POST", "actions", body) + actions = self.session.send_session_command("POST", "actions", body) + self.session.switch_frame("parent") + return actions @command def release(self): @@ -308,8 +310,11 @@ def __init__(self, session): self.session = session @command - def css(self, selector, all=True): - return self._find_element("css selector", selector, all) + def css(self, element_selector, frame, all=True): + if (frame != "window"): + self.session.switch_frame(frame) + elements = self._find_element("css selector", element_selector, all) + return elements def _find_element(self, strategy, selector, all): route = "elements" if all else "element" From 01843dede329a068aee48d9564e0ad9b9b3d539b Mon Sep 17 00:00:00 2001 From: Lan Wei Date: Mon, 24 Jun 2019 11:50:26 -0400 Subject: [PATCH 06/12] create frame --- tools/wptrunner/wptrunner/executors/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/wptrunner/wptrunner/executors/base.py b/tools/wptrunner/wptrunner/executors/base.py index 54f8f9438b5da8..588e0b2fad6afb 100644 --- a/tools/wptrunner/wptrunner/executors/base.py +++ b/tools/wptrunner/wptrunner/executors/base.py @@ -673,7 +673,7 @@ def __call__(self, payload): self.protocol.action_sequence.send_actions({"actions": actions}) def get_element(self, element_selector, frame): - element = self.protocol.select.element_by_selector(element_selector) + element = self.protocol.select.element_by_selector(element_selector, frame) return element class GenerateTestReportAction(object): From 014a14af69a3427d7c41c64e4ee57fd0ace844f0 Mon Sep 17 00:00:00 2001 From: Lan Wei Date: Thu, 27 Jun 2019 14:43:51 -0400 Subject: [PATCH 07/12] Update protocol.py --- tools/wptrunner/wptrunner/executors/protocol.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/wptrunner/wptrunner/executors/protocol.py b/tools/wptrunner/wptrunner/executors/protocol.py index 3aaf367dd4d946..afc6b7df901b39 100644 --- a/tools/wptrunner/wptrunner/executors/protocol.py +++ b/tools/wptrunner/wptrunner/executors/protocol.py @@ -237,10 +237,13 @@ class SelectorProtocolPart(ProtocolPart): def element_by_selector(self, element_selector, frame="window"): elements = self.elements_by_selector_and_frame(element_selector, frame) + frame_name = "window" + if (frame != "window"): + frame_name = frame.id if len(elements) == 0: - raise ValueError("Selector '%s' matches no elements" % element_selector) + raise ValueError("Selector '%s' in frame '%s' matches no elements" % (element_selector, frame_name)) elif len(elements) > 1: - raise ValueError("Selector '%s' matches multiple elements" % element_selector) + raise ValueError("Selector '%s' in frame '%s' matches multiple elements" % (element_selector, frame_name)) return elements[0] @abstractmethod From c34afcf795fc225c27497257ad094f0ff0a50e75 Mon Sep 17 00:00:00 2001 From: Lan Wei Date: Sat, 29 Jun 2019 01:43:29 -0400 Subject: [PATCH 08/12] Update client.py --- tools/webdriver/webdriver/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/webdriver/webdriver/client.py b/tools/webdriver/webdriver/client.py index d47bcc7acb1537..947e42d7f857a4 100644 --- a/tools/webdriver/webdriver/client.py +++ b/tools/webdriver/webdriver/client.py @@ -219,7 +219,7 @@ def perform(self, actions=None): """ body = {"actions": [] if actions is None else actions} actions = self.session.send_session_command("POST", "actions", body) - self.session.switch_frame("parent") + self.session.switch_frame(None) return actions @command From be17b5b40e84951c127f75034dbd1aa0828141c9 Mon Sep 17 00:00:00 2001 From: Lan Wei Date: Sat, 29 Jun 2019 13:52:33 -0400 Subject: [PATCH 09/12] Update client.py --- tools/webdriver/webdriver/client.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/webdriver/webdriver/client.py b/tools/webdriver/webdriver/client.py index 947e42d7f857a4..cf2747196b7756 100644 --- a/tools/webdriver/webdriver/client.py +++ b/tools/webdriver/webdriver/client.py @@ -216,6 +216,7 @@ def perform(self, actions=None): :param actions: List of input source action sequences. A single action sequence may be created with the help of ``ActionSequence.dict``. + user none """ body = {"actions": [] if actions is None else actions} actions = self.session.send_session_command("POST", "actions", body) From fde8ac4c3bdfcb86ff55fe2466ae61034d9ce8fc Mon Sep 17 00:00:00 2001 From: Lan Wei Date: Tue, 2 Jul 2019 12:52:45 -0400 Subject: [PATCH 10/12] Update client.py --- tools/webdriver/webdriver/client.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/webdriver/webdriver/client.py b/tools/webdriver/webdriver/client.py index cf2747196b7756..947e42d7f857a4 100644 --- a/tools/webdriver/webdriver/client.py +++ b/tools/webdriver/webdriver/client.py @@ -216,7 +216,6 @@ def perform(self, actions=None): :param actions: List of input source action sequences. A single action sequence may be created with the help of ``ActionSequence.dict``. - user none """ body = {"actions": [] if actions is None else actions} actions = self.session.send_session_command("POST", "actions", body) From b0862669d1594d9f10b4a3c856efbf83a042e971 Mon Sep 17 00:00:00 2001 From: Lan Wei Date: Fri, 5 Jul 2019 21:31:41 -0400 Subject: [PATCH 11/12] Update client.py --- tools/webdriver/webdriver/client.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/webdriver/webdriver/client.py b/tools/webdriver/webdriver/client.py index 947e42d7f857a4..663556467bd05b 100644 --- a/tools/webdriver/webdriver/client.py +++ b/tools/webdriver/webdriver/client.py @@ -216,6 +216,7 @@ def perform(self, actions=None): :param actions: List of input source action sequences. A single action sequence may be created with the help of ``ActionSequence.dict``. + switch_frame to None """ body = {"actions": [] if actions is None else actions} actions = self.session.send_session_command("POST", "actions", body) From 2103758fe2ceff174c8c4e70d2e1c93a61ede53b Mon Sep 17 00:00:00 2001 From: Lan Wei Date: Mon, 8 Jul 2019 12:29:36 -0400 Subject: [PATCH 12/12] Update client.py --- tools/webdriver/webdriver/client.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/webdriver/webdriver/client.py b/tools/webdriver/webdriver/client.py index 663556467bd05b..947e42d7f857a4 100644 --- a/tools/webdriver/webdriver/client.py +++ b/tools/webdriver/webdriver/client.py @@ -216,7 +216,6 @@ def perform(self, actions=None): :param actions: List of input source action sequences. A single action sequence may be created with the help of ``ActionSequence.dict``. - switch_frame to None """ body = {"actions": [] if actions is None else actions} actions = self.session.send_session_command("POST", "actions", body)