|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Webino (http://webino.sk/) |
|
4
|
|
|
* |
|
5
|
|
|
* @link https://github.com/webino/WebinoDev/ for the canonical source repository |
|
6
|
|
|
* @copyright Copyright (c) 2014-2017 Webino, s. r. o. (http://webino.sk/) |
|
7
|
|
|
* @license BSD-3-Clause |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace WebinoDev\Test\Selenium; |
|
11
|
|
|
|
|
12
|
|
|
use PHPWebDriver_WebDriverBy as By; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* WebDriver tests element helper methods trait |
|
16
|
|
|
*/ |
|
17
|
|
View Code Duplication |
trait ElementTrait |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Returns WebDriver session |
|
21
|
|
|
* |
|
22
|
|
|
* @return \PHPWebDriver_WebDriverSession |
|
23
|
|
|
*/ |
|
24
|
|
|
abstract protected function getSession(); |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Returns page element by class name |
|
28
|
|
|
* |
|
29
|
|
|
* @param string $className |
|
30
|
|
|
* @return \PHPWebDriver_WebDriverElement|WebDriver\ElementInterface |
|
31
|
|
|
*/ |
|
32
|
|
|
protected function elementByClassName($className) |
|
33
|
|
|
{ |
|
34
|
|
|
return $this->getSession()->element(By::CLASS_NAME, $className); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Returns page element by CSS selector |
|
39
|
|
|
* |
|
40
|
|
|
* @param string $selector |
|
41
|
|
|
* @return \PHPWebDriver_WebDriverElement|WebDriver\ElementInterface |
|
42
|
|
|
*/ |
|
43
|
|
|
protected function elementByCssSelector($selector) |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->getSession()->element(By::CSS_SELECTOR, $selector); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Returns page element by ID |
|
50
|
|
|
* |
|
51
|
|
|
* @param string $id |
|
52
|
|
|
* @return \PHPWebDriver_WebDriverElement|WebDriver\ElementInterface |
|
53
|
|
|
*/ |
|
54
|
|
|
protected function elementById($id) |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->getSession()->element(By::ID, $id); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Returns page element by link text |
|
61
|
|
|
* |
|
62
|
|
|
* @param string $text |
|
63
|
|
|
* @return \PHPWebDriver_WebDriverElement|WebDriver\ElementInterface |
|
64
|
|
|
*/ |
|
65
|
|
|
protected function elementByLinkText($text) |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->getSession()->element(By::LINK_TEXT, $text); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Returns page element by its name |
|
72
|
|
|
* |
|
73
|
|
|
* @param string $name |
|
74
|
|
|
* @return \PHPWebDriver_WebDriverElement|WebDriver\ElementInterface |
|
75
|
|
|
*/ |
|
76
|
|
|
protected function elementByName($name) |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->getSession()->element(By::NAME, $name); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Returns page element by partial link text |
|
83
|
|
|
* |
|
84
|
|
|
* @param string $name |
|
85
|
|
|
* @return \PHPWebDriver_WebDriverElement|WebDriver\ElementInterface |
|
86
|
|
|
*/ |
|
87
|
|
|
protected function elementByPartialLinkText($name) |
|
88
|
|
|
{ |
|
89
|
|
|
return $this->getSession()->element(By::PARTIAL_LINK_TEXT, $name); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Returns page element by its tag name |
|
94
|
|
|
* |
|
95
|
|
|
* @param string $tag |
|
96
|
|
|
* @return \PHPWebDriver_WebDriverElement|WebDriver\ElementInterface |
|
97
|
|
|
*/ |
|
98
|
|
|
protected function elementByTagName($tag) |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->getSession()->element(By::TAG_NAME, $tag); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Returns page element by XPath |
|
105
|
|
|
* |
|
106
|
|
|
* @param string $xpath |
|
107
|
|
|
* @return \PHPWebDriver_WebDriverElement|WebDriver\ElementInterface |
|
108
|
|
|
*/ |
|
109
|
|
|
protected function elementByXpath($xpath) |
|
110
|
|
|
{ |
|
111
|
|
|
return $this->getSession()->element(By::XPATH, $xpath); |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|