|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bavix\Cases; |
|
4
|
|
|
|
|
5
|
|
|
use Facebook\WebDriver\Remote\DriverCommand; |
|
6
|
|
|
use Facebook\WebDriver\WebDriverBy; |
|
7
|
|
|
|
|
8
|
|
|
class RemoteWebDriver extends \Facebook\WebDriver\Remote\RemoteWebDriver |
|
9
|
|
|
{ |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @var string |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $baseUrl; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @param string $baseUrl |
|
18
|
|
|
* @return RemoteWebDriver |
|
19
|
|
|
*/ |
|
20
|
|
|
public function setBaseUrl(string $baseUrl): self |
|
21
|
|
|
{ |
|
22
|
|
|
$this->baseUrl = $baseUrl; |
|
23
|
|
|
return $this; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @param string $url |
|
28
|
|
|
* @return self |
|
29
|
|
|
*/ |
|
30
|
|
|
public function get($url): self |
|
31
|
|
|
{ |
|
32
|
|
|
return parent::get($this->baseUrl . $url); |
|
|
|
|
|
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Return the WebDriverElement with the given id. |
|
37
|
|
|
* |
|
38
|
|
|
* @param string $id The id of the element to be created. |
|
39
|
|
|
* @return RemoteWebElement |
|
40
|
|
|
*/ |
|
41
|
|
|
protected function newElement($id) |
|
42
|
|
|
{ |
|
43
|
|
|
return new RemoteWebElement($this->getExecuteMethod(), $id); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Find the first WebDriverElement using the given mechanism. |
|
48
|
|
|
* |
|
49
|
|
|
* @param WebDriverBy $by |
|
50
|
|
|
* @return RemoteWebElement NoSuchElementException is thrown in HttpCommandExecutor if no element is found. |
|
51
|
|
|
* @see WebDriverBy |
|
52
|
|
|
*/ |
|
53
|
|
|
public function findElement(WebDriverBy $by) |
|
54
|
|
|
{ |
|
55
|
|
|
$params = ['using' => $by->getMechanism(), 'value' => $by->getValue()]; |
|
56
|
|
|
$raw_element = $this->execute( |
|
57
|
|
|
DriverCommand::FIND_ELEMENT, |
|
58
|
|
|
$params |
|
59
|
|
|
); |
|
60
|
|
|
|
|
61
|
|
|
return $this->newElement(current($raw_element)); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Find all WebDriverElements within the current page using the given mechanism. |
|
66
|
|
|
* |
|
67
|
|
|
* @param WebDriverBy $by |
|
68
|
|
|
* @return RemoteWebElement[] A list of all WebDriverElements, or an empty array if nothing matches |
|
69
|
|
|
* @see WebDriverBy |
|
70
|
|
|
*/ |
|
71
|
|
|
public function findElements(WebDriverBy $by): array |
|
72
|
|
|
{ |
|
73
|
|
|
$params = ['using' => $by->getMechanism(), 'value' => $by->getValue()]; |
|
74
|
|
|
$raw_elements = $this->execute( |
|
75
|
|
|
DriverCommand::FIND_ELEMENTS, |
|
76
|
|
|
$params |
|
77
|
|
|
); |
|
78
|
|
|
|
|
79
|
|
|
$elements = []; |
|
80
|
|
|
foreach ($raw_elements as $raw_element) { |
|
81
|
|
|
$elements[] = $this->newElement(current($raw_element)); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
return $elements; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
} |
|
88
|
|
|
|