Skip to content

Commit

Permalink
Merge pull request #44 from magento-firedrakes/MAGETWO-32081
Browse files Browse the repository at this point in the history
[Firedrakes] MTF Refactoring
  • Loading branch information
Michael Logvin committed Jan 20, 2015
2 parents 32e3715 + c95234e commit 4044dc2
Show file tree
Hide file tree
Showing 300 changed files with 1,149 additions and 1,085 deletions.
5 changes: 4 additions & 1 deletion dev/tests/functional/composer.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{
"require": {
"magento/mtf": "1.0.0-rc12",
"magento/mtf": "1.0.0-rc13",
"php": ">=5.4.0",
"phpunit/phpunit": "4.1.0",
"phpunit/phpunit-selenium": ">=1.2",
"netwing/selenium-server-standalone": ">=2.35"
},
"suggest": {
"facebook/webdriver": "dev-master"
},
"autoload": {
"psr-4": {
"Mtf\\": ["lib/Mtf/", "generated/Mtf/", "testsuites/Mtf/"],
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
* See COPYING.txt for license details.
*/

namespace Mtf\Client\Driver\Selenium\Element;
namespace Mtf\Client\Element;

use Mtf\Client\Driver\Selenium\Element as AbstractElement;
use Mtf\Client\Element;
use Mtf\Client\Element\Locator;
use Mtf\ObjectManager;
use Mtf\Client\Locator;
use Mtf\Client\ElementInterface;

/**
* Class ConditionsElement
Expand Down Expand Up @@ -37,7 +36,7 @@
*
* @SuppressWarnings(PHPMD.TooManyFields)
*/
class ConditionsElement extends AbstractElement
class ConditionsElement extends SimpleElement
{
/**
* Main condition
Expand Down Expand Up @@ -86,7 +85,7 @@ class ConditionsElement extends AbstractElement
*
* @var string
*/
protected $created = './/preceding-sibling::li[1]';
protected $created = './ul/li[span[contains(@class,"rule-param-new-child")]]/preceding-sibling::li[1]';

/**
* Children condition
Expand All @@ -100,7 +99,7 @@ class ConditionsElement extends AbstractElement
*
* @var string
*/
protected $param = './span[@class="rule-param"]/span/*[substring(@id,(string-length(@id)-%d+1))="%s"]/../..';
protected $param = './span[span[*[substring(@id,(string-length(@id)-%d+1))="%s"]]]';

/**
* Key of last find param
Expand Down Expand Up @@ -187,19 +186,19 @@ public function setValue($value)
* Add condition combination
*
* @param string $condition
* @param Element $context
* @return Element
* @param ElementInterface $context
* @return ElementInterface
*/
protected function addConditionsCombination($condition, Element $context)
protected function addConditionsCombination($condition, ElementInterface $context)
{
$condition = $this->parseCondition($condition);
$newCondition = $context->find($this->newCondition, Locator::SELECTOR_XPATH);
$newCondition->find($this->addNew, Locator::SELECTOR_XPATH)->click();
$typeNewCondition = $newCondition->find($this->typeNew, Locator::SELECTOR_XPATH, 'select');
$typeNewCondition->setValue($condition['type']);
$this->ruleParamWait();

$createdCondition = $newCondition->find($this->created, Locator::SELECTOR_XPATH);
$createdCondition = $context->find($this->created, Locator::SELECTOR_XPATH);
$this->waitForCondition($createdCondition);
if (!empty($condition['rules'])) {
$this->fillCondition($condition['rules'], $createdCondition);
}
Expand All @@ -210,10 +209,10 @@ protected function addConditionsCombination($condition, Element $context)
* Add conditions
*
* @param array $conditions
* @param Element $context
* @param ElementInterface $context
* @return void
*/
protected function addMultipleCondition(array $conditions, Element $context)
protected function addMultipleCondition(array $conditions, ElementInterface $context)
{
foreach ($conditions as $key => $condition) {
$elementContext = is_numeric($key) ? $context : $this->addConditionsCombination($key, $context);
Expand All @@ -229,10 +228,10 @@ protected function addMultipleCondition(array $conditions, Element $context)
* Add single Condition
*
* @param string $condition
* @param Element $context
* @param ElementInterface $context
* @return void
*/
protected function addSingleCondition($condition, Element $context)
protected function addSingleCondition($condition, ElementInterface $context)
{
$condition = $this->parseCondition($condition);

Expand All @@ -246,24 +245,24 @@ function () use ($newCondition, $typeNew) {
}
);
$newCondition->find($this->typeNew, Locator::SELECTOR_XPATH, 'select')->setValue($condition['type']);
$this->ruleParamWait();

$createdCondition = $newCondition->find($this->created, Locator::SELECTOR_XPATH);
$createdCondition = $context->find($this->created, Locator::SELECTOR_XPATH);
$this->waitForCondition($createdCondition);
$this->fillCondition($condition['rules'], $createdCondition);
}

/**
* Fill single condition
*
* @param array $rules
* @param Element $element
* @param ElementInterface $element
* @return void
* @throws \Exception
*/
protected function fillCondition(array $rules, Element $element)
protected function fillCondition(array $rules, ElementInterface $element)
{
$this->resetKeyParam();
foreach ($rules as $rule) {
/** @var ElementInterface $param */
$param = $this->findNextParam($element);
$param->find('a')->click();

Expand All @@ -287,13 +286,13 @@ function () use ($param, $input) {
return $element->isVisible() ? true : null;
}
);
$value = $param->find('select', Locator::SELECTOR_CSS, 'select');
$value = $param->find('select', Locator::SELECTOR_TAG_NAME, 'select');
if ($value->isVisible()) {
$value->setValue($rule);
$this->click();
continue;
}
$value = $param->find('input');
$value = $param->find('input', Locator::SELECTOR_TAG_NAME);
if ($value->isVisible()) {
$value->setValue($rule);

Expand Down Expand Up @@ -356,11 +355,11 @@ protected function parseCondition($condition)
/**
* Find next param of condition for fill
*
* @param Element $context
* @return Element
* @param ElementInterface $context
* @return ElementInterface
* @throws \Exception
*/
protected function findNextParam(Element $context)
protected function findNextParam(ElementInterface $context)
{
do {
if (!isset($this->mapParams[$this->findKeyParam])) {
Expand Down Expand Up @@ -389,14 +388,11 @@ protected function resetKeyParam()
*
* @return void
*/
protected function ruleParamWait()
protected function waitForCondition(ElementInterface $element)
{
$browser = $this;
$ruleParamWait = $this->ruleParamWait;
$browser->waitUntil(
function () use ($browser, $ruleParamWait) {
$element = $browser->find($ruleParamWait, Locator::SELECTOR_XPATH);
return $element->isVisible() ? null : true;
$this->waitUntil(
function () use ($element) {
return $element->getAttribute('class') == 'rule-param-wait' ? null : true;
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
* See COPYING.txt for license details.
*/

namespace Mtf\Client\Driver\Selenium\Element;
namespace Mtf\Client\Element;

use Mtf\Client\Driver\Selenium\Element;
use Mtf\Client\Element\Locator;
use Mtf\Client\Locator;

/**
* General class for datepicker elements.
*/
class DatepickerElement extends Element
class DatepickerElement extends SimpleElement
{
/**
* DatePicker button.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@
* See COPYING.txt for license details.
*/

namespace Mtf\Client\Driver\Selenium\Element;
namespace Mtf\Client\Element;

use Mtf\Client\Element\Locator;
use Mtf\Client\Driver\Selenium\Element;
use Mtf\Client\Locator;
use Mtf\Client\ElementInterface;

/**
* Typified element class for global search element.
*/
class GlobalsearchElement extends Element
class GlobalsearchElement extends SimpleElement
{
/**
* "Backspace" key code.
*/
const BACKSPACE = "\xEE\x80\x83";

/**
* Search icon selector.
*
Expand Down Expand Up @@ -49,11 +54,6 @@ class GlobalsearchElement extends Element
*/
protected $resultItem = 'li';

/**
* "Backspace" key code.
*/
const BACKSPACE = "\xEE\x80\x83";

/**
* Set value.
*
Expand All @@ -62,7 +62,7 @@ class GlobalsearchElement extends Element
*/
public function setValue($value)
{
$this->_eventManager->dispatchEvent(['set_value'], [__METHOD__, $this->getAbsoluteSelector()]);
$this->eventManager->dispatchEvent(['set_value'], [__METHOD__, $this->getAbsoluteSelector()]);

$this->waitInitElement();

Expand All @@ -71,7 +71,7 @@ public function setValue($value)
}
$this->selectWindow();
$this->clear();
$this->find($this->searchInput)->_getWrappedElement()->value($value);
$this->find($this->searchInput)->setValue($value);
$this->selectWindow();

$this->waitResult();
Expand All @@ -86,7 +86,7 @@ protected function clear()
{
$element = $this->find($this->searchInput);
while ('' != $element->getValue()) {
$element->keys([self::BACKSPACE]);
$element->setValue([self::BACKSPACE]);
}
}

Expand All @@ -97,8 +97,7 @@ protected function clear()
*/
protected function selectWindow()
{
$windowHandles = $this->_driver->windowHandles();
$this->_driver->window(end($windowHandles));
$this->driver->closeWindow();
}

/**
Expand All @@ -109,10 +108,10 @@ protected function selectWindow()
*/
protected function waitInitElement()
{
$browser = clone $this;
$selector = $this->initializedSuggest;

$browser->waitUntil(
$browser = $this->driver;
$this->driver->waitUntil(
function () use ($browser, $selector) {
return $browser->find($selector, Locator::SELECTOR_XPATH)->isVisible() ? true : null;
}
Expand All @@ -126,10 +125,10 @@ function () use ($browser, $selector) {
*/
public function waitResult()
{
$browser = clone $this;
$selector = $this->searchResult;
$browser = $this->driver;

$browser->waitUntil(
$this->driver->waitUntil(
function () use ($browser, $selector) {
if ($browser->find($selector)->isVisible()) {
return true;
Expand Down Expand Up @@ -174,12 +173,12 @@ public function isExistValueInSearchResult($value)
*/
protected function getSearchResults()
{
/** @var Element $searchResult */
/** @var ElementInterface $searchResult */
$searchResult = $this->find($this->searchResult);
$resultItems = $searchResult->find($this->resultItem)->getElements();
$resultItems = $searchResult->getElements($this->resultItem);
$resultArray = [];

/** @var Element $resultItem */
/** @var ElementInterface $resultItem */
foreach ($resultItems as $resultItem) {
$resultItemLink = $resultItem->find('a');
$resultText = $resultItemLink->isVisible()
Expand Down
Loading

0 comments on commit 4044dc2

Please sign in to comment.