1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Pagantis\SeleniumFormUtils\Step; |
4
|
|
|
|
5
|
|
|
use Facebook\WebDriver\WebDriver; |
6
|
|
|
use Facebook\WebDriver\WebDriverBy; |
7
|
|
|
use Facebook\WebDriver\WebDriverExpectedCondition; |
8
|
|
|
use Faker\Factory; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class AbstractStep |
12
|
|
|
* |
13
|
|
|
* @package Pagantis\SeleniumFormUtils\Step |
14
|
|
|
*/ |
15
|
|
|
abstract class AbstractStep implements StepInterface |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var WebDriver |
19
|
|
|
*/ |
20
|
|
|
protected $webDriver; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var Factory |
24
|
|
|
*/ |
25
|
|
|
protected $faker; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* AbstractStep constructor. |
29
|
|
|
* |
30
|
|
|
* @param WebDriver $webDriver |
31
|
|
|
*/ |
32
|
|
|
public function __construct(WebDriver $webDriver) |
33
|
|
|
{ |
34
|
|
|
$this->webDriver = $webDriver; |
35
|
|
|
$this->faker = Factory::create(); |
|
|
|
|
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param WebDriverBy $webDriverBy |
40
|
|
|
* |
41
|
|
|
* @return \Facebook\WebDriver\WebDriverElement |
42
|
|
|
* |
43
|
|
|
* @throws \Facebook\WebDriver\Exception\NoSuchElementException |
44
|
|
|
* @throws \Facebook\WebDriver\Exception\TimeOutException |
45
|
|
|
*/ |
46
|
|
|
public function waitTobeClickAble(WebDriverBy $webDriverBy) |
47
|
|
|
{ |
48
|
|
|
$condition = WebDriverExpectedCondition::elementToBeClickable($webDriverBy); |
49
|
|
|
$this->webDriver->wait(5, 200)->until($condition); |
50
|
|
|
|
51
|
|
|
return $this->webDriver->findElement($webDriverBy); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param WebDriverBy $webDriverBy |
56
|
|
|
* |
57
|
|
|
* @return \Facebook\WebDriver\WebDriverElement |
58
|
|
|
* |
59
|
|
|
* @throws \Facebook\WebDriver\Exception\NoSuchElementException |
60
|
|
|
* @throws \Facebook\WebDriver\Exception\TimeOutException |
61
|
|
|
*/ |
62
|
|
|
public function waitTobeVisible(WebDriverBy $webDriverBy) |
63
|
|
|
{ |
64
|
|
|
$condition = WebDriverExpectedCondition::visibilityOfElementLocated($webDriverBy); |
65
|
|
|
$this->webDriver->wait(5, 200)->until($condition); |
66
|
|
|
|
67
|
|
|
return $this->webDriver->findElement($webDriverBy); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param string $step |
72
|
|
|
* |
73
|
|
|
* @throws \Exception |
74
|
|
|
*/ |
75
|
|
|
public function validateStep($step) |
76
|
|
|
{ |
77
|
|
|
$element = WebDriverBy::cssSelector(".Loading .is-disabled"); |
78
|
|
|
$condition = WebDriverExpectedCondition::presenceOfElementLocated($element); |
79
|
|
|
$this->webDriver->wait(5, 200)->until($condition); |
80
|
|
|
|
81
|
|
|
$path = parse_url($this->webDriver->getCurrentURL(), PHP_URL_PATH); |
82
|
|
|
$arguments = explode(DIRECTORY_SEPARATOR, $path); |
83
|
|
|
$tempStep = ''; |
84
|
|
|
for ($i = 2; $i < count($arguments); $i++) { |
|
|
|
|
85
|
|
|
$tempStep .= DIRECTORY_SEPARATOR.$arguments[$i]; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
if ($step !== $tempStep) { |
89
|
|
|
throw new \Exception('Wrong step: ' . $tempStep); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param $iFrameLocator |
95
|
|
|
* |
96
|
|
|
* @throws \Facebook\WebDriver\Exception\NoSuchElementException |
97
|
|
|
* @throws \Facebook\WebDriver\Exception\TimeOutException |
98
|
|
|
*/ |
99
|
|
|
public function moveToIFrame($iFrameLocator) |
100
|
|
|
{ |
101
|
|
|
$condition = WebDriverExpectedCondition::frameToBeAvailableAndSwitchToIt($iFrameLocator); |
102
|
|
|
$this->webDriver->wait(5, 200)->until($condition); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Switch to parent window |
107
|
|
|
*/ |
108
|
|
|
public function moveToParent() |
109
|
|
|
{ |
110
|
|
|
$handles=$this->webDriver->getWindowHandles(); |
111
|
|
|
$parent = end($handles); |
112
|
|
|
$this->webDriver->switchTo()->window($parent); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..