1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Test; |
4
|
|
|
|
5
|
|
|
use Facebook\WebDriver\Interactions\WebDriverActions; |
6
|
|
|
use Facebook\WebDriver\Remote\DesiredCapabilities; |
7
|
|
|
use Facebook\WebDriver\Remote\RemoteWebDriver; |
8
|
|
|
use Facebook\WebDriver\WebDriverBy; |
9
|
|
|
use Facebook\WebDriver\WebDriverElement; |
10
|
|
|
use Facebook\WebDriver\WebDriverExpectedCondition; |
11
|
|
|
use Facebook\WebDriver\Remote\RemoteWebElement; |
12
|
|
|
use Faker\Factory; |
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class PagantisOscommerceTest |
17
|
|
|
* @package Test |
18
|
|
|
*/ |
19
|
|
|
abstract class PagantisOscommerceTest extends TestCase |
20
|
|
|
{ |
21
|
|
|
const OSCURL = 'http://oscommerce-test.docker:8096'; |
22
|
|
|
|
23
|
|
|
const BACKOFFICE_FOLDER = '/admin'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Const title |
27
|
|
|
*/ |
28
|
|
|
const TITLE = 'osCommerce'; |
29
|
|
|
/** |
30
|
|
|
* Const admin_title |
31
|
|
|
*/ |
32
|
|
|
const ADMIN_TITLE = 'osCommerce Online Merchant Administration Tool'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var array |
36
|
|
|
*/ |
37
|
|
|
protected $configuration = array( |
38
|
|
|
'username' => 'root', |
39
|
|
|
'password' => 'root', |
40
|
|
|
'publicKey' => 'tk_fd53cd467ba49022e4f8215e', |
41
|
|
|
'secretKey' => '21e57baa97459f6a', |
42
|
|
|
'birthdate' => '05/05/2005', |
43
|
|
|
'firstname' => 'Jøhn', |
44
|
|
|
'lastname' => 'Dōè', |
45
|
|
|
'email' => '[email protected]', |
46
|
|
|
'longpwd' => 'd53cd467ba49022e4f821', |
47
|
|
|
'company' => 'Digital Origin SL', |
48
|
|
|
'zip' => '08023', |
49
|
|
|
'country' => '195', |
50
|
|
|
'city' => 'Barcelona', |
51
|
|
|
'phone' => '600123123', |
52
|
|
|
'dni' => '09422447Z', |
53
|
|
|
'extra' => 'Free Finance', |
54
|
|
|
'address' => 'Av.Diagonal 579', |
55
|
|
|
'methodName' => 'Pagantis', |
56
|
|
|
'checkoutTitle' => 'Instant Financing', |
57
|
|
|
'defaultMinIns' => 3, |
58
|
|
|
'defaultMaxIns' => 12, |
59
|
|
|
'defaultSimulatorOpt' => 6, |
60
|
|
|
'confirmationMsg'=>'Pedido recibido', |
61
|
|
|
'checkoutDescription'=> 'Pay up to 12 comfortable installments with Pagantis', |
62
|
|
|
'enter' => 'Haz clic aquí para acceder' |
63
|
|
|
); |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* WooCommerce constructor. |
68
|
|
|
* |
69
|
|
|
* @param null $name |
|
|
|
|
70
|
|
|
* @param array $data |
71
|
|
|
* @param string $dataName |
72
|
|
|
*/ |
73
|
|
|
public function __construct($name = null, array $data = array(), $dataName = '') |
74
|
|
|
{ |
75
|
|
|
$faker = Factory::create(); |
76
|
|
|
$this->configuration['dni'] = $this->getDNI(); |
77
|
|
|
// $this->configuration['birthdate'] = |
78
|
|
|
// $faker->numberBetween(1, 28) . '/' . |
79
|
|
|
// $faker->numberBetween(1, 12). '/1975' |
80
|
|
|
// ; |
81
|
|
|
$this->configuration['firstname'] = $faker->firstName; |
82
|
|
|
$this->configuration['lastname'] = $faker->lastName . ' ' . $faker->lastName; |
83
|
|
|
$this->configuration['company'] = $faker->company; |
84
|
|
|
$this->configuration['zip'] = '28'.$faker->randomNumber(3, true); |
85
|
|
|
$this->configuration['street'] = $faker->streetAddress; |
86
|
|
|
$this->configuration['phone'] = '6' . $faker->randomNumber(8); |
87
|
|
|
$this->configuration['email'] = date('ymd') . '@pagantis.com'; |
88
|
|
|
parent::__construct($name, $data, $dataName); |
89
|
|
|
} |
90
|
|
|
/** |
91
|
|
|
* @return string |
92
|
|
|
*/ |
93
|
|
|
protected function getDNI() |
94
|
|
|
{ |
95
|
|
|
$dni = '0000' . rand(pow(10, 4-1), pow(10, 4)-1); |
96
|
|
|
$value = (int) ($dni / 23); |
97
|
|
|
$value *= 23; |
98
|
|
|
$value= $dni - $value; |
99
|
|
|
$letter= "TRWAGMYFPDXBNJZSQVHLCKEO"; |
100
|
|
|
$dniLetter= substr($letter, $value, 1); |
101
|
|
|
return $dni.$dniLetter; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @var RemoteWebDriver |
106
|
|
|
*/ |
107
|
|
|
protected $webDriver; |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Configure selenium |
111
|
|
|
*/ |
112
|
|
|
protected function setUp() |
113
|
|
|
{ |
114
|
|
|
$this->webDriver = PagantisWebDriver::create( |
115
|
|
|
'http://localhost:4444/wd/hub', |
116
|
|
|
DesiredCapabilities::chrome(), |
117
|
|
|
90000, |
118
|
|
|
90000 |
119
|
|
|
); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param $name |
124
|
|
|
* |
125
|
|
|
* @return RemoteWebElement |
126
|
|
|
*/ |
127
|
|
|
public function findByName($name) |
128
|
|
|
{ |
129
|
|
|
return $this->webDriver->findElement(WebDriverBy::name($name)); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @param $id |
134
|
|
|
* |
135
|
|
|
* @return RemoteWebElement |
136
|
|
|
*/ |
137
|
|
|
public function findById($id) |
138
|
|
|
{ |
139
|
|
|
return $this->webDriver->findElement(WebDriverBy::id($id)); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @param $className |
144
|
|
|
* |
145
|
|
|
* @return RemoteWebElement |
146
|
|
|
*/ |
147
|
|
|
public function findByClass($className) |
148
|
|
|
{ |
149
|
|
|
return $this->webDriver->findElement(WebDriverBy::className($className)); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @param $css |
154
|
|
|
* |
155
|
|
|
* @return RemoteWebElement |
156
|
|
|
*/ |
157
|
|
|
public function findByCss($css) |
158
|
|
|
{ |
159
|
|
|
return $this->webDriver->findElement(WebDriverBy::cssSelector($css)); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @param $xpath |
164
|
|
|
* |
165
|
|
|
* @return RemoteWebElement |
166
|
|
|
*/ |
167
|
|
|
public function findByXpath($xpath) |
168
|
|
|
{ |
169
|
|
|
return $this->webDriver->findElement(WebDriverBy::xpath($xpath)); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @param $link |
174
|
|
|
* |
175
|
|
|
* @return RemoteWebElement |
176
|
|
|
*/ |
177
|
|
|
public function findByLinkText($link) |
178
|
|
|
{ |
179
|
|
|
return $this->webDriver->findElement(WebDriverBy::partialLinkText($link)); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @param WebDriverExpectedCondition $condition |
184
|
|
|
* @return mixed |
185
|
|
|
* @throws \Facebook\WebDriver\Exception\NoSuchElementException |
186
|
|
|
* @throws \Facebook\WebDriver\Exception\TimeOutException |
187
|
|
|
*/ |
188
|
|
|
public function waitUntil(WebDriverExpectedCondition $condition) |
189
|
|
|
{ |
190
|
|
|
return $this->webDriver->wait()->until($condition); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @param WebDriverElement $element |
195
|
|
|
* |
196
|
|
|
* @return WebDriverElement |
197
|
|
|
*/ |
198
|
|
|
public function moveToElementAndClick(WebDriverElement $element) |
199
|
|
|
{ |
200
|
|
|
$action = new WebDriverActions($this->webDriver); |
201
|
|
|
$action->moveToElement($element); |
202
|
|
|
$action->click($element); |
203
|
|
|
$action->perform(); |
204
|
|
|
|
205
|
|
|
return $element; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* @param WebDriverElement $element |
210
|
|
|
* |
211
|
|
|
* @return WebDriverElement |
212
|
|
|
*/ |
213
|
|
|
public function getParent(WebDriverElement $element) |
214
|
|
|
{ |
215
|
|
|
return $element->findElement(WebDriverBy::xpath("..")); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* Quit browser |
220
|
|
|
*/ |
221
|
|
|
protected function quit() |
222
|
|
|
{ |
223
|
|
|
$this->webDriver->quit(); |
224
|
|
|
} |
225
|
|
|
} |