/** * 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(); }
/** * 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(); }
/** * * @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; }
/** * Path for submit registration button on create account page * * @return string */ public function getRegistrationSubmitButtonPath() { return "//button[@type='submit'][" . Menta_Util_Div::contains($this->__('Submit'), 'title') . "]"; }
/** * 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; }