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