Skip to content

Commit e1e6bf9

Browse files
author
vpaladiychuk
committed
Merge remote-tracking branch 'mainline/develop' into MAGETWO-37969
2 parents c6e113a + dcda524 commit e1e6bf9

File tree

78 files changed

+1222
-979
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+1222
-979
lines changed

dev/tests/functional/lib/Magento/Mtf/Client/Element/JquerytreeElement.php

Lines changed: 76 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -7,154 +7,138 @@
77
namespace Magento\Mtf\Client\Element;
88

99
use Magento\Mtf\Client\ElementInterface;
10+
use Magento\Mtf\Client\Locator;
1011

1112
/**
12-
* Class JquerytreeElement
13-
* Typified element class for JqueryTree elements
13+
* Typified element class for JqueryTree elements.
1414
*/
1515
class JquerytreeElement extends Tree
1616
{
1717
/**
18-
* Css class for finding tree nodes.
18+
* Root element.
1919
*
2020
* @var string
2121
*/
22-
protected $nodeCssClass = ' > ul';
22+
protected $rootElement = '//div[contains(@class, "tree x-tree jstree")]';
2323

2424
/**
25-
* Css class for detecting tree nodes.
25+
* Pattern for level node.
2626
*
2727
* @var string
2828
*/
29-
protected $nodeSelector = 'li[data-id]';
29+
protected $level = '/ul/li[contains(@class, "jstree")]';
3030

3131
/**
32-
* Css class for detecting tree nodes.
32+
* Pattern for child element node.
3333
*
3434
* @var string
3535
*/
36-
protected $checkedNodeSelector = 'li.jstree-checked[data-id]';
36+
protected $pattern = '/ul/li[contains(@class, "jstree") and a[text() = "%s"]]';
3737

3838
/**
39-
* Css class for fetching node's name.
39+
* Pattern for child open node.
4040
*
4141
* @var string
4242
*/
43-
protected $nodeName = 'a';
43+
protected $openNode = '//li[contains(@class, "jstree-open") and a[text() = "%s"]]';
4444

4545
/**
46-
* Array, which holds all selected elements paths.
46+
* Pattern for child closed node.
4747
*
48-
* @var array
48+
* @var string
4949
*/
50-
protected $checkedNodesPaths = [];
50+
protected $closedNode = '//li[contains(@class, "jstree-closed") and a[text() = "%s"]]';
5151

5252
/**
53-
* Returns structure of the jquerytree element.
53+
* Selector for parent element.
5454
*
55-
* @return array
55+
* @var string
5656
*/
57-
public function getStructure()
58-
{
59-
return $this->_getNodeContent($this, 'div[class*=jstree] > ul');
60-
}
57+
protected $parentElement = './../../../a';
6158

6259
/**
63-
* Recursive walks tree
60+
* Selector for input.
6461
*
65-
* @param ElementInterface $node
66-
* @param string $parentCssClass
67-
* @return array
62+
* @var string
6863
*/
69-
protected function _getNodeContent(ElementInterface $node, $parentCssClass)
70-
{
71-
$counter = 1;
72-
$nextNodeSelector = $parentCssClass . " > " . $this->nodeSelector . ":nth-of-type($counter)";
73-
$nodeArray = [];
74-
//Get list of all children nodes to work with
75-
$newNode = $node->find($nextNodeSelector);
76-
while ($newNode->isVisible()) {
77-
$nextCheckedNodeSelector = $parentCssClass . " > " . $this->checkedNodeSelector . ":nth-of-type($counter)";
78-
$nodesNames = $newNode->find($this->nodeName);
79-
$text = ltrim($nodesNames->getText());
80-
$childNodeSelector = $nextNodeSelector . $this->nodeCssClass;
81-
$nodesContents = $newNode->find($childNodeSelector);
82-
$subNodes = null;
83-
if ($nodesContents->isVisible()) {
84-
$subNodes = $this->_getNodeContent($nodesContents, $childNodeSelector);
85-
}
86-
$nodeArray[] = [
87-
'name' => $text,
88-
'isChecked' => $node->find($nextCheckedNodeSelector)->isVisible() ? true : false,
89-
'element' => $newNode,
90-
'subnodes' => $subNodes,
91-
];
92-
++$counter;
93-
$nextNodeSelector = $parentCssClass . " > " . $this->nodeSelector . ":nth-of-type($counter)";
94-
$newNode = $node->find($nextNodeSelector);
95-
}
96-
return $nodeArray;
97-
}
64+
protected $input = '/a/ins[@class="jstree-checkbox"]';
65+
66+
/**
67+
* Selected checkboxes.
68+
*
69+
* @var string
70+
*/
71+
protected $selectedLabels = '//li[contains(@class, "jstree-checked")]/a';
72+
73+
/**
74+
* Selected checkboxes by level.
75+
*
76+
* @var string
77+
*/
78+
protected $selectedLabelsByLevel = '/ul/li[contains(@class, "jstree-checked")]/a';
9879

9980
/**
100-
* Retrieve array of checked nodes from structure array.
81+
* Display children.
10182
*
102-
* @param array $structure
103-
* @return array|null
83+
* @param string $element
84+
* @return void
10485
*/
105-
protected function getCheckedNodes($structure)
86+
protected function displayChildren($element)
10687
{
107-
$pathArray = [];
108-
if ($structure['isChecked'] == true) {
109-
array_push($pathArray, $structure['name']);
110-
if (is_array($structure['subnodes'])) {
111-
foreach ($structure['subnodes'] as $node) {
112-
array_push($pathArray, $this->getCheckedNodes($node));
113-
}
114-
}
115-
return $pathArray;
88+
$element = $this->find(sprintf($this->openNode, $element), Locator::SELECTOR_XPATH);
89+
if ($element->isVisible()) {
90+
return;
91+
}
92+
$plusButton = $this->find(sprintf($this->closedNode, $element) . $this->input, Locator::SELECTOR_XPATH);
93+
if ($plusButton->isVisible()) {
94+
$plusButton->click();
95+
$this->waitLoadChildren($element);
11696
}
117-
return null;
11897
}
11998

12099
/**
121-
* Method for recursive walk array of checked elements.
122-
* If element haven't subnodes, adds element's path to $checkedNodesPaths
100+
* Get element label.
123101
*
124-
* @param array $pathArray
125-
* @param string $rootPath
102+
* @param ElementInterface $element
126103
* @return string
127104
*/
128-
protected function getPathFromArray($pathArray, $rootPath = '')
105+
protected function getElementLabel(ElementInterface $element)
129106
{
130-
$path = '';
131-
$rootPath = $rootPath == '' ? $pathArray[0] : $rootPath . '/' . $pathArray[0];
132-
if (count($pathArray) > 1) {
133-
for ($counter = 1; $counter < count($pathArray); $counter++) {
134-
$path .= $this->getPathFromArray($pathArray[$counter], $rootPath);
135-
}
136-
} else {
137-
$path = $rootPath;
138-
$this->checkedNodesPaths[] = $path;
139-
}
140-
return $path;
107+
return trim($element->getText());
141108
}
142109

143110
/**
144-
* Returns array of paths of all selected elements.
111+
* Get structure.
145112
*
113+
* @param int|null $level
146114
* @return array
147115
*/
148-
public function getValue()
116+
public function getStructure($level = null)
149117
{
150-
$pathsArray = [];
151-
$structure = $this->getStructure();
152-
foreach ($structure as $structureChunk) {
153-
$pathsArray[] = $this->getCheckedNodes($structureChunk);
154-
}
155-
foreach ($pathsArray as $pathArray) {
156-
$this->getPathFromArray($pathArray);
118+
$nodesSelector = $this->getNodesSelector($level);
119+
$nodes = $this->getElements($nodesSelector, Locator::SELECTOR_XPATH);
120+
121+
return $this->prepareValues($nodes);
122+
}
123+
124+
/**
125+
* Get nodes selector.
126+
*
127+
* @param int|null $level
128+
* @return string
129+
*/
130+
protected function getNodesSelector($level)
131+
{
132+
$selector = $this->rootElement;
133+
if ($level !== null) {
134+
for ($i = 1; $i < $level; $i++) {
135+
$selector .= $this->level;
136+
}
137+
$selector .= $this->selectedLabelsByLevel;
138+
} else {
139+
$selector .= $this->selectedLabels;
157140
}
158-
return array_filter($this->checkedNodesPaths);
141+
142+
return $selector;
159143
}
160144
}

dev/tests/functional/lib/Magento/Mtf/Client/Element/MultiselectlistElement.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ class MultiselectlistElement extends MultiselectElement
2727
*/
2828
protected $optionCheckedElement = './/*[contains(@class, "mselect-checked")]/following-sibling::span';
2929

30+
/**
31+
* Option locator by value.
32+
*
33+
* @var string
34+
*/
35+
protected $optionByValue = './/*[contains(@class,"mselect-list-item")]/label[contains(normalize-space(.), %s)]';
36+
3037
/**
3138
* Select options by values in multiple select list
3239
*
@@ -107,4 +114,16 @@ public function getAllValues()
107114

108115
return $optionsValue;
109116
}
117+
118+
/**
119+
* Check whether value is visible in the list.
120+
*
121+
* @param string $value
122+
* @return bool
123+
*/
124+
public function isValueVisible($value)
125+
{
126+
$option = $this->find(sprintf($this->optionByValue, $this->escapeQuotes($value)), Locator::SELECTOR_XPATH);
127+
return $option->isVisible();
128+
}
110129
}

dev/tests/functional/lib/Magento/Mtf/Client/Element/SuggestElement.php

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66

77
namespace Magento\Mtf\Client\Element;
88

9-
use Magento\Framework\Webapi\Exception;
109
use Magento\Mtf\Client\Locator;
1110

1211
/**
13-
* Class SuggestElement
1412
* General class for suggest elements.
1513
*/
1614
class SuggestElement extends SimpleElement
@@ -21,35 +19,35 @@ class SuggestElement extends SimpleElement
2119
const BACKSPACE = "\xEE\x80\x83";
2220

2321
/**
24-
* Selector suggest input
22+
* Selector suggest input.
2523
*
2624
* @var string
2725
*/
2826
protected $suggest = '.mage-suggest-inner > .search';
2927

3028
/**
31-
* Selector search result
29+
* Selector search result.
3230
*
3331
* @var string
3432
*/
3533
protected $searchResult = '.mage-suggest-dropdown';
3634

3735
/**
38-
* Selector item of search result
36+
* Selector item of search result.
3937
*
4038
* @var string
4139
*/
4240
protected $resultItem = './/ul/li/a[text()="%s"]';
4341

4442
/**
45-
* Suggest state loader
43+
* Suggest state loader.
4644
*
4745
* @var string
4846
*/
4947
protected $suggestStateLoader = '.mage-suggest-state-loading';
5048

5149
/**
52-
* Set value
50+
* Set value.
5351
*
5452
* @param string $value
5553
* @return void
@@ -64,10 +62,7 @@ public function setValue($value)
6462
return;
6563
}
6664
foreach (str_split($value) as $symbol) {
67-
$input = $this->find($this->suggest);
68-
$input->click();
69-
$input->keys([$symbol]);
70-
$this->waitResult();
65+
$this->keys([$symbol]);
7166
$searchedItem = $this->find(sprintf($this->resultItem, $value), Locator::SELECTOR_XPATH);
7267
if ($searchedItem->isVisible()) {
7368
try {
@@ -81,6 +76,20 @@ public function setValue($value)
8176
}
8277
}
8378

79+
/**
80+
* Send keys.
81+
*
82+
* @param array $keys
83+
* @return void
84+
*/
85+
public function keys(array $keys)
86+
{
87+
$input = $this->find($this->suggest);
88+
$input->click();
89+
$input->keys($keys);
90+
$this->waitResult();
91+
}
92+
8493
/**
8594
* Clear value of element.
8695
*
@@ -95,7 +104,7 @@ protected function clear()
95104
}
96105

97106
/**
98-
* Wait for search result is visible
107+
* Wait for search result is visible.
99108
*
100109
* @return void
101110
*/
@@ -112,7 +121,7 @@ function () use ($browser, $selector) {
112121
}
113122

114123
/**
115-
* Get value
124+
* Get value.
116125
*
117126
* @return string
118127
*/
@@ -124,21 +133,25 @@ public function getValue()
124133
}
125134

126135
/**
127-
* Checking exist value in search result
136+
* Checking exist value in search result.
128137
*
129138
* @param string $value
130139
* @return bool
131140
*/
132141
public function isExistValueInSearchResult($value)
133142
{
134-
$searchResult = $this->find($this->searchResult);
135-
136-
$this->find($this->suggest)->setValue($value);
137-
$this->waitResult();
138-
if (!$searchResult->isVisible()) {
139-
return false;
143+
$needle = $this->find($this->searchResult)->find(sprintf($this->resultItem, $value), Locator::SELECTOR_XPATH);
144+
$keys = str_split($value);
145+
$this->keys($keys);
146+
if ($needle->isVisible()) {
147+
try {
148+
return true;
149+
} catch (\Exception $e) {
150+
// In parallel run on windows change the focus is lost on element
151+
// that causes disappearing of attribute suggest list.
152+
}
140153
}
141154

142-
return $searchResult->find(sprintf($this->resultItem, $value), Locator::SELECTOR_XPATH)->isVisible();
155+
return false;
143156
}
144157
}

0 commit comments

Comments
 (0)