-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathElement.php
168 lines (150 loc) · 4.86 KB
/
Element.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
/**
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
class PHPUnit_Extensions_AppiumTestCase_Element
extends PHPUnit_Extensions_Selenium2TestCase_Element
{
/**
* @return \self
* @throws InvalidArgumentException
*/
public static function fromResponseValue(
array $value,
PHPUnit_Extensions_Selenium2TestCase_URL $parentFolder,
PHPUnit_Extensions_Selenium2TestCase_Driver $driver)
{
if (!isset($value['ELEMENT'])) {
throw new InvalidArgumentException('Element not found.');
}
$url = $parentFolder->descend($value['ELEMENT']);
return new self($driver, $url);
}
public function byIOSUIAutomation($value)
{
return $this->by('-ios uiautomation', $value);
}
public function byAndroidUIAutomator($value)
{
return $this->by('-android uiautomator', $value);
}
public function byAccessibilityId($value)
{
return $this->by('accessibility id', $value);
}
public function setImmediateValue($value)
{
$data = array(
'id' => $this->getId(),
'value' => $value
);
$url = $this->getSessionUrl()->descend('appium')->descend('element')->descend($this->getId())->descend('value');
$this->driver->curl('POST', $url, $data);
}
public function setText($keys)
{
$data = array(
'id' => $this->getId(),
'value' => array($keys)
);
$url = $this->getSessionUrl()->descend('appium')->descend('element')->descend($this->getId())->descend('replace_value');
$this->driver->curl('POST', $url, $data);
}
public function by($strategy, $value)
{
$el = $this->element($this->using($strategy)->value($value));
return $el;
}
// override to return Appium element
public function element(PHPUnit_Extensions_Selenium2TestCase_ElementCriteria $criteria)
{
$value = $this->postCommand('element', $criteria);
return PHPUnit_Extensions_AppiumTestCase_Element::fromResponseValue(
$value, $this->getSessionUrl()->descend('element'), $this->driver);
}
public function elements(PHPUnit_Extensions_Selenium2TestCase_ElementCriteria $criteria)
{
$values = $this->postCommand('elements', $criteria);
$elements = array();
foreach ($values as $value) {
$elements[] =
PHPUnit_Extensions_AppiumTestCase_Element::fromResponseValue(
$value, $this->getSessionUrl()->descend('element'), $this->driver);
}
return $elements;
}
/**
* @param string $value e.g. 'container'
* @return PHPUnit_Extensions_Selenium2TestCase_Element
*/
public function byClassName($value)
{
return $this->by('class name', $value);
}
/**
* @param string $value e.g. 'div.container'
* @return PHPUnit_Extensions_Selenium2TestCase_Element
*/
public function byCssSelector($value)
{
return $this->by('css selector', $value);
}
/**
* @param string $value e.g. 'uniqueId'
* @return PHPUnit_Extensions_Selenium2TestCase_Element
*/
public function byId($value)
{
return $this->by('id', $value);
}
/**
* @param string $value e.g. 'Link text'
* @return PHPUnit_Extensions_Selenium2TestCase_Element
*/
public function byLinkText($value)
{
return $this->by('link text', $value);
}
/**
* @param string $value e.g. 'Link te'
* @return PHPUnit_Extensions_Selenium2TestCase_Element
*/
public function byPartialLinkText($value)
{
return $this->by('partial link text', $value);
}
/**
* @param string $value e.g. 'email_address'
* @return PHPUnit_Extensions_Selenium2TestCase_Element
*/
public function byName($value)
{
return $this->by('name', $value);
}
/**
* @param string $value e.g. 'body'
* @return PHPUnit_Extensions_Selenium2TestCase_Element
*/
public function byTag($value)
{
return $this->by('tag name', $value);
}
/**
* @param string $value e.g. '/div[@attribute="value"]'
* @return PHPUnit_Extensions_Selenium2TestCase_Element
*/
public function byXPath($value)
{
return $this->by('xpath', $value);
}
}