Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlo Tasca committed May 17, 2016
2 parents f5d8f42 + 981d0da commit 34730ea
Showing 1 changed file with 36 additions and 14 deletions.
50 changes: 36 additions & 14 deletions magefix/src/Magefix/Plugin/Spinner.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,54 +38,52 @@ public function spin($lambda, $wait = 60)
/**
* Spin until element is visible. Default timeout is 60 seconds.
*
* @param string $element
* @param string|Object $element
* @param int $wait
*/
public function spinUntilVisible($element, $wait = 60)
{
$this->spin(function($context) use ($element) {
return $context->getElement($element)->isVisible();
$this->spin(function ($context) use ($element) {
return $this->_spinnerAction($context, $element, 'isVisible', true);
}, $wait);
}

/**
* Spin until element is not visible. Default timeout is 60 seconds.
*
* @param string $element
* @param string|Object $element
* @param int $wait
*/
public function spinUntilInvisible($element, $wait = 60)
{
$this->spin(function($context) use ($element) {
return ($context->getElement($element)->isVisible() == false);
$this->spin(function ($context) use ($element) {
return $this->_spinnerAction($context, $element, 'isVisible', false);
}, $wait);
}

/**
* Spin and click element. Default timeout is 60 seconds.
*
* @param string $element
* @param string|Object $element
* @param int $wait
*/
public function spinAndClick($element, $wait = 60)
{
$this->spin(function($context) use ($element) {
$context->getElement($element)->click();
return true;
$this->spin(function ($context) use ($element) {
return $this->_spinnerAction($context, $element, 'click');
}, $wait);
}

/**
* Spin and press element. Default timeout is 60 seconds.
*
* @param string $element
* @param string|Object $element
* @param int $wait
*/
public function spinAndPress($element, $wait = 60)
{
$this->spin(function($context) use ($element) {
$context->getElement($element)->press();
return true;
$this->spin(function ($context) use ($element) {
return $this->_spinnerAction($context, $element, 'press');
}, $wait);
}

Expand All @@ -101,4 +99,28 @@ protected function _throwBacktraceException()
$backtrace[1]['file'] . ", line " . $backtrace[1]['line']
);
}

/**
* @param $context
* @param $element
* @param $action
* @param null $condition
* @return bool
*/
private function _spinnerAction($context, $element, $action, $condition = null)
{
if (is_object($element)) {
if (!is_null($condition)) {
return $element->$action() === $condition;
}
$element->$action();
} else {
if (!is_null($condition)) {
return $context->getElement($element)->$action() === $condition;
}
$context->getElement($element)->$action();
}

return true;
}
}

0 comments on commit 34730ea

Please sign in to comment.