/** * Check newsletter box and subscribe to newsletter * * @test */ public function testCheckNewsletterboxAndSave() { /* @var $mail MagentoComponents_ImapMail */ $mail = Menta_ComponentManager::get('MagentoComponents_ImapMail'); $mail->deleteAllMailsMatching('Newsletter subscription success'); /* @var $customerAccount MagentoComponents_Pages_CustomerAccount */ $customerAccount = Menta_ComponentManager::get('MagentoComponents_Pages_CustomerAccount'); $customerAccount->login(); $customerAccount->openDashboard(); $this->getHelperAssert()->assertElementPresent($customerAccount->getNewsletterEditPathInDashoboard()); $this->getHelperCommon()->click($customerAccount->getNewsletterEditPathInDashoboard()); $this->getHelperWait()->waitForElementPresent('//h1[' . Menta_Util_Div::containsText('Newsletter Subscription') . ']'); if ($this->getHelperCommon()->isSelected("//input[@id='subscription']")) { $this->markTestSkipped('Subscribe to newsletter already selected!'); } $this->getHelperAssert()->assertElementPresent("//input[@id='subscription']"); $this->getHelperCommon()->click("//input[@id='subscription']"); $this->getHelperCommon()->isSelected("//input[@id='subscription']"); $this->getHelperCommon()->click('//form[@id="form-validate"]//button[@type="submit"]'); /* @var $message MagentoComponents_Pages_Message */ $message = Menta_ComponentManager::get('MagentoComponents_Pages_Message'); $message->waitForSuccessMessagePresent('The subscription has been saved'); $this->getHelperWait()->waitForTextPresent('The subscription has been saved.'); $mail->checkNewsletterSignUpMail(array('firstname' => 'Test', 'lastname' => 'User')); }
/** * Constructor * * Parameter can be set in the phpunit xml configuration file: * <code> * <listeners> * <listener class="..." file="..."> * <arguments> * <string>...</string><!-- targetFile --> * * <string>...</string><!-- directory --> * * <array> * <element key="js/handle.gif"> * <string>###MENTA_ROOTDIR###/PHPUnit/Listener/Resources/Templates/files/handle.gif</string> * </element> * <element key="js/jquery.beforeafter-1.4.min.js"> * <string>###MENTA_ROOTDIR###/PHPUnit/Listener/Resources/Templates/files/jquery.beforeafter-1.4.min.js</string> * </element> * <!-- ... --> * </array> * </arguments> * </listener> * </listeners> * </code> * * @param string $targetFile * @param string $templateFile * @param array $additionalFiles * @throws Exception * @author Fabrizio Branca */ public function __construct($targetFile = NULL, $templateFile = NULL, array $additionalFiles = NULL) { if (!is_null($targetFile)) { $this->targetFile = $targetFile; $this->targetFile = Menta_Util_Div::replaceWithEnvironmentVariables($this->targetFile); } $dir = dirname($this->targetFile); if (!is_dir($dir)) { throw new Exception("Target dir '{$dir}' does not exist"); } // clean target dir foreach (glob($dir . "/*") as $file) { if (!is_dir($file)) { unlink($file); } } if (!is_null($templateFile)) { $this->templateFile = $templateFile; } $this->templateFile = str_replace('###MENTA_ROOTDIR###', MENTA_ROOTDIR, $this->templateFile); if (empty($this->templateFile)) { throw new Exception('No template file defined'); } if (!is_null($additionalFiles)) { $this->additionalFiles = $additionalFiles; } parent::__construct($this->targetFile); }
/** * Put simple products into cart * * @test */ public function putItemsIntoCartFromProductSingleView() { $cart = Menta_ComponentManager::get('MagentoComponents_Pages_Cart'); /* @var $cart MagentoComponents_Pages_Cart */ $cart->clearCart(); /* @var $helper MagentoComponents_Helper */ $helper = Menta_ComponentManager::get('MagentoComponents_Helper'); /* @var $singleView MagentoComponents_Pages_ProductSingleView */ $singleView = Menta_ComponentManager::get('MagentoComponents_Pages_ProductSingleView'); $this->assertEquals(0, $helper->getCartItemsFromHeader(), 'Cart items from eggs is not 0'); $singleView->putProductsIntoCart($this->getConfiguration()->getValue('testing.simple.product.id')); $this->assertEquals(1, $helper->getCartItemsFromHeader(), 'Cart items from eggs is not 1'); $singleView->putProductsIntoCart(52); $this->assertEquals(2, $helper->getCartItemsFromHeader(), 'Cart items from eggs is not 2'); // add same product a second $singleView->putProductsIntoCart(52); /* @var $categoryView MagentoComponents_Pages_CategoryView */ $categoryView = Menta_ComponentManager::get('MagentoComponents_Pages_CategoryView'); $categoryView->open(10); $this->assertEquals(3, $helper->getCartItemsFromHeader(), 'Cart items from eggs is not 3 (from category view)'); $cart->open(); $this->assertEquals(3, $helper->getCartItemsFromHeader(), 'Cart items from eggs is not 3 (from cart view)'); $this->assertEquals(2, $this->getHelperCommon()->getElementCount($cart->getCartTablePath() . "/tbody/tr"), 'Expecting 2 rows in cart'); // remove second row $this->getHelperCommon()->click($cart->getCartTablePath() . '/tbody/tr[2]/td/a[' . Menta_Util_Div::contains($cart->__('Remove item'), 'title') . ']'); $this->assertEquals(1, $helper->getCartItemsFromHeader(), 'Cart items from eggs is not 1 (from cart view)'); }
/** * Check user name when logged in * * @test */ public function userNameWhenLoggedIn() { /* @var $customer MagentoComponents_Pages_CustomerAccount */ $customer = Menta_ComponentManager::get('MagentoComponents_Pages_CustomerAccount'); $customer->login(); $customer->openDashboard(); $this->getHelperAssert()->assertElementContainsText('//div[' . Menta_Util_Div::contains('welcome-msg') . ']', 'Test User'); $customer->logout(); }
public function __construct($x1, $y1 = null, $x2 = null, $y2 = null) { if ($x1 instanceof \WebDriver\Element) { list($x1, $y1, $x2, $y2) = array_values(Menta_Util_Div::getElementCoordinates($x1)); } $this->x1 = $x1; $this->y1 = $y1; $this->x2 = $x2; $this->y2 = $y2; }
/** * Check user name when logged in * @test */ public function userNameWhenLoggedIn() { $admin = Menta_ComponentManager::get('MagentoComponents_Pages_Admin'); /* @var $admin MagentoComponents_Pages_Admin */ $admin->openAdmin(); $adminUser = $admin->getAdminUser(); $admin->logIntoAdmin($adminUser['username'], $adminUser['password']); $this->getHelperAssert()->assertElementContainsText('//div[' . Menta_Util_Div::contains('header') . ']', $adminUser['username']); $admin->logoutFromAdmin(); }
/** * Order simple product with different shipping address * * @test * @group adds_testdata */ public function orderWithDifferentShippingAddress() { /* @var $cart MagentoComponents_Pages_Cart */ $cart = Menta_ComponentManager::get('MagentoComponents_Pages_Cart'); $cart->clearCart(); $productSingleView = Menta_ComponentManager::get('MagentoComponents_Pages_ProductSingleView'); /* @var $productSingleView MagentoComponents_Pages_ProductSingleView */ $productSingleView->putProductsIntoCart($this->getConfiguration()->getValue('testing.simple.product.id')); $onePageCheckout = Menta_ComponentManager::get('MagentoComponents_Pages_OnePageCheckout'); /* @var $onePageCheckout MagentoComponents_Pages_OnePageCheckout */ $onePageCheckout->open(); $onePageCheckout->setCheckoutMethod('register'); $onePageCheckout->finishStep('checkoutMethod'); $onePageCheckout->addAddress('uk', 'billing'); $this->getHelperAssert()->assertElementPresent('billing:customer_password'); $onePageCheckout->saveAccountForLaterUse(); $onePageCheckout->toggleShipToDifferentAddress(); /* @var $customerAccount MagentoComponents_Pages_CustomerAccount */ $customerAccount = Menta_ComponentManager::get('MagentoComponents_Pages_CustomerAccount'); $onePageCheckout->finishStep('billingAddress'); $onePageCheckout->addAddress('uk', 'shipping'); $onePageCheckout->finishStep('shippingAddress'); $onePageCheckout->finishStep('shippingMethod'); $onePageCheckout->selectPaymentMethodCheckmo(); $onePageCheckout->finishStep('paymentMethod'); $onePageCheckout->submitForm(); $this->lastOrderId = $onePageCheckout->getOrderIdFromSuccessPage(); $lastOrderNumber = $onePageCheckout->getOrderNumberFromSuccessPage(); $this->getHelperCommon()->open('/sales/order/history/?limit=50'); $viewOrderLinkPath = '//*[@id="my-orders-table"]/tbody/tr/td/span/a[contains(@href, "view/order_id/' . $this->lastOrderId . '")]'; $this->getHelperCommon()->click($viewOrderLinkPath); $this->getHelperWait()->waitForElementPresent('//h1[ ' . Menta_Util_Div::containsText("Order #{$lastOrderNumber}") . ']'); $this->getHelperAssert()->assertTextPresent($this->lastOrderId); $addressProvider = new MagentoComponents_Provider_Address(); $shippingAddress = $addressProvider->getAddressField('shipping', 'uk'); $billingAddress = $addressProvider->getAddressField('billing', 'uk'); $this->getHelperAssert()->assertTextPresent($shippingAddress['firstname']); $this->getHelperAssert()->assertTextPresent($shippingAddress['lastname']); $this->getHelperAssert()->assertTextPresent($shippingAddress['street1']); if (isset($shippingAddress['region']) && $shippingAddress['region']) { $this->getHelperAssert()->assertTextPresent($shippingAddress['region']); } $this->getHelperAssert()->assertTextPresent($shippingAddress['country']); $this->getHelperAssert()->assertTextPresent($shippingAddress['phone']); $this->getHelperAssert()->assertTextPresent($billingAddress['firstname']); $this->getHelperAssert()->assertTextPresent($billingAddress['lastname']); $this->getHelperAssert()->assertTextPresent($billingAddress['street1']); if (isset($billingAddress['region']) && $billingAddress['region']) { $this->getHelperAssert()->assertTextPresent($billingAddress['region']); } $this->getHelperAssert()->assertTextPresent($billingAddress['country']); $this->getHelperAssert()->assertTextPresent($billingAddress['phone']); return $lastOrderNumber; }
/** * Rectangle processor constructor * * @param int $x1 * @param int $y1 * @param int $x2 * @param int $y2 * @param string $color * @param bool $fill */ public function __construct($x1, $y1 = NULL, $x2 = NULL, $y2 = NULL, $color = '#ffffff', $fill = true) { if ($x1 instanceof \WebDriver\Element) { list($x1, $y1, $x2, $y2) = array_values(Menta_Util_Div::getElementCoordinates($x1)); } $this->x1 = $x1; $this->y1 = $y1; $this->x2 = $x2; $this->y2 = $y2; $this->color = $color; $this->fill = $fill; }
/** * Get configuration value * * @throws Exception if key is not found * @param string $key * @return string */ public function getValue($key, $throwException = true) { if (empty($GLOBALS[__CLASS__ . '_defaultsLoaded'])) { $this->loadDefaults(); } if (!$this->issetKey($key)) { if ($throwException) { throw new Exception(sprintf('Could not find configuration key "%s"', $key)); } return null; } $value = $GLOBALS[$key]; $value = Menta_Util_Div::replaceWithEnvironmentVariables($value); if (is_string($value)) { if (strpos($value, '[') !== false || strpos($value, '{') !== false) { // json decoding if possible $jsonDecoded = json_decode($value, true); if (!is_null($jsonDecoded)) { $value = $jsonDecoded; } } } return $value; }
/** * * @return string */ public function getTaxXpath() { return "//tfoot//td[" . Menta_Util_Div::containsText('Tax') . "]/following-sibling::td/span[" . Menta_Util_Div::contains('price') . "]"; }
/** * Assert no error message present */ public function assertNoErrorMessagePresent() { $xpath = '//ul[' . Menta_Util_Div::contains('messages') . ']'; $xpath .= '/li[' . Menta_Util_Div::contains('error-msg') . ']'; $this->getHelperAssert()->assertElementNotPresent($xpath, 'Error messsage found!'); }
/** * Get xpath to "add to cart" * * @param int $productId * @return string */ public function getAddToCartLinkXpath($productId) { $xpath = "//li//button[" . Menta_Util_Div::contains($this->__('Add to Cart'), 'title') . " and contains(@onclick," . $productId . ")] "; return $xpath; }
/** * Create random user name * * @param int $length * @return string */ public function createRandomName($length = 8) { $name = Menta_Util_Div::createRandomString($length, 'abcdefghijklmnopqrstuvwxyz'); return ucfirst($name); }
/** * Path for any link in header * @param $text * @return string */ public function getLinkPathFromHeader($text) { return '//div[' . Menta_Util_Div::contains('header') . ']//ul[' . Menta_Util_Div::contains('links') . ']//a[' . Menta_Util_Div::contains($text, 'title') . ' ]'; }
/** * Get status xpath * * @param $status * @return string */ public function getStatusXpath($status) { return '//*[@id="product_addtocart_form"]//p[' . Menta_Util_Div::contains($status, 'class') . ']/span'; }
/** * @test * @group adds_testdata */ public function testInvalidDataRegistration() { /* @var $customerAccount MagentoComponents_Pages_CustomerAccount */ $customerAccount = Menta_ComponentManager::get('MagentoComponents_Pages_CustomerAccount'); $this->getHelperCommon()->open('/customer/account/create/'); $userAccount = array('username' => $customerAccount->createNewMailAddress('register'), 'password' => 'testtest', 'firstname' => "Test_{$this->testId}", 'lastname' => "User_{$this->testId}"); $this->getHelperWait()->waitForTextPresent($customerAccount->__('Create an Account')); $this->getHelperAssert()->assertTextPresent($customerAccount->__('Confirm Password')); $formFields = array('firstname', 'lastname', 'email_address', 'password', 'confirmation'); foreach ($formFields as $formField) { $this->getHelperAssert()->assertElementPresent("id={$formField}"); } $this->getHelperCommon()->click($customerAccount->getRegistrationSubmitButtonPath()); // all fields should have failed foreach ($formFields as $formField) { $this->getHelperAssert()->assertElementPresent("//input[@id='{$formField}']/following-sibling::div[@class='validation-advice']"); } $this->getHelperCommon()->type("id=firstname", $userAccount['firstname']); $this->getHelperCommon()->click($customerAccount->getRegistrationSubmitButtonPath()); $this->getHelperWait()->waitForElementNotVisible("//input[@id='firstname']/following-sibling::div[@class='validation-advice']"); $this->getHelperCommon()->type("id=lastname", $userAccount['lastname']); // triggering revalidation $this->getHelperCommon()->click($customerAccount->getRegistrationSubmitButtonPath()); $this->getHelperWait()->waitForElementNotVisible("//input[@id='lastname']/following-sibling::div[@class='validation-advice']"); // first try invalid mail address ... $this->getHelperCommon()->type("id=email_address", "invalid_mail_address"); // triggering revalidation $this->getHelperCommon()->click($customerAccount->getRegistrationSubmitButtonPath()); $this->getHelperAssert()->assertElementPresent("//input[@id='email_address']/following-sibling::div[@id='advice-validate-email-email_address']"); $this->assertEquals('Please enter a valid email address. For example johndoe@domain.com.', $this->getHelperCommon()->getText("//input[@id='email_address']/following-sibling::div[@id='advice-validate-email-email_address']")); // ... then a valid mail address $this->getHelperCommon()->type("id=email_address", $userAccount['username']); $this->getHelperCommon()->click($customerAccount->getRegistrationSubmitButtonPath()); /*how to check if element is not */ $this->getHelperAssert()->assertElementPresent("//div[@id='advice-validate-email-email_address'][" . Menta_Util_Div::contains('display: none;', 'style') . "]"); // First try too short passwort ... $this->getHelperCommon()->type("id=password", "short"); $this->getHelperCommon()->click($customerAccount->getRegistrationSubmitButtonPath()); $this->getHelperAssert()->assertElementPresent("//input[@id='password']/following-sibling::div[@id='advice-validate-password-password']"); $this->assertEquals('Please enter 6 or more characters. Leading or trailing spaces will be ignored.', $this->getHelperCommon()->getText("//input[@id='password'][" . Menta_Util_Div::contains('validation-failed') . "]/following-sibling::div[@class='validation-advice']")); // ... then a password that is long enough $this->getHelperCommon()->type("id=password", $userAccount['password'], true); $this->getHelperCommon()->click($customerAccount->getRegistrationSubmitButtonPath()); $this->getHelperAssert()->assertElementNotPresent("//input[@id='password'][" . Menta_Util_Div::contains('validation-failed') . "]"); // ... then a password that does not match $this->getHelperCommon()->type("id=confirmation", "doesntmatch"); $this->getHelperAssert()->assertElementPresent("//input[@id='confirmation'][" . Menta_Util_Div::contains('validation-failed') . "]"); $this->getHelperCommon()->click($customerAccount->getRegistrationSubmitButtonPath()); $this->assertEquals('Please make sure your passwords match.', $this->getHelperCommon()->getText("//input[@id='confirmation']/following-sibling::div[" . Menta_Util_Div::contains('validation-advice') . "]")); // ... and finally a matching password $this->getHelperCommon()->type("id=confirmation", $userAccount['password'], true); $this->getHelperAssert()->assertElementNotPresent("//div[contains(@class,'validation-error')]/input[@id='confirmation']"); $this->getHelperCommon()->click($customerAccount->getRegistrationSubmitButtonPath()); // Check if everything is ok and we're in the dashboard $this->getHelperAssert()->assertTextPresent('Thank you for registering with Main Store'); $customerAccount->assertIsOnDashboard(); $this->getHelperAssert()->assertTextPresent($userAccount['firstname'] . ' ' . $userAccount['lastname'], 'Firstname, lastname not present.'); $this->getHelperAssert()->assertTextPresent($userAccount['username'], "Email/username not present."); $this->getHelperAssert()->assertTextPresent('You have not set a default billing address.'); $this->getHelperAssert()->assertTextPresent('You have not set a default shipping address.'); $customerAccount->logoutViaOpen(); return $userAccount; }