Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge pull request minkphp#51 from aik099/578-relaxed-exception-match…
Browse files Browse the repository at this point in the history
…ing-in-tests

Removing wrapping of ConnectionException exception with DriverException class
  • Loading branch information
stof committed Jul 13, 2014
2 parents 50d3da0 + 55ee8fb commit 9eac7d6
Showing 1 changed file with 29 additions and 137 deletions.
166 changes: 29 additions & 137 deletions src/Behat/Mink/Driver/SahiDriver.php
Expand Up @@ -250,61 +250,41 @@ public function find($xpath)
*/
public function getTagName($xpath)
{
try {
return strtolower($this->client->findByXPath($xpath)->getName());
} catch (ConnectionException $e) {
throw new DriverException('An error happened while getting the tag name', 0, $e);
}
return strtolower($this->client->findByXPath($xpath)->getName());
}

/**
* {@inheritdoc}
*/
public function getText($xpath)
{
try {
return $this->removeSahiInjectionFromText(
$this->client->findByXPath($xpath)->getText()
);
} catch (ConnectionException $e) {
throw new DriverException('An error happened while getting the text', 0, $e);
}
return $this->removeSahiInjectionFromText(
$this->client->findByXPath($xpath)->getText()
);
}

/**
* {@inheritdoc}
*/
public function getHtml($xpath)
{
try {
return $this->client->findByXPath($xpath)->getHTML();
} catch (ConnectionException $e) {
throw new DriverException('An error happened while getting the HTML', 0, $e);
}
return $this->client->findByXPath($xpath)->getHTML();
}

/**
* {@inheritdoc}
*/
public function getOuterHtml($xpath)
{
try {
return $this->client->findByXPath($xpath)->getOuterHTML();
} catch (ConnectionException $e) {
throw new DriverException('An error happened while getting the outer HTML', 0, $e);
}
return $this->client->findByXPath($xpath)->getOuterHTML();
}

/**
* {@inheritdoc}
*/
public function getAttribute($xpath, $name)
{
try {
return $this->client->findByXPath($xpath)->getAttr($name);
} catch (ConnectionException $e) {
throw new DriverException('An error happened while getting the attribute', 0, $e);
}
return $this->client->findByXPath($xpath)->getAttr($name);
}

/**
Expand Down Expand Up @@ -372,11 +352,7 @@ public function getValue($xpath)
return explode(',', $value);
}

try {
return $this->client->findByXPath($xpath)->getValue();
} catch (ConnectionException $e) {
throw new DriverException('An error happened while getting the value', 0, $e);
}
return $this->client->findByXPath($xpath)->getValue();
}

/**
Expand All @@ -395,11 +371,7 @@ public function setValue($xpath, $value)
$this->uncheck($xpath);
}
} else {
try {
$this->client->findByXPath($xpath)->setValue($value);
} catch (ConnectionException $e) {
throw new DriverException('An error happened while setting the value', 0, $e);
}
$this->client->findByXPath($xpath)->setValue($value);
}
}

Expand All @@ -408,35 +380,23 @@ public function setValue($xpath, $value)
*/
public function check($xpath)
{
try {
$this->client->findByXPath($xpath)->check();
} catch (ConnectionException $e) {
throw new DriverException('An error happened while checking the checkbox', 0, $e);
}
$this->client->findByXPath($xpath)->check();
}

/**
* {@inheritdoc}
*/
public function uncheck($xpath)
{
try {
$this->client->findByXPath($xpath)->uncheck();
} catch (ConnectionException $e) {
throw new DriverException('An error happened while unchecking the checkbox', 0, $e);
}
$this->client->findByXPath($xpath)->uncheck();
}

/**
* {@inheritdoc}
*/
public function isChecked($xpath)
{
try {
return $this->client->findByXPath($xpath)->isChecked();
} catch (ConnectionException $e) {
throw new DriverException('An error happened while getting the state of the checkbox', 0, $e);
}
return $this->client->findByXPath($xpath)->isChecked();
}

/**
Expand All @@ -449,11 +409,7 @@ public function selectOption($xpath, $value, $multiple = false)
if ('radio' === $type) {
$this->selectRadioOption($xpath, $value);
} else {
try {
$this->client->findByXPath($xpath)->choose($value, $multiple);
} catch (ConnectionException $e) {
throw new DriverException('An error happened while choosing an option', 0, $e);
}
$this->client->findByXPath($xpath)->choose($value, $multiple);
}
}

Expand All @@ -462,143 +418,95 @@ public function selectOption($xpath, $value, $multiple = false)
*/
public function isSelected($xpath)
{
try {
return $this->client->findByXPath($xpath)->isSelected();
} catch (ConnectionException $e) {
throw new DriverException('An error happened while getting the state of an option', 0, $e);
}
return $this->client->findByXPath($xpath)->isSelected();
}

/**
* {@inheritdoc}
*/
public function click($xpath)
{
try {
$this->client->findByXPath($xpath)->click();
} catch (ConnectionException $e) {
throw new DriverException('An error happened while clicking', 0, $e);
}
$this->client->findByXPath($xpath)->click();
}

/**
* {@inheritdoc}
*/
public function doubleClick($xpath)
{
try {
$this->client->findByXPath($xpath)->doubleClick();
} catch (ConnectionException $e) {
throw new DriverException('An error happened while double clicking', 0, $e);
}
$this->client->findByXPath($xpath)->doubleClick();
}

/**
* {@inheritdoc}
*/
public function rightClick($xpath)
{
try {
$this->client->findByXPath($xpath)->rightClick();
} catch (ConnectionException $e) {
throw new DriverException('An error happened while right clicking', 0, $e);
}
$this->client->findByXPath($xpath)->rightClick();
}

/**
* {@inheritdoc}
*/
public function attachFile($xpath, $path)
{
try {
$this->client->findByXPath($xpath)->setFile($path);
} catch (ConnectionException $e) {
throw new DriverException('An error happened while setting the file', 0, $e);
}
$this->client->findByXPath($xpath)->setFile($path);
}

/**
* {@inheritdoc}
*/
public function isVisible($xpath)
{
try {
return $this->client->findByXPath($xpath)->isVisible();
} catch (ConnectionException $e) {
throw new DriverException('An error happened while getting the visibility', 0, $e);
}
return $this->client->findByXPath($xpath)->isVisible();
}

/**
* {@inheritdoc}
*/
public function mouseOver($xpath)
{
try {
$this->client->findByXPath($xpath)->mouseOver();
} catch (ConnectionException $e) {
throw new DriverException('An error happened while mouving the mouse over the element', 0, $e);
}
$this->client->findByXPath($xpath)->mouseOver();
}

/**
* {@inheritdoc}
*/
public function focus($xpath)
{
try {
$this->client->findByXPath($xpath)->focus();
} catch (ConnectionException $e) {
throw new DriverException('An error happened while focusing the element', 0, $e);
}
$this->client->findByXPath($xpath)->focus();
}

/**
* {@inheritdoc}
*/
public function blur($xpath)
{
try {
$this->client->findByXPath($xpath)->blur();
} catch (ConnectionException $e) {
throw new DriverException('An error happened while blurring the element', 0, $e);
}
$this->client->findByXPath($xpath)->blur();
}

/**
* {@inheritdoc}
*/
public function keyPress($xpath, $char, $modifier = null)
{
try {
$this->client->findByXPath($xpath)->keyPress($char, strtoupper($modifier));
} catch (ConnectionException $e) {
throw new DriverException('An error happened while pressing a key', 0, $e);
}
$this->client->findByXPath($xpath)->keyPress($char, strtoupper($modifier));
}

/**
* {@inheritdoc}
*/
public function keyDown($xpath, $char, $modifier = null)
{
try {
$this->client->findByXPath($xpath)->keyDown($char, strtoupper($modifier));
} catch (ConnectionException $e) {
throw new DriverException('An error happened while pressing a key', 0, $e);
}
$this->client->findByXPath($xpath)->keyDown($char, strtoupper($modifier));
}

/**
* {@inheritdoc}
*/
public function keyUp($xpath, $char, $modifier = null)
{
try {
$this->client->findByXPath($xpath)->keyUp($char, strtoupper($modifier));
} catch (ConnectionException $e) {
throw new DriverException('An error happened while pressing a key', 0, $e);
}
$this->client->findByXPath($xpath)->keyUp($char, strtoupper($modifier));
}

/**
Expand All @@ -609,11 +517,7 @@ public function dragTo($sourceXpath, $destinationXpath)
$from = $this->client->findByXPath($sourceXpath);
$to = $this->client->findByXPath($destinationXpath);

try {
$from->dragDrop($to);
} catch (ConnectionException $e) {
throw new DriverException('An error happened while dragging the element', 0, $e);
}
$from->dragDrop($to);
}

/**
Expand All @@ -623,11 +527,7 @@ public function executeScript($script)
{
$script = $this->prepareScript($script);

try {
$this->client->getConnection()->executeJavascript($script);
} catch (ConnectionException $e) {
throw new DriverException('An error happened while executing the script', 0, $e);
}
$this->client->getConnection()->executeJavascript($script);
}

/**
Expand All @@ -637,11 +537,7 @@ public function evaluateScript($script)
{
$script = $this->prepareScript($script);

try {
return $this->client->getConnection()->evaluateJavascript($script);
} catch (ConnectionException $e) {
throw new DriverException('An error happened while evaluating the script', 0, $e);
}
return $this->client->getConnection()->evaluateJavascript($script);
}

/**
Expand All @@ -657,11 +553,7 @@ public function wait($timeout, $condition)
*/
public function submitForm($xpath)
{
try {
$this->client->findByXPath($xpath)->submitForm();
} catch (ConnectionException $e) {
throw new DriverException('An error happened while submitting the form', 0, $e);
}
$this->client->findByXPath($xpath)->submitForm();
}

/**
Expand Down

0 comments on commit 9eac7d6

Please sign in to comment.