public function testWithoutMagium() { // This test is based off of my own test environment and so everything up until the Twitter authentication will // not work. So ignore the first part. $webDriver = RemoteWebDriver::create('http://*****:*****@data-strategy="twitter"]')); $webDriver->wait()->until(ExpectedCondition::visibilityOf($element)); $element->click(); // Start from here $configurationProvider = new StandardConfigurationProvider(new ConfigurationReader(), new ClassConfigurationReader(), new EnvironmentConfigurationReader()); $collector = new DefaultPropertyCollector(); $action = new AuthenticateTwitter($webDriver, new \Magium\Twitter\Themes\Twitter($configurationProvider, $collector), new Twitter($configurationProvider, $collector)); $action->execute(); $webDriver->quit(); }
public function nextAction() { $this->webdriver->wait()->until(ExpectedCondition::elementExists($this->theme->getShippingMethodContinueButtonXpath(), WebDriver::BY_XPATH)); $this->webdriver->wait()->until(ExpectedCondition::visibilityOf($this->webdriver->byXpath($this->theme->getShippingMethodContinueButtonXpath()))); $this->webdriver->byXpath($this->theme->getShippingMethodContinueButtonXpath())->click(); $this->webdriver->wait()->until(WebDriverExpectedCondition::not(WebDriverExpectedCondition::visibilityOf($this->webdriver->byXpath($this->theme->getShippingMethodContinueCompletedXpath())))); return true; }
public function execute() { $this->webdriver->wait()->until(ExpectedCondition::elementExists($this->theme->getShippingMethodContinueButtonXpath(), WebDriver::BY_XPATH)); $this->webdriver->wait()->until(ExpectedCondition::visibilityOf($this->webdriver->byXpath($this->theme->getShippingMethodContinueButtonXpath()))); $this->shipping->choose($this->requireShipping); return true; // continue to next step }
public function execute(WebDriverElement $testElement = null) { if ($testElement instanceof WebDriverElement) { $this->webDriver->wait()->until(ExpectedCondition::elementRemoved($testElement)); } $this->webDriver->wait()->until(ExpectedCondition::elementExists($this->theme->getGuaranteedPageLoadedElementDisplayedXpath(), WebDriver::BY_XPATH)); $element = $this->webDriver->byXpath($this->theme->getGuaranteedPageLoadedElementDisplayedXpath()); $this->webDriver->wait()->until(ExpectedCondition::visibilityOf($element)); }
public function execute() { $this->webdriver->wait(10)->until(ExpectedCondition::elementExists($this->theme->getPaymentMethodContinueButtonXpath(), WebDriver::BY_XPATH)); $element = $this->webdriver->byXpath($this->theme->getPaymentMethodContinueButtonXpath()); $this->webdriver->wait(5)->until(ExpectedCondition::visibilityOf($element)); /* Given that there is the possibility of either a) products with $0, and b) payment methods that do not use * the standard form we do not fail if we cannot find payment elements */ $this->paymentMethod->pay($this->requirePayment); return true; }
/** * @param array $instructions * @throws ElementNotVisibleException * @throws InvalidConfigurationException * @throws \Facebook\WebDriver\Exception\NoSuchElementException * @throws \Facebook\WebDriver\Exception\TimeOutException */ public function navigateTo(array $instructions) { $this->testCase->assertGreaterThan(0, count($instructions), 'Instruction navigator requires at least one instruction'); $useAutomaticTiming = true; foreach ($instructions as $key => $instruction) { if (count($instruction) > 0 && $instruction[0] == self::INSTRUCTION_USE_MANUAL_TIMING) { $useAutomaticTiming = false; } } foreach ($instructions as $instruction) { $this->testCase->assertCount(2, $instruction, 'Navigation instructions need to be a 2 member array. First item is the instruction type, the second is the XPath'); list($instruction, $xpath) = $instruction; if ($useAutomaticTiming) { $this->testCase->sleep('100ms'); // Courtesy sleep of 100ms if ($instruction == self::INSTRUCTION_MOUSE_MOVETO || $instruction == self::INSTRUCTION_MOUSE_CLICK) { $this->webdriver->wait()->until(ExpectedCondition::elementExists($xpath, WebDriver::BY_XPATH)); $this->webdriver->wait(5)->until(ExpectedCondition::elementToBeClickable(WebDriverBy::xpath($xpath))); } } switch ($instruction) { case self::INSTRUCTION_MOUSE_CLICK: $element = $this->webdriver->byXpath($xpath); if (!$element->isDisplayed()) { throw new ElementNotVisibleException('The element is not visible: ' . $xpath); } $element->click(); break; case self::INSTRUCTION_MOUSE_MOVETO: $element = $this->webdriver->byXpath($xpath); $this->webdriver->getMouse()->mouseMove($element->getCoordinates()); break; case self::INSTRUCTION_WAIT_FOR_EXISTS: $this->webdriver->wait()->until(ExpectedCondition::elementExists($xpath, WebDriver::BY_XPATH)); break; case self::INSTRUCTION_WAIT_FOR_NOT_EXISTS: $this->webdriver->wait()->until(ExpectedCondition::not(ExpectedCondition::elementExists($xpath, WebDriver::BY_XPATH))); break; case self::INSTRUCTION_WAIT_FOR_DISPLAYED: $element = $this->webdriver->byXpath($xpath); $this->webdriver->wait()->until(ExpectedCondition::visibilityOf($element)); break; case self::INSTRUCTION_PAUSE: $this->testCase->sleep($xpath); break; case self::INSTRUCTION_WAIT_FOR_HIDDEN: $element = $this->webdriver->byXpath($xpath); $this->webdriver->wait()->until(ExpectedCondition::not(ExpectedCondition::visibilityOf($element))); break; default: throw new InvalidConfigurationException('Unknown login instruction: ' . $instruction); } } }
public function execute() { if ($this->enterNewAddress) { $this->webdriver->wait()->until(ExpectedCondition::visibilityOf($this->webdriver->byXpath($this->theme->getShippingNewAddressXpath()))); $this->webdriver->byXpath($this->theme->getShippingNewAddressXpath())->click(); $this->webdriver->wait()->until(ExpectedCondition::visibilityOf($this->webdriver->byXpath($this->theme->getShippingFirstNameXpath()))); } // We will bypass ourself if the billing address is the same as the shipping address. if (!$this->webdriver->elementDisplayed($this->theme->getShippingFirstNameXpath(), AbstractTestCase::BY_XPATH)) { $this->bypassNextStep = true; return true; } // assertions $this->testCase->assertElementExists($this->theme->getShippingFirstNameXpath(), WebDriver::BY_XPATH); $this->testCase->assertElementExists($this->theme->getShippingLastNameXpath(), WebDriver::BY_XPATH); $this->testCase->assertElementExists($this->theme->getShippingCompanyXpath(), WebDriver::BY_XPATH); $this->testCase->assertElementExists($this->theme->getShippingAddressXpath(), WebDriver::BY_XPATH); $this->testCase->assertElementExists($this->theme->getShippingAddress2Xpath(), WebDriver::BY_XPATH); $this->testCase->assertElementExists($this->theme->getShippingCityXpath(), WebDriver::BY_XPATH); $regionXpath = $this->theme->getShippingRegionIdXpath($this->customerIdentity->getShippingRegionId()); $this->testCase->assertElementExists($regionXpath, WebDriver::BY_XPATH); $this->testCase->assertElementExists($this->theme->getShippingPostCodeXpath(), WebDriver::BY_XPATH); $countryXpath = $this->theme->getShippingCountryIdXpath($this->customerIdentity->getShippingCountryId()); $this->testCase->assertElementExists($countryXpath, WebDriver::BY_XPATH); $this->testCase->assertElementExists($this->theme->getShippingTelephoneXpath(), WebDriver::BY_XPATH); $this->testCase->assertElementExists($this->theme->getShippingFaxXpath(), WebDriver::BY_XPATH); $this->testCase->assertElementExists($this->theme->getShippingContinueButtonXpath(), WebDriver::BY_XPATH); // clear $this->testCase->byXpath($this->theme->getShippingFirstNameXpath())->clear(); $this->testCase->byXpath($this->theme->getShippingLastNameXpath())->clear(); $this->testCase->byXpath($this->theme->getShippingCompanyXpath())->clear(); $this->testCase->byXpath($this->theme->getShippingAddressXpath())->clear(); $this->testCase->byXpath($this->theme->getShippingAddress2Xpath())->clear(); $this->testCase->byXpath($this->theme->getShippingCityXpath())->clear(); $this->testCase->byXpath($this->theme->getShippingPostCodeXpath())->clear(); $this->testCase->byXpath($this->theme->getShippingTelephoneXpath())->clear(); $this->testCase->byXpath($this->theme->getShippingFaxXpath())->clear(); // execute $this->testCase->byXpath($this->theme->getShippingFirstNameXpath())->sendKeys($this->customerIdentity->getShippingFirstName()); $this->testCase->byXpath($this->theme->getShippingLastNameXpath())->sendKeys($this->customerIdentity->getShippingLastName()); $this->testCase->byXpath($this->theme->getShippingCompanyXpath())->sendKeys($this->customerIdentity->getShippingCompany()); $this->testCase->byXpath($this->theme->getShippingAddressXpath())->sendKeys($this->customerIdentity->getShippingAddress()); $this->testCase->byXpath($this->theme->getShippingAddress2Xpath())->sendKeys($this->customerIdentity->getShippingAddress2()); $this->testCase->byXpath($this->theme->getShippingCityXpath())->sendKeys($this->customerIdentity->getShippingCity()); $regionXpath = $this->theme->getShippingRegionIdXpath($this->customerIdentity->getShippingRegionId()); $this->testCase->byXpath($regionXpath)->click(); $this->testCase->byXpath($this->theme->getShippingPostCodeXpath())->sendKeys($this->customerIdentity->getShippingPostCode()); $countryXpath = $this->theme->getShippingCountryIdXpath($this->customerIdentity->getShippingCountryId()); $this->testCase->byXpath($countryXpath)->click(); $this->testCase->byXpath($this->theme->getShippingTelephoneXpath())->sendKeys($this->customerIdentity->getShippingTelephone()); $this->testCase->byXpath($this->theme->getShippingFaxXpath())->sendKeys($this->customerIdentity->getShippingFax()); return true; }
protected function preExecute() { if ($this->enterNewAddress) { $this->webdriver->wait()->until(ExpectedCondition::visibilityOf($this->webdriver->byXpath($this->theme->getShippingNewAddressXpath()))); $this->webdriver->byXpath($this->theme->getShippingNewAddressXpath())->click(); $this->webdriver->wait()->until(ExpectedCondition::visibilityOf($this->webdriver->byXpath($this->theme->getShippingFirstNameXpath()))); } // We will bypass ourself if the billing address is the same as the shipping address. if (!$this->webdriver->elementDisplayed($this->theme->getShippingFirstNameXpath(), AbstractTestCase::BY_XPATH)) { $this->bypassNextStep = true; return true; } return false; }
public function navigateTo($path) { $paths = explode('/', $path); $xpath = $this->themeConfiguration->getNavigationBaseXPathSelector(); $this->webdriver->wait()->until(ExpectedCondition::visibilityOf($this->webdriver->byXpath($xpath))); $element = null; foreach ($paths as $p) { $element = $this->pathAction($p, $xpath); } if (!$this->themeConfiguration->getUseClicksToNavigate() && $element instanceof WebDriverElement) { $element->click(); $this->loaded->execute($element); } }
public function extract() { $testXpath = $this->theme->getSearchSuggestionTextXpath(1); $this->webDriver->wait(5)->until(ExpectedCondition::elementExists($testXpath, WebDriver::BY_XPATH)); $testElement = $this->webDriver->byXpath($testXpath); $this->webDriver->wait(5)->until(ExpectedCondition::visibilityOf($testElement)); $count = 0; $this->suggestions = []; while ($this->webDriver->elementExists($this->theme->getSearchSuggestionTextXpath(++$count), WebDriver::BY_XPATH)) { $suggestionCount = trim($this->webDriver->byXpath($this->theme->getSearchSuggestionCountXpath($count))->getText()); $suggestionText = trim($this->webDriver->byXpath($this->theme->getSearchSuggestionTextXpath($count))->getText()); $suggestionText = trim($suggestionText, $suggestionCount); $this->suggestions[] = new SearchSuggestion($this->webDriver->byXpath($this->theme->getSearchSuggestionTextXpath($count)), $suggestionCount, $suggestionText); } }
protected function clickAddToCart() { $element = $this->addToCart->getElement(); // Because, for some reason, the M2 design HIDES the add-to-cart button as part of the default theme. Why // would you want to hide the second most important button on the site? try { $element->click(); } catch (\Exception $e) { $e2 = $this->webDriver->byXpath($this->theme->getAddToCartXpath() . '/ancestor::li'); $this->webDriver->getMouse()->mouseMove($e2->getCoordinates()); $element->click(); } $this->webDriver->wait()->until(ExpectedCondition::elementExists($this->theme->getAddToCartSuccessXpath(), WebDriver::BY_XPATH)); $element = $this->webDriver->byXpath($this->theme->getAddToCartSuccessXpath()); $this->webDriver->wait()->until(ExpectedCondition::visibilityOf($element)); }
public function navigateTo($tab) { $tabs = explode('::', $tab); $tab = $header = array_shift($tabs); if (count($tabs)) { $header = array_shift($tabs); } $element = $this->webDriver->byXpath($this->themeConfiguration->getWidgetTabXpath($tab)); $element->click(); if ($header) { $this->webDriver->wait()->until(ExpectedCondition::elementExists($this->themeConfiguration->getWidgetTabHeaderXpath($header), WebDriver::BY_XPATH)); $element = $this->webDriver->byXpath($this->themeConfiguration->getWidgetTabHeaderXpath($header)); } else { $this->loadingMask->wait(); } $this->webDriver->wait()->until(ExpectedCondition::visibilityOf($element)); }
public function execute($registerForNewsletter = false) { $this->webdriver->wait(5)->until(ExpectedCondition::elementExists($this->theme->getRegisterFirstNameXpath(), WebDriver::BY_XPATH)); $firstnameElement = $this->webdriver->byXpath($this->theme->getRegisterFirstNameXpath()); $this->webdriver->wait(5)->until(ExpectedCondition::visibilityOf($firstnameElement)); $lastnameElement = $this->webdriver->byXpath($this->theme->getRegisterLastNameXpath()); $emailElement = $this->webdriver->byXpath($this->theme->getRegisterEmailXpath()); $passwordElement = $this->webdriver->byXpath($this->theme->getRegisterPasswordXpath()); $confirmElement = $this->webdriver->byXpath($this->theme->getRegisterConfirmPasswordXpath()); $registerElement = $this->webdriver->byXpath($this->theme->getRegisterNewsletterXpath()); $firstnameElement->sendKeys($this->customerIdentity->getFirstName()); $lastnameElement->sendKeys($this->customerIdentity->getLastName()); $emailElement->sendKeys($this->customerIdentity->getEmailAddress()); $passwordElement->sendKeys($this->customerIdentity->getPassword()); $confirmElement->sendKeys($this->customerIdentity->getPassword()); if ($registerForNewsletter) { $registerElement->click(); } }
public function navigateTo($path) { $paths = explode('/', $path); $xpath = $this->themeConfiguration->getNavigationBaseXPathSelector(); $this->webdriver->wait()->until(ExpectedCondition::visibilityOf($this->webdriver->byXpath($xpath))); $level = 0; $element = null; foreach ($paths as $p) { usleep(500000); // Give the UI some time to update $xpath .= '/descendant::' . $this->themeConfiguration->getNavigationChildXPathSelector($level++, $p); $element = $this->webdriver->byXpath($xpath . '/a'); $this->webdriver->getMouse()->mouseMove($element->getCoordinates()); $this->webdriver->wait()->until(ExpectedCondition::visibilityOf($element)); } if ($element instanceof WebDriverElement) { $element->click(); } $this->loaded->execute($element); }
public function navigateTo(AbstractCustomerNavigation $navigation) { $this->adminMenuNavigator->navigateTo('Customers/Manage Customers'); $this->clearTableFilters->clear(); $parts = explode('-', $navigation->getSelectorID()); foreach ($parts as $part) { $element = $this->webDriver->byId($part); $element->sendKeys($navigation->getSearch()); } $this->clickButton->click($this->themeConfiguration->getSearchButtonText()); $this->testCase->sleep('100ms'); $this->waitForLoadingMask->wait(); $selectXpath = $this->themeConfiguration->getSelectCustomerXpath($navigation->getSearch()); $this->testCase->assertElementDisplayed($selectXpath, WebDriver::BY_XPATH); $element = $this->webDriver->byXpath($selectXpath); $element->click(); $elementExists = $this->testCase->getTranslator()->translatePlaceholders('//h4[.="{{Personal Information}}"]'); $this->webDriver->wait()->until(ExpectedCondition::elementExists($elementExists, WebDriver::BY_XPATH)); $element = $this->webDriver->byXpath($elementExists); $this->webDriver->wait()->until(ExpectedCondition::visibilityOf($element)); }
public function testAuthenticationWorksEvenIfCurrentUserIsLoggedIn() { $this->markTestSkipped('This test requires a local Magium environment. It will not work.'); // This test is based off of my own test environment and so everything up until the Twitter authentication will // not work. So ignore the first part. // Also note that this test only works for users that have NOT signed in with your app. $identity = $this->getIdentity(Twitter::IDENTITY); /* @var $identity Twitter */ $this->commandOpen('https://www.twitter.com/'); $this->byText('Log In')->click(); $this->byXpath('//input[@name="session[username_or_email]"]')->sendKeys($identity->getUsername()); $this->byXpath('//input[@name="session[password]"]')->sendKeys($identity->getPassword()); $this->byXpath('//input[@type="submit" and @value="Log in"]')->click(); $this->commandOpen('http://magiumlib.loc/'); $this->byText('Log In')->click(); $this->webdriver->wait()->until(ExpectedCondition::elementExists('//div[@data-strategy="twitter"]', WebDriver::BY_XPATH)); $element = $this->byXpath('//div[@data-strategy="twitter"]'); $this->webdriver->wait()->until(ExpectedCondition::visibilityOf($element)); $this->byXpath('//div[@data-strategy="twitter"]')->click(); // This part should work for you $action = $this->getAction(SignInWithTwitter::ACTION); /* @var $action AuthenticateTwitter */ $action->execute(); }
/** * This method will wait until the message window is open, indicating that the message has been loaded. This timeout * could be immediate or several minutes, depending on the maximum expected elapsed time from when the email is * requested to when it is sent. * */ protected function waitForMessageScreen() { $this->webDriver->wait($this->getMessageTimeout())->until(ExpectedCondition::visibilityOf($this->webDriver->byId('close-message-window'))); }
public function wait() { $this->webDriver->wait()->until(ExpectedCondition::not(ExpectedCondition::visibilityOf($this->webDriver->byId('loading-mask')))); }