Completed
Push — master ( 4e6ecf...24a4d5 )
by Cesar
12s
created

AbstractStep   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 92
rs 10
c 0
b 0
f 0
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A waitTobeVisible() 0 6 1
A moveToIFrame() 0 4 1
A validateStep() 0 15 3
A __construct() 0 4 1
A waitTobeClickAble() 0 6 1
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();
0 ignored issues
show
Documentation Bug introduced by
It seems like Faker\Factory::create() of type Faker\Generator is incompatible with the declared type Faker\Factory of property $faker.

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..

Loading history...
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++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
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