Skip to content

Commit

Permalink
Refactored trigger methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Dorin committed Sep 16, 2016
1 parent 73dd938 commit f97506d
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/Selenium2Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand Down Expand Up @@ -821,17 +820,15 @@ public function mouseOver($xpath)
*/
public function focus($xpath)
{
$script = 'Syn.trigger("focus", {}, {{ELEMENT}})';
$this->withSyn()->executeJsOnXpath($xpath, $script);
$this->trigger($xpath, 'focus');
}

/**
* {@inheritdoc}
*/
public function blur($xpath)
{
$script = 'Syn.trigger("blur", {}, {{ELEMENT}})';
$this->withSyn()->executeJsOnXpath($xpath, $script);
$this->trigger($xpath, 'blur');
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}
}

0 comments on commit f97506d

Please sign in to comment.