forked from magento/magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJquerytreeElement.php
144 lines (127 loc) · 3.22 KB
/
JquerytreeElement.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Mtf\Client\Element;
use Magento\Mtf\Client\ElementInterface;
use Magento\Mtf\Client\Locator;
/**
* Typified element class for JqueryTree elements.
*/
class JquerytreeElement extends Tree
{
/**
* Root element.
*
* @var string
*/
protected $rootElement = '//div[contains(@class, "tree x-tree jstree")]';
/**
* Pattern for level node.
*
* @var string
*/
protected $level = '/ul/li[contains(@class, "jstree")]';
/**
* Pattern for child element node.
*
* @var string
*/
protected $pattern = '/ul/li[contains(@class, "jstree") and a[text() = "%s"]]';
/**
* Pattern for child open node.
*
* @var string
*/
protected $openNode = '//li[contains(@class, "jstree-open") and a[text() = "%s"]]';
/**
* Pattern for child closed node.
*
* @var string
*/
protected $closedNode = '//li[contains(@class, "jstree-closed") and a[text() = "%s"]]';
/**
* Selector for parent element.
*
* @var string
*/
protected $parentElement = './../../../a';
/**
* Selector for input.
*
* @var string
*/
protected $input = '/a/ins[@class="jstree-checkbox"]';
/**
* Selected checkboxes.
*
* @var string
*/
protected $selectedLabels = '//li[contains(@class, "jstree-checked")]/a';
/**
* Selected checkboxes by level.
*
* @var string
*/
protected $selectedLabelsByLevel = '/ul/li[contains(@class, "jstree-checked")]/a';
/**
* Display children.
*
* @param string $element
* @return void
*/
protected function displayChildren($element)
{
$element = $this->find(sprintf($this->openNode, $element), Locator::SELECTOR_XPATH);
if ($element->isVisible()) {
return;
}
$plusButton = $this->find(sprintf($this->closedNode, $element) . $this->input, Locator::SELECTOR_XPATH);
if ($plusButton->isVisible()) {
$plusButton->click();
$this->waitLoadChildren($element);
}
}
/**
* Get element label.
*
* @param ElementInterface $element
* @return string
*/
protected function getElementLabel(ElementInterface $element)
{
return trim($element->getText());
}
/**
* Get structure.
*
* @param int|null $level
* @return array
*/
public function getStructure($level = null)
{
$nodesSelector = $this->getNodesSelector($level);
$nodes = $this->getElements($nodesSelector, Locator::SELECTOR_XPATH);
return $this->prepareValues($nodes);
}
/**
* Get nodes selector.
*
* @param int|null $level
* @return string
*/
protected function getNodesSelector($level)
{
$selector = $this->rootElement;
if ($level !== null) {
for ($i = 1; $i < $level; $i++) {
$selector .= $this->level;
}
$selector .= $this->selectedLabelsByLevel;
} else {
$selector .= $this->selectedLabels;
}
return $selector;
}
}