1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Pagantis\SeleniumFormUtils\Step\ConfirmData; |
4
|
|
|
|
5
|
|
|
use Facebook\WebDriver\WebDriverBy; |
6
|
|
|
use Facebook\WebDriver\WebDriverSelect; |
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 = '/confirm-data/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
|
|
|
* Pass from confirm-data to next step in Application Form |
39
|
|
|
* |
40
|
|
|
* @throws \Exception |
41
|
|
|
*/ |
42
|
|
|
public function run() |
43
|
|
|
{ |
44
|
|
|
$this->validateStep(self::STEP); |
45
|
|
|
//Click on confirm: |
46
|
|
|
$this->waitTobeVisible(WebDriverBy::name('workingStatus')); |
47
|
|
|
$select = new WebDriverSelect($this->webDriver->findElement(WebDriverBy::name('workingStatus'))); |
48
|
|
|
$select->selectByValue('employed'); |
49
|
|
|
|
50
|
|
|
/* |
51
|
|
|
* Optional Full Name: |
52
|
|
|
*/ |
53
|
|
|
try { |
54
|
|
|
$name = $this->webDriver->findElement(WebDriverBy::name('name')); |
55
|
|
|
$name->clear()->sendKeys( |
56
|
|
|
$this->faker->firstName . ' ' . $this->faker->lastName |
|
|
|
|
57
|
|
|
); |
58
|
|
|
} catch (\Exception $exception) { |
59
|
|
|
unset($exception); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/* |
63
|
|
|
* Optional DNI: |
64
|
|
|
*/ |
65
|
|
|
try { |
66
|
|
|
$name = $this->webDriver->findElement(WebDriverBy::name('dni')); |
67
|
|
|
$name->clear()->sendKeys($this->getDNI()); |
68
|
|
|
} catch (\Exception $exception) { |
69
|
|
|
unset($exception); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/* |
73
|
|
|
* Optional BirthDate: |
74
|
|
|
*/ |
75
|
|
|
try { |
76
|
|
|
$select = new WebDriverSelect($this->webDriver->findElement(WebDriverBy::name('dob-day'))); |
77
|
|
|
$select->selectByValue($this->faker->numberBetween(1, 28)); |
|
|
|
|
78
|
|
|
$select = new WebDriverSelect($this->webDriver->findElement(WebDriverBy::name('dob-month'))); |
79
|
|
|
$select->selectByValue($this->faker->numberBetween(1, 12)); |
80
|
|
|
$select = new WebDriverSelect($this->webDriver->findElement(WebDriverBy::name('dob-year'))); |
81
|
|
|
$select->selectByValue('1975'); |
82
|
|
|
} catch (\Exception $exception) { |
83
|
|
|
unset($exception); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/* |
87
|
|
|
* Optional Phone: |
88
|
|
|
*/ |
89
|
|
|
try { |
90
|
|
|
$name = $this->webDriver->findElement(WebDriverBy::name('cellphone')); |
91
|
|
|
$name->clear()->sendKeys('6' . $this->faker->randomNumber(8)); |
|
|
|
|
92
|
|
|
} catch (\Exception $exception) { |
93
|
|
|
unset($exception); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/* |
97
|
|
|
* Optional address: |
98
|
|
|
*/ |
99
|
|
|
try { |
100
|
|
|
$name = $this->webDriver->findElement(WebDriverBy::name('address')); |
101
|
|
|
$name->clear()->sendKeys($this->faker->address. ' ' . $this->faker->city); |
|
|
|
|
102
|
|
|
} catch (\Exception $exception) { |
103
|
|
|
unset($exception); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/* |
107
|
|
|
* Optional city: |
108
|
|
|
*/ |
109
|
|
|
try { |
110
|
|
|
$name = $this->webDriver->findElement(WebDriverBy::name('city')); |
111
|
|
|
$name->clear()->sendKeys($this->faker->city); |
112
|
|
|
} catch (\Exception $exception) { |
113
|
|
|
unset($exception); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/* |
117
|
|
|
* Optional zipcode: |
118
|
|
|
*/ |
119
|
|
|
try { |
120
|
|
|
$name = $this->webDriver->findElement(WebDriverBy::name('zipcode')); |
121
|
|
|
$name->clear()->sendKeys($this->faker->postcode); |
|
|
|
|
122
|
|
|
} catch (\Exception $exception) { |
123
|
|
|
unset($exception); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/* |
127
|
|
|
* Optional password: |
128
|
|
|
*/ |
129
|
|
|
try { |
130
|
|
|
$name = $this->webDriver->findElement(WebDriverBy::name('password')); |
131
|
|
|
if (null === SeleniumHelper::$mobilePhone) { |
|
|
|
|
132
|
|
|
throw new \Exception('Please provide mobile phone for returning customer'); |
133
|
|
|
} else { |
134
|
|
|
$name->clear()->sendKeys(substr(SeleniumHelper::$mobilePhone, -4)); |
135
|
|
|
} |
136
|
|
|
} catch (\Exception $exception) { |
137
|
|
|
unset($exception); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/* |
141
|
|
|
* Click form continue |
142
|
|
|
*/ |
143
|
|
|
try { |
144
|
|
|
$formContinue = $this->webDriver->findElement(WebDriverBy::name('edit_customer_data_form_continue')); |
145
|
|
|
$formContinue->click(); |
146
|
|
|
} catch (\Exception $exception) { |
147
|
|
|
unset($exception); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/* |
151
|
|
|
* Click login button |
152
|
|
|
*/ |
153
|
|
|
try { |
154
|
|
|
$formContinue = $this->webDriver->findElement(WebDriverBy::name('login_modal_loginButton')); |
155
|
|
|
$formContinue->click(); |
156
|
|
|
} catch (\Exception $exception) { |
157
|
|
|
unset($exception); |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|