From 73dd93838e651d133aa8c77e3c4e6324e3768573 Mon Sep 17 00:00:00 2001 From: Dorin Date: Fri, 16 Sep 2016 09:20:56 +0300 Subject: [PATCH 1/2] Fixed unwanted trailing tab in chrome 53 --- src/Selenium2Driver.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Selenium2Driver.php b/src/Selenium2Driver.php index eb6a1e55..3123e570 100755 --- a/src/Selenium2Driver.php +++ b/src/Selenium2Driver.php @@ -678,10 +678,12 @@ public function setValue($xpath, $value) $existingValueLength = strlen($element->attribute('value')); // Add the TAB key to ensure we unfocus the field as browsers are triggering the change event only // after leaving the field. - $value = str_repeat(Key::BACKSPACE . Key::DELETE, $existingValueLength) . $value . Key::TAB; + $value = str_repeat(Key::BACKSPACE . Key::DELETE, $existingValueLength) . $value; } $element->postValue(array('value' => array($value))); + $script = 'Syn.trigger("change", {}, {{ELEMENT}})'; + $this->withSyn()->executeJsOnXpath($xpath, $script); } /** From f97506d3dc1fc045d6ebb24f003be826a9be2dbe Mon Sep 17 00:00:00 2001 From: Dorin Date: Fri, 16 Sep 2016 09:21:26 +0300 Subject: [PATCH 2/2] Refactored trigger methods --- src/Selenium2Driver.php | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/Selenium2Driver.php b/src/Selenium2Driver.php index 3123e570..a1a3e2d9 100755 --- a/src/Selenium2Driver.php +++ b/src/Selenium2Driver.php @@ -682,8 +682,7 @@ public function setValue($xpath, $value) } $element->postValue(array('value' => array($value))); - $script = 'Syn.trigger("change", {}, {{ELEMENT}})'; - $this->withSyn()->executeJsOnXpath($xpath, $script); + $this->trigger($xpath, 'change'); } /** @@ -821,8 +820,7 @@ public function mouseOver($xpath) */ public function focus($xpath) { - $script = 'Syn.trigger("focus", {}, {{ELEMENT}})'; - $this->withSyn()->executeJsOnXpath($xpath, $script); + $this->trigger($xpath, 'focus'); } /** @@ -830,8 +828,7 @@ public function focus($xpath) */ public function blur($xpath) { - $script = 'Syn.trigger("blur", {}, {{ELEMENT}})'; - $this->withSyn()->executeJsOnXpath($xpath, $script); + $this->trigger($xpath, 'blur'); } /** @@ -840,8 +837,7 @@ public function blur($xpath) public function keyPress($xpath, $char, $modifier = null) { $options = self::charToOptions($char, $modifier); - $script = "Syn.trigger('keypress', $options, {{ELEMENT}})"; - $this->withSyn()->executeJsOnXpath($xpath, $script); + $this->trigger($xpath, 'keypress', $options); } /** @@ -850,8 +846,7 @@ public function keyPress($xpath, $char, $modifier = null) public function keyDown($xpath, $char, $modifier = null) { $options = self::charToOptions($char, $modifier); - $script = "Syn.trigger('keydown', $options, {{ELEMENT}})"; - $this->withSyn()->executeJsOnXpath($xpath, $script); + $this->trigger($xpath, 'keydown', $options); } /** @@ -860,8 +855,7 @@ public function keyDown($xpath, $char, $modifier = null) public function keyUp($xpath, $char, $modifier = null) { $options = self::charToOptions($char, $modifier); - $script = "Syn.trigger('keyup', $options, {{ELEMENT}})"; - $this->withSyn()->executeJsOnXpath($xpath, $script); + $this->trigger($xpath, 'keyup', $options); } /** @@ -1115,4 +1109,15 @@ private function ensureInputType(Element $element, $xpath, $type, $action) throw new DriverException(sprintf($message, $action, $xpath, $type)); } } + + /** + * @param $xpath + * @param $event + * @param string $options + */ + private function trigger($xpath, $event, $options = '{}') + { + $script = 'Syn.trigger("' . $event . '", ' . $options . ', {{ELEMENT}})'; + $this->withSyn()->executeJsOnXpath($xpath, $script); + } }