Issues (11)

src/Step/Missing.php (6 issues)

1
<?php
2
3
namespace Pagantis\SeleniumFormUtils\Step;
4
5
use Facebook\WebDriver\WebDriverBy;
6
use Facebook\WebDriver\WebDriverExpectedCondition;
7
use Faker\Factory;
8
use Pagantis\SeleniumFormUtils\SeleniumHelper;
9
use Pagantis\SeleniumFormUtils\Step\AbstractStep;
10
11
/**
12
 * Class Missing
13
 * @package Pagantis\SeleniumFormUtils\Step\Result\Status
14
 */
15
class Missing extends AbstractStep
16
{
17
    /**
18
     * Handler step
19
     */
20
    const STEP = 'Missing';
21
22
    /**
23
     * @return string
24
     */
25
    protected function getDNI()
26
    {
27
        $dni = '0000' . rand(pow(10, 4-1), pow(10, 4)-1);
28
        $value = (int) ($dni / 23);
29
        $value *= 23;
30
        $value= $dni - $value;
31
        $letter= "TRWAGMYFPDXBNJZSQVHLCKEO";
32
        $dniLetter= substr($letter, $value, 1);
33
34
        return $dni.$dniLetter;
35
    }
36
37
    /**
38
     * Second step fill the form data (dni, address...)
39
     *
40
     * @param bool $rejected
41
     * @return bool
42
     * @throws \Exception
43
     */
44
    public function run($rejected = false)
45
    {
46
        $this->validateStep(self::STEP);
47
48
        /*
49
         * Field DNI:
50
         */
51
        try {
52
            $name = $this->webDriver->findElement(WebDriverBy::name('dni'));
53
            $name->clear()->sendKeys($this->getDNI());
54
        } catch (\Exception $exception) {
55
            unset($exception);
56
        }
57
        /*
58
         * Field BirthDate:
59
         */
60
        try {
61
            $dob = $this->webDriver->findElement(WebDriverBy::name('dob'));
62
            $dob->clear()->sendKeys('12/12/1979');
63
        } catch (\Exception $exception) {
64
            unset($exception);
65
        }
66
        /*
67
         * Field address:
68
         */
69
        try {
70
            $name = $this->webDriver->findElement(WebDriverBy::name('address'));
71
            $name->clear()->sendKeys($this->faker->address. ' ' . $this->faker->city);
0 ignored issues
show
The property address does not seem to exist on Faker\Factory.
Loading history...
The property city does not seem to exist on Faker\Factory.
Loading history...
72
        } catch (\Exception $exception) {
73
            unset($exception);
74
        }
75
        /*
76
         * Field city:
77
         */
78
        try {
79
            $name = $this->webDriver->findElement(WebDriverBy::name('city'));
80
            $name->clear()->sendKeys($this->faker->city);
81
        } catch (\Exception $exception) {
82
            unset($exception);
83
        }
84
        /*
85
         * Field zipcode:
86
         */
87
        try {
88
            $name = $this->webDriver->findElement(WebDriverBy::name('zipcode'));
89
            $name->clear()->sendKeys('28045');
90
        } catch (\Exception $exception) {
91
            unset($exception);
92
        }
93
        /*
94
         * Field Phone:
95
         */
96
        try {
97
            $name = $this->webDriver->findElement(WebDriverBy::name('mobilePhone'));
98
            $name->clear()->sendKeys('6' . $this->faker->randomNumber(8));
0 ignored issues
show
The method randomNumber() does not exist on Faker\Factory. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

98
            $name->clear()->sendKeys('6' . $this->faker->/** @scrutinizer ignore-call */ randomNumber(8));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
99
        } catch (\Exception $exception) {
100
            unset($exception);
101
        }
102
        /*
103
         * Field Full Name:
104
         */
105
        try {
106
            $name = $this->webDriver->findElement(WebDriverBy::name('name'));
107
            $name->clear()->sendKeys(
108
                $this->faker->firstName . ' ' . $this->faker->lastName
0 ignored issues
show
The property lastName does not seem to exist on Faker\Factory.
Loading history...
The property firstName does not seem to exist on Faker\Factory.
Loading history...
109
            );
110
        } catch (\Exception $exception) {
111
            unset($exception);
112
        }
113
114
        /*
115
         * Field password:
116
         */
117
        try {
118
            $name = $this->webDriver->findElement(WebDriverBy::name('password'));
119
            if (null === SeleniumHelper::$mobilePhone) {
0 ignored issues
show
The condition null === Pagantis\Seleni...niumHelper::mobilePhone is always false.
Loading history...
120
                throw new \Exception('Please provide mobile phone for returning customer');
121
            } else {
122
                $name->clear()->sendKeys(substr(SeleniumHelper::$mobilePhone, -4));
123
            }
124
        } catch (\Exception $exception) {
125
            unset($exception);
126
        }
127
128
        /*
129
         * Click form continue
130
         */
131
        $element = WebDriverBy::name("continue_button");
132
        try {
133
            $condition = WebDriverExpectedCondition::elementToBeClickable($element);
134
            $this->webDriver->wait(90, 1500)->until($condition);
135
            $formContinue = $this->webDriver->findElement($element);
136
            $formContinue->click();
137
        } catch (\Exception $exception) {
138
            sleep(10);
139
            unset($exception);
140
        }
141
142
        return true;
143
    }
144
}
145