| 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/1982', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         'customeremail'       => '[email protected]', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         'customerpwd'         => 'oscommerce_demo', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         'country'             => '195', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         'city'                => 'Barcelona', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         'methodName'          => 'Pagantis', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         'checkoutTitle'       => 'Instant Financing', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         'confirmationMsg'     => 'Pedido recibido', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         'checkoutDescription' => 'Pay up to 12 comfortable installments with Pagantis', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         'enter'               => 'Haz click aquí para acceder', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      * WooCommerce constructor. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      * @param null   $name | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      * @param array  $data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      * @param string $dataName | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 61 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |     public function __construct($name = null, array $data = array(), $dataName = '') | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |         $faker = Factory::create(); | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |         $this->configuration['dni'] = $this->getDNI(); | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |         $this->configuration['firstname'] = $faker->firstName; | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |         $this->configuration['lastname'] = $faker->lastName . ' ' . $faker->lastName; | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |         $this->configuration['company'] = $faker->company; | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |         $this->configuration['zip'] = '28'.$faker->randomNumber(3, true); | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |         $this->configuration['address'] = $faker->streetAddress; | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |         $this->configuration['phone'] = '6' . $faker->randomNumber(8); | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |         $this->configuration['email'] = date('ymd') . '@pagantis.com'; | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |         parent::__construct($name, $data, $dataName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     protected function getDNI() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         $dni = '0000' . rand(pow(10, 4-1), pow(10, 4)-1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         $value = (int) ($dni / 23); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         $value *= 23; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         $value= $dni - $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         $letter= "TRWAGMYFPDXBNJZSQVHLCKEO"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         $dniLetter= substr($letter, $value, 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         return $dni.$dniLetter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      * @var RemoteWebDriver | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     protected $webDriver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |      * Configure selenium | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     protected function setUp() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         $this->webDriver = PagantisWebDriver::create( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |             'http://localhost:4444/wd/hub', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |             DesiredCapabilities::chrome(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |             90000, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |             90000 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |      * @param $name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |      * @return RemoteWebElement | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     public function findByName($name) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |         return $this->webDriver->findElement(WebDriverBy::name($name)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |      * @param $id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |      * @return RemoteWebElement | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |     public function findById($id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |         return $this->webDriver->findElement(WebDriverBy::id($id)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |      * @param $className | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |      * @return RemoteWebElement | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |     public function findByClass($className) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |         return $this->webDriver->findElement(WebDriverBy::className($className)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |      * @param $css | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |      * @return RemoteWebElement | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |     public function findByCss($css) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |         return $this->webDriver->findElement(WebDriverBy::cssSelector($css)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |      * @param $xpath | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |      * @return RemoteWebElement | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |     public function findByXpath($xpath) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |         return $this->webDriver->findElement(WebDriverBy::xpath($xpath)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |      * @param $link | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |      * @return RemoteWebElement | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |     public function findByLinkText($link) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |         return $this->webDriver->findElement(WebDriverBy::partialLinkText($link)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |      * @param WebDriverExpectedCondition $condition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |      * @throws \Facebook\WebDriver\Exception\NoSuchElementException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |      * @throws \Facebook\WebDriver\Exception\TimeOutException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |     public function waitUntil(WebDriverExpectedCondition $condition) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |         return $this->webDriver->wait()->until($condition); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |      * @param WebDriverElement $element | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |      * @return WebDriverElement | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |     public function moveToElementAndClick(WebDriverElement $element) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |         $action = new WebDriverActions($this->webDriver); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |         $action->moveToElement($element); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |         $action->click($element); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |         $action->perform(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |         return $element; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |      * @param WebDriverElement $element | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |      * @return WebDriverElement | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |     public function getParent(WebDriverElement $element) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |         return $element->findElement(WebDriverBy::xpath("..")); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |      * Quit browser | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |     protected function quit() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |         $this->webDriver->quit(); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 209 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 210 |  |  | } |