From 0bd51c65164fdca1030680addff8b00ba23598aa Mon Sep 17 00:00:00 2001 From: Oleg Andreyev Date: Mon, 14 Jan 2019 00:08:34 +0200 Subject: [PATCH 1/5] added pressKey, deprecated keyPress/keyDown/keyUp --- src/Driver/CoreDriver.php | 8 ++++++++ src/Driver/DriverInterface.php | 18 ++++++++++++++++++ src/Element/NodeElement.php | 17 +++++++++++++++++ tests/Element/NodeElementTest.php | 12 ++++++++++++ 4 files changed, 55 insertions(+) diff --git a/src/Driver/CoreDriver.php b/src/Driver/CoreDriver.php index 9b4c04e43..a4939e62a 100644 --- a/src/Driver/CoreDriver.php +++ b/src/Driver/CoreDriver.php @@ -417,6 +417,14 @@ public function keyUp($xpath, $char, $modifier = null) throw new UnsupportedDriverActionException('Keyboard manipulations are not supported by %s', $this); } + /** + * {@inheritdoc} + */ + public function pressKey($xpath, $char, $modifier = null) + { + throw new UnsupportedDriverActionException('Keyboard manipulations are not supported by %s', $this); + } + /** * {@inheritdoc} */ diff --git a/src/Driver/DriverInterface.php b/src/Driver/DriverInterface.php index 0880960c7..4ee709eec 100644 --- a/src/Driver/DriverInterface.php +++ b/src/Driver/DriverInterface.php @@ -525,6 +525,8 @@ public function blur($xpath); * * @throws UnsupportedDriverActionException When operation not supported by the driver * @throws DriverException When the operation cannot be done + * + * @deprecated Deprecating in favor of `pressKey` which is WebDriver (W3C) compliant */ public function keyPress($xpath, $char, $modifier = null); @@ -537,6 +539,8 @@ public function keyPress($xpath, $char, $modifier = null); * * @throws UnsupportedDriverActionException When operation not supported by the driver * @throws DriverException When the operation cannot be done + * + * @deprecated Deprecating in favor of `pressKey` which is WebDriver (W3C) compliant */ public function keyDown($xpath, $char, $modifier = null); @@ -549,9 +553,23 @@ public function keyDown($xpath, $char, $modifier = null); * * @throws UnsupportedDriverActionException When operation not supported by the driver * @throws DriverException When the operation cannot be done + * + * @deprecated Deprecating in favor of `pressKey` which is WebDriver (W3C) compliant */ public function keyUp($xpath, $char, $modifier = null); + /** + * Send a sequence of key strokes to the active element + * + * @param string $xpath + * @param string|int $char could be either char ('b') or char-code (98) + * @param string $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta') + * + * @throws UnsupportedDriverActionException When operation not supported by the driver + * @throws DriverException When the operation cannot be done + */ + public function pressKey($xpath, $char, $modifier = null); + /** * Drag one element onto another. * diff --git a/src/Element/NodeElement.php b/src/Element/NodeElement.php index bbb857332..c4a7d6c40 100644 --- a/src/Element/NodeElement.php +++ b/src/Element/NodeElement.php @@ -310,6 +310,8 @@ public function blur() * * @param string|int $char could be either char ('b') or char-code (98) * @param string $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta') + * + * @deprecated Deprecating in favor of `pressKey` which is WebDriver (W3C) compliant */ public function keyPress($char, $modifier = null) { @@ -321,6 +323,8 @@ public function keyPress($char, $modifier = null) * * @param string|int $char could be either char ('b') or char-code (98) * @param string $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta') + * + * @deprecated Deprecating in favor of `pressKey` which is WebDriver (W3C) compliant */ public function keyDown($char, $modifier = null) { @@ -332,12 +336,25 @@ public function keyDown($char, $modifier = null) * * @param string|int $char could be either char ('b') or char-code (98) * @param string $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta') + * + * @deprecated Deprecating in favor of `pressKey` which is WebDriver (W3C) compliant */ public function keyUp($char, $modifier = null) { $this->getDriver()->keyUp($this->getXpath(), $char, $modifier); } + /** + * Send a sequence of key strokes to the active element + * + * @param string|int $char could be either char ('b') or char-code (98) + * @param string $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta') + */ + public function pressKey($char, $modifier = null) + { + $this->getDriver()->pressKey($this->getXpath(), $char, $modifier); + } + /** * Submits the form. * diff --git a/tests/Element/NodeElementTest.php b/tests/Element/NodeElementTest.php index 5ee860d8a..c4d29bd3a 100644 --- a/tests/Element/NodeElementTest.php +++ b/tests/Element/NodeElementTest.php @@ -538,6 +538,18 @@ public function testKeyUp() $node->keyUp('key'); } + public function testPressKey() + { + $node = new NodeElement('elem', $this->session); + + $this->driver + ->expects($this->once()) + ->method('pressKey') + ->with('elem', 'key'); + + $node->pressKey('key'); + } + public function testSubmitForm() { $node = new NodeElement('some_xpath', $this->session); From 3001c2506e843521e3d70b8a6ef07071f05766d3 Mon Sep 17 00:00:00 2001 From: Oleg Andreyev Date: Tue, 15 Jan 2019 21:34:35 +0200 Subject: [PATCH 2/5] improved deprecation comment --- src/Driver/DriverInterface.php | 6 +++--- src/Element/NodeElement.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Driver/DriverInterface.php b/src/Driver/DriverInterface.php index 4ee709eec..219e2ee0b 100644 --- a/src/Driver/DriverInterface.php +++ b/src/Driver/DriverInterface.php @@ -526,7 +526,7 @@ public function blur($xpath); * @throws UnsupportedDriverActionException When operation not supported by the driver * @throws DriverException When the operation cannot be done * - * @deprecated Deprecating in favor of `pressKey` which is WebDriver (W3C) compliant + * @deprecated since version 1.8.0. Use "pressKey" instead, which is WebDriver (W3C) compliant. */ public function keyPress($xpath, $char, $modifier = null); @@ -540,7 +540,7 @@ public function keyPress($xpath, $char, $modifier = null); * @throws UnsupportedDriverActionException When operation not supported by the driver * @throws DriverException When the operation cannot be done * - * @deprecated Deprecating in favor of `pressKey` which is WebDriver (W3C) compliant + * @deprecated since version 1.8.0. Use "pressKey" instead, which is WebDriver (W3C) compliant. */ public function keyDown($xpath, $char, $modifier = null); @@ -554,7 +554,7 @@ public function keyDown($xpath, $char, $modifier = null); * @throws UnsupportedDriverActionException When operation not supported by the driver * @throws DriverException When the operation cannot be done * - * @deprecated Deprecating in favor of `pressKey` which is WebDriver (W3C) compliant + * @deprecated since version 1.8.0. Use "pressKey" instead, which is WebDriver (W3C) compliant. */ public function keyUp($xpath, $char, $modifier = null); diff --git a/src/Element/NodeElement.php b/src/Element/NodeElement.php index c4a7d6c40..0c838e795 100644 --- a/src/Element/NodeElement.php +++ b/src/Element/NodeElement.php @@ -311,7 +311,7 @@ public function blur() * @param string|int $char could be either char ('b') or char-code (98) * @param string $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta') * - * @deprecated Deprecating in favor of `pressKey` which is WebDriver (W3C) compliant + * @deprecated since version 1.8.0. Use "pressKey" instead, which is WebDriver (W3C) compliant. */ public function keyPress($char, $modifier = null) { From 2fc4ca1ddf2f370e2fbcbe0deb29cee96895d309 Mon Sep 17 00:00:00 2001 From: Oleg Andreyev Date: Tue, 15 Jan 2019 21:35:06 +0200 Subject: [PATCH 3/5] updated branch-alias to 1.8.x-dev --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 1e4ba6031..dbac39538 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,7 @@ "extra": { "branch-alias": { - "dev-master": "1.7.x-dev" + "dev-master": "1.8.x-dev" } } } From 45d4b611dd63a05f8ee96e2df42562e955bec5b2 Mon Sep 17 00:00:00 2001 From: Oleg Andreyev Date: Tue, 15 Jan 2019 21:39:33 +0200 Subject: [PATCH 4/5] added trigger_error to deprecated methods --- src/Element/NodeElement.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Element/NodeElement.php b/src/Element/NodeElement.php index 0c838e795..41ea817c2 100644 --- a/src/Element/NodeElement.php +++ b/src/Element/NodeElement.php @@ -315,6 +315,7 @@ public function blur() */ public function keyPress($char, $modifier = null) { + @trigger_error('Method "keyPress" is deprecated since version 1.8.0. Use "pressKey" instead, which is WebDriver (W3C) compliant.', E_USER_DEPRECATED); $this->getDriver()->keyPress($this->getXpath(), $char, $modifier); } @@ -328,6 +329,7 @@ public function keyPress($char, $modifier = null) */ public function keyDown($char, $modifier = null) { + @trigger_error('Method "keyDown" is deprecated since version 1.8.0. Use "pressKey" instead, which is WebDriver (W3C) compliant.', E_USER_DEPRECATED); $this->getDriver()->keyDown($this->getXpath(), $char, $modifier); } @@ -341,6 +343,7 @@ public function keyDown($char, $modifier = null) */ public function keyUp($char, $modifier = null) { + @trigger_error('Method "keyUp" is deprecated since version 1.8.0. Use "pressKey" instead, which is WebDriver (W3C) compliant.', E_USER_DEPRECATED); $this->getDriver()->keyUp($this->getXpath(), $char, $modifier); } From abdca8bd51d29b5f1679d4e8eb49c74c816a308f Mon Sep 17 00:00:00 2001 From: Oleg Andreyev Date: Tue, 15 Jan 2019 21:39:53 +0200 Subject: [PATCH 5/5] marked deprecated method tests as legacy --- tests/Element/NodeElementTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/Element/NodeElementTest.php b/tests/Element/NodeElementTest.php index c4d29bd3a..fa92bc0b7 100644 --- a/tests/Element/NodeElementTest.php +++ b/tests/Element/NodeElementTest.php @@ -502,6 +502,9 @@ public function testDragTo() $node->dragTo($target); } + /** + * @group legacy + */ public function testKeyPress() { $node = new NodeElement('elem', $this->session); @@ -514,6 +517,9 @@ public function testKeyPress() $node->keyPress('key'); } + /** + * @group legacy + */ public function testKeyDown() { $node = new NodeElement('elem', $this->session); @@ -526,6 +532,9 @@ public function testKeyDown() $node->keyDown('key'); } + /** + * @group legacy + */ public function testKeyUp() { $node = new NodeElement('elem', $this->session);