This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
forked from minkphp/Mink
-
Notifications
You must be signed in to change notification settings - Fork 10
/
NodeElement.php
255 lines (226 loc) · 6.08 KB
/
NodeElement.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<?php
namespace Behat\Mink\Element;
use Behat\Mink\Session,
Behat\Mink\Driver\DriverInterface,
Behat\Mink\Element\ElementInterface;
/*
* This file is part of the Behat\Mink.
* (c) Konstantin Kudryashov <ever.zet@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Page node element.
*
* @author Konstantin Kudryashov <ever.zet@gmail.com>
*/
class NodeElement extends Element
{
private $xpath;
/**
* Initializes node element.
*
* @param string $xpath element xpath
* @param Behat\Mink\Session $session session instance
*/
public function __construct($xpath, Session $session)
{
$this->xpath = $xpath;
parent::__construct($session);
}
/**
* @see Behat\Mink\Element\ElementInterface::getXpath()
*/
public function getXpath()
{
return $this->xpath;
}
/**
* Returns element text (inside tag).
*
* @return string|null
*/
public function getText()
{
return trim($this->getSession()->getDriver()->getText($this->getXpath()));
}
/**
* Returns element value.
*
* @return mixed
*/
public function getValue()
{
return $this->getSession()->getDriver()->getValue($this->getXpath());
}
/**
* Checks whether element has attribute with specified name.
*
* @param string $name
*/
public function hasAttribute($name)
{
return null !== $this->getSession()->getDriver()->getAttribute($this->getXpath(), $name);
}
/**
* Returns specified attribute value.
*
* @param string $name
*
* @return mixed|null
*/
public function getAttribute($name)
{
return $this->getSession()->getDriver()->getAttribute($this->getXpath(), $name);
}
/**
* Sets node value.
*
* @param string $value
*/
public function setValue($value)
{
$this->getSession()->getDriver()->setValue($this->getXpath(), $value);
}
/**
* Clicks current node.
*/
public function click()
{
$this->getSession()->getDriver()->click($this->getXpath());
}
/**
* Double-clicks current node.
*/
public function doubleClick()
{
$this->getSession()->getDriver()->doubleClick($this->getXpath());
}
/**
* Right-clicks current node.
*/
public function rightClick()
{
$this->getSession()->getDriver()->rightClick($this->getXpath());
}
/**
* Checks current node if it's a checkbox field.
*/
public function check()
{
$this->getSession()->getDriver()->check($this->getXpath());
}
/**
* Unchecks current node if it's a checkbox field.
*/
public function uncheck()
{
$this->getSession()->getDriver()->uncheck($this->getXpath());
}
/**
* Selects current node specified option if it's a select field.
*
* @param string $option
*/
public function selectOption($option)
{
$this->getSession()->getDriver()->selectOption($this->getXpath(), $option);
}
/**
* Attach file to current node if it's a file input.
*
* @param string $path path to file (local)
*/
public function attachFile($path)
{
$this->getSession()->getDriver()->attachFile($this->getXpath(), $path);
}
/**
* Returns current node tag name.
*
* @return string
*/
public function getTagName()
{
return $this->getSession()->getDriver()->getTagName($this->getXpath());
}
/**
* Checks whether current node is visible on page.
*
* @return Boolean
*/
public function isVisible()
{
return (Boolean) $this->getSession()->getDriver()->isVisible($this->getXpath());
}
/**
* Checks whether current node is checked if it's a checkbox field.
*
* @return Boolean
*/
public function isChecked()
{
return (Boolean) $this->getSession()->getDriver()->isChecked($this->getXpath());
}
/**
* Brings focus to element.
*/
public function focus()
{
$this->getSession()->getDriver()->focus($this->getXpath());
}
/**
* Removes focus from element.
*/
public function blur()
{
$this->getSession()->getDriver()->blur($this->getXpath());
}
/**
* Simulates a mouse over on the element.
*/
public function mouseOver()
{
$this->getSession()->getDriver()->mouseOver($this->getXpath());
}
/**
* Presses specific keyboard key.
*
* @param mixed $char could be either char ('b') or char-code (98)
* @param string $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta')
*/
public function keyPress($char, $modifier = null)
{
$this->getSession()->getDriver()->keyPress($this->getXpath(), $char, $modifier);
}
/**
* Pressed down specific keyboard key.
*
* @param mixed $char could be either char ('b') or char-code (98)
* @param string $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta')
*/
public function keyDown($char, $modifier = null)
{
$this->getSession()->getDriver()->keyDown($this->getXpath(), $char, $modifier);
}
/**
* Pressed up specific keyboard key.
*
* @param mixed $char could be either char ('b') or char-code (98)
* @param string $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta')
*/
public function keyUp($char, $modifier = null)
{
$this->getSession()->getDriver()->keyUp($this->getXpath(), $char, $modifier);
}
/**
* Drags current node onto other node.
*
* @param ElementInterface $destination other node
*/
public function dragTo(ElementInterface $destination)
{
$this->getSession()->getDriver()->dragTo($this->getXpath(), $destination->getXpath());
}
}