private function checkDomainPointsToShopWithoutRedirection($domain, $shopName, $timeout = 300) { $spinner = new Spinner(null, $timeout, 5000); $url = $this->getBrowser()->getCurrentURL(); $spinner->addPassthroughExceptionClass('PrestaShop\\PSTAF\\Exception\\Unexpected301Exception'); $spinner->assertNoException(function () use($domain, $shopName) { if (!preg_match('#^\\w+://#', $domain)) { $url = "http://{$domain}"; } else { $url = $domain; } list($status, $location) = $this->getStatusAndLocation($url); if ($status === 301) { throw new Unexpected301Exception('Redirected to `' . $location . '`. Expected status code 200 on `' . $url . '`, but got 301. This is very bad because 301 is permanent.'); } elseif ($status !== 200) { throw new Exception('Expected status code 200 on `' . $url . '`, but got ' . $status . '.'); } $this->getBrowser()->visit($url); $currentURL = $this->getBrowser()->getCurrentURL(); if (strpos($currentURL, $domain) === false) { throw new Exception('Not a primary domain, redirected to `' . $currentURL . '` but expected `' . $domain . '`.'); } $alt = $this->getBrowser()->getAttribute('#header_logo img', 'alt'); if (strtolower($alt) !== strtolower($shopName)) { throw new Exception('This is not the shop you\'re looking for. Got `' . $alt . '` instead of `' . $shopName . '`.'); } }); $this->getBrowser()->visit($url); return $this; }
/** * find */ private function _find($selector, array $options = array()) { $defaults = ['unique' => true, 'wait' => true, 'baseElement' => null, 'timeout' => $this->defaultTimeout, 'interval' => $this->defaultInterval, 'displayed' => null, 'enabled' => null]; $options = array_merge($defaults, $options); $base = $this->driver; if ($options['baseElement']) { $base = $options['baseElement']->getNativeElement(); } if (!$options['wait']) { $options['timeout'] = 0; } $finalSelector = $selector; $selectorType = 'cssSelector'; if (preg_match('/^{xpath}(.*)$/', $selector, $m)) { $finalSelector = $m[1]; $selectorType = 'xpath'; } $spinner = new Spinner(null, $options['timeout'], $options['interval']); $spinner->addPassthroughExceptionClass('PrestaShop\\PSTAF\\Exception\\TooManyElementsFoundException'); try { return $spinner->assertNoException(function () use($base, $selectorType, $finalSelector, $options) { $found = $base->findElements(WebDriverBy::$selectorType($finalSelector)); $elements = array_map(function ($nativeElement) { return new Element($nativeElement, $this); }, $found); if ($options['displayed'] !== null || $options['enabled'] !== null) { $elements = array_filter($elements, function ($element) use($options) { $ok = true; if ($options['displayed'] !== null) { $ok = $ok && $element->isDisplayed() == $options['displayed']; } if ($ok && $options['enabled'] !== null) { $ok = $ok && $element->isEnabled() == $options['enabled']; } return $ok; }); } if (empty($elements)) { throw new Exception('No element found.'); } $nFound = count($elements); if ($options['unique'] && $nFound > 1) { throw new TooManyElementsFoundException("Found `{$nFound}` elements matching selector `{$finalSelector}`."); } // reindex array starting at 0 $elements = array_values($elements); if ($options['unique']) { return $elements[0]; } else { return $elements; } }); } catch (Exception $e) { if ($e instanceof TooManyElementsFoundException) { throw $e; } throw new ElementNotFoundException('Could not find element(s) (selector: `' . $selector . '`).', 1, $e); } }