diff --git a/config/localization.yaml b/config/localization.yaml index a0c75f0..5fecb3a 100644 --- a/config/localization.yaml +++ b/config/localization.yaml @@ -32,6 +32,11 @@ default: successfulAccountCreation: Your account has been created. Log in with your email address and password. emailDoesNotExistError: The email address you entered doesn't exist. Please try again. incorrectPasswordError: The password you entered is incorrect. Please try again. + CheckoutPages: + shippingAddressFormTitle: Enter a shipping address + newShippingAddressFormTitle: Add a new shipping address + billingAddressFormTitle: Enter a billing address + newBillingAddressFormTitle: Add a new billing address General: addresses: fullname: Full name* diff --git a/src/test/java/posters/cucumber/features/Order.feature b/src/test/java/posters/cucumber/features/Order.feature index c08a3ab..fe643b5 100644 --- a/src/test/java/posters/cucumber/features/Order.feature +++ b/src/test/java/posters/cucumber/features/Order.feature @@ -5,7 +5,7 @@ Feature: Order Given "" is open And product page "" is open When I add this product with size "" and style "" to the cart - And I specify the shipping address "", "", "
", "", "", "", "" and use it for billing + And I specify the shipping address "", "", "", "", "
", "", "", "", "", "" and use it for billing And I enter payment data "", "", "", "" Then I see all the products in order overview And my shipping and billing addresses as well as payment data are displayed correctly @@ -13,20 +13,21 @@ Feature: Order @Chrome Examples: - | browser | productUrl | productSize | productStyle | name | company | address | city | state | zip | country | cardNumber | month | year | - | Chrome_1024x768 | productDetail/Grizzly%20Bear?productId=1 | 32 x 24 in | gloss | James | Monster Corporation | 621 Wall St | North Tonawada | New York | 14120 | United States | 4111111111111111 | 05 | 2021 | + | browser | productUrl | productSize | productStyle | firstName | lastName | name | company | address | city | state | zip | country | cardNumber | month | year | sameBillingAddress | + | Chrome_1024x768 | productDetail/Grizzly%20Bear?productId=1 | 32 x 24 in | gloss | Jakobi | Doe | James | Monster Corporation | 621 Wall St | North Tonawada | New York | 14120 | United States | 4111111111111111 | 05 | 2021 | false | + | Chrome_1024x768 | productDetail/Grizzly%20Bear?productId=1 | 32 x 24 in | gloss | Jakobi | Doe | James | Monster Corporation | 621 Wall St | North Tonawada | New York | 14120 | United States | 4111111111111111 | 05 | 2021 | true | @Firefox Examples: - | browser | productUrl | productSize | productStyle | name | company | address | city | state | zip | country | cardNumber | month | year | - | Firefox_1024x768 | productDetail/Grizzly%20Bear?productId=1 | 32 x 24 in | gloss | James | Monster Corporation | 621 Wall St | North Tonawada | New York | 14120 | United States | 4111111111111111 | 05 | 2021 | + | browser | productUrl | productSize | productStyle | firstName | lastName | name | company | address | city | state | zip | country | cardNumber | month | year | sameBillingAddress | + | Firefox_1024x768 | productDetail/Grizzly%20Bear?productId=1 | 32 x 24 in | gloss | Jakobi | Doe | James | Monster Corporation | 621 Wall St | North Tonawada | New York | 14120 | United States | 4111111111111111 | 05 | 2021 | false | @DeleteUserAfterwards - Scenario Outline: Order some products as User + Scenario Outline: Order some products as registered User Given "" is open And new user with "", "", "", "" is registered and logged in When I add product "" in size "" and style "" - And I specify the shipping address "", "", "
", "", "", "", "" and use it for billing + And I specify the shipping address "", "", "", "", "
", "", "", "", "", "" and use it for billing And I enter payment data "", "", "", "" Then I see all the products in order overview And my shipping and billing addresses as well as payment data are displayed correctly diff --git a/src/test/java/posters/cucumber/support/BrowseRandomVisualAssertSupport.java b/src/test/java/posters/cucumber/support/BrowseRandomVisualAssertSupport.java index a4aca02..c6c5f48 100644 --- a/src/test/java/posters/cucumber/support/BrowseRandomVisualAssertSupport.java +++ b/src/test/java/posters/cucumber/support/BrowseRandomVisualAssertSupport.java @@ -10,7 +10,7 @@ import io.cucumber.java.en.When; import posters.pageobjects.pages.browsing.CategoryPage; import posters.pageobjects.pages.browsing.HomePage; -import posters.pageobjects.pages.browsing.ProductdetailPage; +import posters.pageobjects.pages.browsing.ProductDetailPage; public class BrowseRandomVisualAssertSupport { @@ -21,8 +21,8 @@ public class BrowseRandomVisualAssertSupport @Given("^homepage is open") public void openHomePageAndValidate() { - HomePage homepage = OpenPageFlows.homepage(); - homepage.validateAndVisualAssert(); + var homePage = OpenPageFlows.homePage(); + homePage.validateAndVisualAssert(); } @When("^I choose random sub category with seed \"([^\"]*)\"$") @@ -37,8 +37,7 @@ public void openRandomSubCategoryAndValidate(String seed) random = new Random(Long.valueOf(seed)); } String categoryName = new HomePage().topNav.getRandomSubcategoryName(random); - CategoryPage categoryPage = new HomePage().topNav.clickSubcategoryByName(categoryName); - categoryPage.isExpectedPage(); + var categoryPage = new HomePage().topNav.clickSubcategoryByName(categoryName); categoryPage.validateAndVisualAssert(categoryName); } @@ -52,7 +51,7 @@ public void openRandomProduct() @Then("^I see correct product") public void validateProduct() { - new ProductdetailPage().validateAndVisualAssert(productName); + new ProductDetailPage().validateAndVisualAssert(productName); } } diff --git a/src/test/java/posters/cucumber/support/CartSupport.java b/src/test/java/posters/cucumber/support/CartSupport.java index 2e9ba5a..5522097 100644 --- a/src/test/java/posters/cucumber/support/CartSupport.java +++ b/src/test/java/posters/cucumber/support/CartSupport.java @@ -3,7 +3,7 @@ import io.cucumber.java.en.Then; import io.cucumber.java.en.When; import posters.dataobjects.Product; -import posters.pageobjects.pages.browsing.ProductdetailPage; +import posters.pageobjects.pages.browsing.ProductDetailPage; import posters.pageobjects.pages.checkout.CartPage; import posters.pageobjects.utility.PriceHelper; @@ -20,15 +20,14 @@ public CartSupport(GlobalStorage storage) @When("^I open the cart$") public void openCart() { - CartPage cartPage = new ProductdetailPage().miniCart.openCartPage(); - cartPage.isExpectedPage(); + new ProductDetailPage().miniCart.openCartPage(); } @Then("^I see all the added products in the cart and their properties are correct$") public void validateProductsInTheCart() { double subtotal = 0.0; - CartPage cartPage = new CartPage(); + var cartPage = new CartPage(); for (Product product : storage.products) { @@ -39,25 +38,18 @@ public void validateProductsInTheCart() } @Then("^I can change amount of the \"([^\"]*)\" with \"([^\"]*)\" and \"([^\"]*)\" to (\\d+)$") - public void updateCountOfProduct(String productName, String size, String style, int amount) + public void updateCountOfProduct(String name, String size, String style, int amount) { - CartPage cartPage = new CartPage(); - cartPage.updateProductCountByName(productName, style, size, amount); - for (Product product : storage.products) - { - if (product.getName().equals(productName) && product.getSize().equals(size) - && product.getStyle().equals(style)) - { - product.setAmount(amount); - } - cartPage.validateContainsProduct(product); - } + var cartPage = new CartPage(); + cartPage.updateProductCountByName(name, style, size, amount); + + storage.updateCountOfProduct(name, size, style, amount); } @Then("^I can remove \"([^\"]*)\" with \"([^\"]*)\" and \"([^\"]*)\"$") public void removeProduct(String productName, String size, String style) { - CartPage cartPage = new CartPage(); + var cartPage = new CartPage(); cartPage.removeProductByName(productName, style, size); storage.removeProduct(productName, style, size); diff --git a/src/test/java/posters/cucumber/support/GlobalStorage.java b/src/test/java/posters/cucumber/support/GlobalStorage.java index df949e3..2a4f8d7 100644 --- a/src/test/java/posters/cucumber/support/GlobalStorage.java +++ b/src/test/java/posters/cucumber/support/GlobalStorage.java @@ -1,6 +1,3 @@ -/** - * - */ package posters.cucumber.support; import java.util.ArrayList; @@ -38,9 +35,7 @@ public Product addProduct(Product product) // increase amount of product if already there or add the whole product if (products.contains(product)) { - Product updatedProduct = products.get(products.indexOf(product)); - updatedProduct.setAmount(updatedProduct.getAmount() + 1); - return updatedProduct; + return updateCountOfProduct(product.getName(), product.getSize(), product.getStyle(), product.getAmount() + 1); } else { @@ -49,15 +44,32 @@ public Product addProduct(Product product) } } - public void removeProduct(String productName, String style, String size) + public Product getProductFromArrayList(String name, String size, String style) { + int i = 0; for (Product product : products) { - if (product.getName().equals(productName) && product.getSize().equals(size) - && product.getStyle().equals(style)) + if (product.getName().equals(name) && product.getSize().equals(size) && product.getStyle().equals(style)) { - products.remove(product); + i = products.indexOf(product); } } + return products.get(i); + } + + public Product updateCountOfProduct(String name, String size, String style, int amount) + { + var product = getProductFromArrayList(name, size, style); + String unitPrice = product.getUnitPrice(); + products.remove(products.indexOf(product)); + product = new Product(name, unitPrice, style, size, amount); + products.add(product); + return product; + } + + public void removeProduct(String name, String style, String size) + { + var product = getProductFromArrayList(name, size, style); + products.remove(product); } } diff --git a/src/test/java/posters/cucumber/support/HomePageSupport.java b/src/test/java/posters/cucumber/support/HomePageSupport.java index 9dc8369..90e3cb1 100644 --- a/src/test/java/posters/cucumber/support/HomePageSupport.java +++ b/src/test/java/posters/cucumber/support/HomePageSupport.java @@ -1,17 +1,14 @@ package posters.cucumber.support; import io.cucumber.java.en.Then; -import io.qameta.allure.Step; import posters.pageobjects.pages.browsing.HomePage; public class HomePageSupport { @Then("^I see homepage with logo, carousel, hot products and footer and it's title is \"([^\"]*)\"$") - @Step("validate homepage") public void validateHomePage(String title) { - HomePage homePage = new HomePage(); - homePage.isExpectedPage(); + var homePage = new HomePage(); homePage.title.validateTitle(title); homePage.validateStructure(); homePage.footer.validate(); diff --git a/src/test/java/posters/cucumber/support/OpenPageFlows.java b/src/test/java/posters/cucumber/support/OpenPageFlows.java index 15705b2..bcb3287 100644 --- a/src/test/java/posters/cucumber/support/OpenPageFlows.java +++ b/src/test/java/posters/cucumber/support/OpenPageFlows.java @@ -6,60 +6,48 @@ import com.xceptance.neodymium.util.Neodymium; import io.cucumber.java.en.Given; -import io.qameta.allure.Step; import posters.pageobjects.pages.browsing.HomePage; -import posters.pageobjects.pages.browsing.ProductdetailPage; +import posters.pageobjects.pages.browsing.ProductDetailPage; import posters.pageobjects.pages.user.LoginPage; import posters.pageobjects.pages.user.RegisterPage; public class OpenPageFlows { @Given("^homepage is loaded$") - @Step("open home page") - public static HomePage homepage() + public static HomePage homePage() { // clear cookies to ensure a new session clearBrowserCookies(); // open home page open(Neodymium.configuration().url()); - HomePage homePage = new HomePage(); - homePage.isExpectedPage(); - return homePage; - }; + return new HomePage().isExpectedPage(); + } @Given("^login page is loaded$") - @Step("open login page") public static LoginPage loginPage() { // open login page and check for expected page - LoginPage loginPage = homepage().userMenu.openLogin(); - loginPage.isExpectedPage(); - return loginPage; - }; + return homePage().userMenu.openLogin(); + } @Given("^register page is loaded$") - @Step("open register page") public static RegisterPage registerPage() { // open login page and check for expected page - RegisterPage registerPage = homepage().userMenu.openRegister(); - registerPage.isExpectedPage(); - return registerPage; - }; + return homePage().userMenu.openRegister(); + } @Given("^product page \"([^\"]*)\" is open$") - @Step("open product page with cleared cookes") - public static ProductdetailPage openProductdetailsPageWithClearedCookes(String url) + public static ProductDetailPage openProductDetailsPageWithClearedCookes(String url) { clearBrowserCookies(); open(Neodymium.configuration().url() + url); - return new ProductdetailPage(); + return new ProductDetailPage().isExpectedPage(); } - @Step("open product page without cleared cookes") - public static ProductdetailPage openProductdetailsPage(String url) + public static ProductDetailPage openProductDetailsPage(String url) { open(Neodymium.configuration().url() + url); - return new ProductdetailPage(); + return new ProductDetailPage().isExpectedPage(); } } diff --git a/src/test/java/posters/cucumber/support/OrderSupport.java b/src/test/java/posters/cucumber/support/OrderSupport.java index c5b9c5d..ea74d77 100644 --- a/src/test/java/posters/cucumber/support/OrderSupport.java +++ b/src/test/java/posters/cucumber/support/OrderSupport.java @@ -3,21 +3,15 @@ import io.cucumber.java.en.Given; import io.cucumber.java.en.Then; import io.cucumber.java.en.When; -import io.qameta.allure.Step; import posters.dataobjects.Address; import posters.dataobjects.CreditCard; import posters.dataobjects.Product; import posters.dataobjects.User; import posters.pageobjects.pages.browsing.HomePage; -import posters.pageobjects.pages.browsing.ProductdetailPage; -import posters.pageobjects.pages.checkout.CartPage; +import posters.pageobjects.pages.browsing.ProductDetailPage; +import posters.pageobjects.pages.checkout.ShippingAddressPage; import posters.pageobjects.pages.checkout.PaymentPage; import posters.pageobjects.pages.checkout.PlaceOrderPage; -import posters.pageobjects.pages.checkout.ShippingAddressPage; -import posters.pageobjects.pages.user.AccountOverviewPage; -import posters.pageobjects.pages.user.LoginPage; -import posters.pageobjects.pages.user.OrderHistoryPage; -import posters.pageobjects.pages.user.RegisterPage; import posters.pageobjects.utility.PriceHelper; public class OrderSupport @@ -33,97 +27,102 @@ public OrderSupport(GlobalStorage storage) @Given("^new user with \"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\" is registered and logged in$") public void registerAndLogIn(String firstName, String lastName, String email, String password) { - RegisterPage registerPage = OpenPageFlows.registerPage(); - registerPage.isExpectedPage(); + // the user is saved for later reuse storage.user = new User(firstName, lastName, email, password); - registerPage.sendRegisterForm(firstName, lastName, email, password, password); - LoginPage loginPage = registerPage.userMenu.openLogin(); - loginPage.isExpectedPage(); + + var registerPage = OpenPageFlows.registerPage(); + registerPage.sendRegisterForm(storage.user); + var loginPage = registerPage.userMenu.openLogin();; loginPage.sendLoginform(email, password); } - @Then("^all the products are to find in order history$") - public void validateOrderInOrderHistory() + @When("I add this product with size \"([^\"]*)\" and style \"([^\"]*)\" to the cart$") + public void addProductToCart(String size, String style) { - AccountOverviewPage accountOverview = new HomePage().userMenu.openAccountOverview(); - accountOverview.isExpectedPage(); - OrderHistoryPage orderHistory = accountOverview.openOrderHistory(); - for (Product product : storage.products) - { - orderHistory.validateContainsProduct(product); - } - } + var productDetailPage = new ProductDetailPage(); + productDetailPage.setSize(size); + productDetailPage.setStyle(style); + var product = storage.addProduct(productDetailPage.getProduct()); + + productDetailPage.addToCart(); + productDetailPage.miniCart.openMiniCart(); + productDetailPage.miniCart.validateMiniCartByProduct(product); + } + @When("^I add product \"([^\"]*)\" in size \"([^\"]*)\" and style \"([^\"]*)\"$") - @Step("open product page and add product to the cart") public void openProductPageAndAddItoTheCart(String productUrl, String size, String style) { - OpenPageFlows.openProductdetailsPage(productUrl); + OpenPageFlows.openProductDetailsPage(productUrl); addProductToCart(size, style); } - - @When("I add this product with size \"([^\"]*)\" and style \"([^\"]*)\" to the cart$") - public void addProductToCart(String size, String style) + + @Then("^I specify the shipping address \"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\" and use it for billing$") + public void openFillAndSendShippingFormUseForBilling(String firstName, String lastName, String name, String company, String street, String city, String state, String zip, String country, boolean sameBillingAddress) { - ProductdetailPage productPage = new ProductdetailPage(); - productPage.setSize(size); - productPage.setStyle(style); - - Product product = storage.addProduct(productPage.getProduct()); + // addresses are saved for later reuse + storage.shippingAddress = new Address(firstName, lastName, company, street, city, state, zip, country); + storage.billingAddress = new Address(firstName, lastName, company, street, city, state, zip, country); - productPage.addToCart(); - productPage.miniCart.openMiniCart(); - productPage.miniCart.validateMiniCartByProduct(product); - } - - @When("^I specify the shipping address \"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\" and use it for billing$") - public void openFillAndSendShippingFormUseForBilling(String name, String company, String address, String city, String state, String zip, String country) - { - CartPage cartPage = new ProductdetailPage().miniCart.openCartPage(); - cartPage.isExpectedPage(); + var cartPage = new ProductDetailPage().miniCart.openCartPage(); ShippingAddressPage shippingPage = cartPage.openShippingPage(); - shippingPage.isExpectedPage(); - shippingPage.sendShippingAddressForm(name, company, address, city, state, zip, country, true); - storage.shippingAddress = new Address(name, company, address, city, state, zip, country); - storage.billingAddress = new Address(name, company, address, city, state, zip, country); - new PaymentPage().isExpectedPage(); + + if (sameBillingAddress) + { + shippingPage.fillShippingAddressWithSameAsBilling(storage.shippingAddress); + } + else + { + var billingPage = shippingPage.fillShippingAddressWithDifferentBilling(storage.shippingAddress); + billingPage.fillBillingAddress(storage.billingAddress); + } } - @When("^I enter payment data \"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\"$") + @Then("^I enter payment data \"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\"$") public void fillAndSendPaymentForm(String name, String cardNumber, String month, String year) { - PaymentPage paymentPage = new PaymentPage(); - paymentPage.isExpectedPage(); - PlaceOrderPage placeOrder = paymentPage.sendPaymentForm(cardNumber, name, month, year); + // the creditcard is saved for later reuse storage.creditcard = new CreditCard(name, cardNumber, "xxxx xxxx xxxx " + cardNumber.substring(12, 16), month, year); - placeOrder.isExpectedPage(); + + var paymentPage = new PaymentPage().isExpectedPage(); + paymentPage.sendPaymentForm(storage.creditcard); } @Then("^I see all the products in order overview$") public void validateContainsAllProductsWithCorrectPricesAndAmount() { double subtotal = 0.0; - PlaceOrderPage placeOrder = new PlaceOrderPage(); + var placeOrderPage = new PlaceOrderPage(); for (Product product : storage.products) { - placeOrder.validateContainsProduct(product); + placeOrderPage.validateContainsProduct(product); subtotal += product.getTotalPrice(); } - placeOrder.validateSubtotal(PriceHelper.format(subtotal)); + placeOrderPage.validateSubtotal(PriceHelper.format(subtotal)); } @Then("^my shipping and billing addresses as well as payment data are displayed correctly") public void validateAddressesAndPaymentData() { - PlaceOrderPage placeOrder = new PlaceOrderPage(); - placeOrder.validateAddressesAndPayment(storage.shippingAddress, storage.billingAddress, storage.creditcard); + var placeOrderPage = new PlaceOrderPage(); + placeOrderPage.validateAddressesAndPayment(storage.shippingAddress, storage.billingAddress, storage.creditcard); } @Then("^my order is successfully placed$") public void placeOrder() { HomePage succssefulOrder = new PlaceOrderPage().placeOrder(); - succssefulOrder.isExpectedPage(); succssefulOrder.validateSuccessfulOrder(); } + + @Then("^all the products are to find in order history$") + public void validateOrderInOrderHistory() + { + var accountOverviewPage = new HomePage().userMenu.openAccountOverview(); + var orderHistoryPage = accountOverviewPage.openOrderHistory(); + for (Product product : storage.products) + { + orderHistoryPage.validateContainsProduct(product); + } + } } diff --git a/src/test/java/posters/cucumber/support/ProductSupport.java b/src/test/java/posters/cucumber/support/ProductSupport.java index 6293cfe..86ac86e 100644 --- a/src/test/java/posters/cucumber/support/ProductSupport.java +++ b/src/test/java/posters/cucumber/support/ProductSupport.java @@ -3,19 +3,19 @@ import io.cucumber.java.en.Then; import io.cucumber.java.en.When; import posters.pageobjects.pages.browsing.CategoryPage; -import posters.pageobjects.pages.browsing.ProductdetailPage; +import posters.pageobjects.pages.browsing.ProductDetailPage; public class ProductSupport { @When("^product \"([^\"]*)\" is opened$") - public ProductdetailPage clickProductByName(String productName) + public void clickProductByName(String productName) { - return new CategoryPage().clickProductByName(productName); + new CategoryPage().clickProductByName(productName); } @Then("^a product detail page shows the headline \"([^\"]*)\"$") public void validateProductName(String name) { - new ProductdetailPage().validateProductName(name); + new ProductDetailPage().validateProductName(name); } } diff --git a/src/test/java/posters/cucumber/support/RegisterSupport.java b/src/test/java/posters/cucumber/support/RegisterSupport.java index cde20d6..0f957cc 100644 --- a/src/test/java/posters/cucumber/support/RegisterSupport.java +++ b/src/test/java/posters/cucumber/support/RegisterSupport.java @@ -4,14 +4,10 @@ import io.cucumber.java.en.Given; import io.cucumber.java.en.Then; import io.cucumber.java.en.When; -import io.qameta.allure.Step; import posters.dataobjects.User; import posters.pageobjects.pages.browsing.HomePage; -import posters.pageobjects.pages.checkout.CartPage; import posters.pageobjects.pages.user.AccountOverviewPage; -import posters.pageobjects.pages.user.DeleteAccountPage; import posters.pageobjects.pages.user.LoginPage; -import posters.pageobjects.pages.user.PersonalDataPage; import posters.pageobjects.pages.user.RegisterPage; public class RegisterSupport @@ -27,24 +23,16 @@ public RegisterSupport(GlobalStorage storage) @Given("^user setup: \"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\"$") public void setUpUser(String firstName, String lastName, String eMail, String password) { - // set up user for the clean up steps + // create a user for later use (e.g. register or delete) storage.user = new User(firstName, lastName, eMail, password); }; - @Given("^login page is opened after registration$") - public void registerUserSetup() - { - // use the user coming from dependency injection - registerUser(storage.user); - } - @After("@DeleteUserAfterwards") - @Step("delete user flow") - public LoginPage deleteUser() + public void deleteUser() { - HomePage homePage = new HomePage(); + var homePage = new HomePage(); // ensure that the user is logged in - LoginPage loginPage; + var loginPage = new LoginPage(); if (!homePage.userMenu.isLoggedIn()) { loginPage = homePage.userMenu.openLogin(); @@ -54,7 +42,7 @@ public LoginPage deleteUser() // needed since there is a bug in posters if (homePage.miniCart.getTotalCount() > 0) { - CartPage cartPage = homePage.miniCart.openCartPage(); + var cartPage = homePage.miniCart.openCartPage(); while (cartPage.hasProductsInCart()) { cartPage.removeProduct(1); @@ -62,15 +50,16 @@ public LoginPage deleteUser() } // goto account page - AccountOverviewPage accountOverviewPage = homePage.userMenu.openAccountOverview(); + var accountOverviewPage = new AccountOverviewPage(); + accountOverviewPage = homePage.userMenu.openAccountOverview(); accountOverviewPage.validateStructure(); // goto personal data page - PersonalDataPage personalDataPage = accountOverviewPage.openPersonalData(); + var personalDataPage = accountOverviewPage.openPersonalData(); personalDataPage.validateStructure(); // goto account deletion page - DeleteAccountPage deleteAccountPage = personalDataPage.openDeleteAccount(); + var deleteAccountPage = personalDataPage.openDeleteAccount(); deleteAccountPage.validateStructure(); // delete the account @@ -82,28 +71,15 @@ public LoginPage deleteUser() loginPage.validateStructure(); loginPage.sendFalseLoginform(storage.user); loginPage.validateWrongEmail(storage.user.getEmail()); - - return loginPage; - } - - public static LoginPage registerUser(User user) - { - RegisterPage registerPage = OpenPageFlows.registerPage(); - registerPage.isExpectedPage(); - LoginPage loginPage = registerPage.sendRegisterForm(user, user.getPassword()); - loginPage.isExpectedPage(); - - return loginPage; } @When("^I register a new user with \"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\"$") - @Step("set up user and register him") public void registerUser(String firstName, String lastName, String email, String password) { - RegisterPage registerPage = new RegisterPage(); + var registerPage = new RegisterPage(); registerPage.isExpectedPage(); storage.user = new User(firstName, lastName, email, password); - registerPage.sendRegisterForm(firstName, lastName, email, password, password); + registerPage.sendRegisterForm(storage.user); } @Given("^new user with \"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\" is registered$") diff --git a/src/test/java/posters/dataobjects/Address.java b/src/test/java/posters/dataobjects/Address.java index e3b9bfa..5efa540 100644 --- a/src/test/java/posters/dataobjects/Address.java +++ b/src/test/java/posters/dataobjects/Address.java @@ -1,6 +1,3 @@ -/** - * - */ package posters.dataobjects; /** @@ -8,11 +5,13 @@ */ public class Address { - String fullName; + String firstName; + + String lastName; String company; - String addressLine; + String street; String city; @@ -23,12 +22,14 @@ public class Address String country; /** - * @param fullName - * the fullName to set + * @param firstName + * the firstName to set + * @param lastName + * the lastName to set * @param company * the company to set - * @param addressLine - * the addressLine to set + * @param street + * the street to set * @param city * the city to set * @param state @@ -38,11 +39,12 @@ public class Address * @param country * the country to set */ - public Address(String fullName, String company, String addressLine, String city, String state, String zip, String country) + public Address(String firstName, String lastName, String company, String street, String city, String state, String zip, String country) { - this.fullName = fullName; + this.firstName = firstName; + this.lastName = lastName; this.company = company; - this.addressLine = addressLine; + this.street = street; this.city = city; this.state = state; this.zip = zip; @@ -50,20 +52,19 @@ public Address(String fullName, String company, String addressLine, String city, } /** - * @return the fullName + * @return the firstName */ - public String getFullName() + public String getFirstName() { - return fullName; + return firstName; } /** - * @param fullName - * the fullName to set + * @return the lastName */ - public void setFullName(String fullName) + public String getLastName() { - this.fullName = fullName; + return lastName; } /** @@ -75,29 +76,11 @@ public String getCompany() } /** - * @param company - * the company to set - */ - public void setCompany(String company) - { - this.company = company; - } - - /** - * @return the address - */ - public String getAddressLine() - { - return addressLine; - } - - /** - * @param addressLine - * the address to set + * @return the street */ - public void setAddressLine(String addressLine) + public String getStreet() { - this.addressLine = addressLine; + return street; } /** @@ -108,15 +91,6 @@ public String getCity() return city; } - /** - * @param city - * the city to set - */ - public void setCity(String city) - { - this.city = city; - } - /** * @return the state */ @@ -125,15 +99,6 @@ public String getState() return state; } - /** - * @param state - * the state to set - */ - public void setState(String state) - { - this.state = state; - } - /** * @return the zip */ @@ -142,15 +107,6 @@ public String getZip() return zip; } - /** - * @param zip - * the zip to set - */ - public void setZip(String zip) - { - this.zip = zip; - } - /** * @return the country */ @@ -159,19 +115,10 @@ public String getCountry() return country; } - /** - * @param country - * the country to set - */ - public void setCountry(String country) - { - this.country = country; - } - @Override public String toString() { - return String.format("Address [fullName()=%s, company()=%s, addressLine()=%s, zip()=%s, city()=%s, state()=%s, country()=%s]", - getFullName(), getCompany(), getAddressLine(), getZip(), getCity(), getState(), getCountry()); + return String.format("Address [firtName()=%s, lastName()=%s, company()=%s, street()=%s, zip()=%s, city()=%s, state()=%s, country()=%s]", + getFirstName(), getLastName(), getCompany(), getStreet(), getZip(), getCity(), getState(), getCountry()); } } diff --git a/src/test/java/posters/dataobjects/CreditCard.java b/src/test/java/posters/dataobjects/CreditCard.java index 6c37296..b710ea8 100644 --- a/src/test/java/posters/dataobjects/CreditCard.java +++ b/src/test/java/posters/dataobjects/CreditCard.java @@ -1,6 +1,3 @@ -/** - * - */ package posters.dataobjects; /** @@ -47,15 +44,6 @@ public String getFullName() return fullName; } - /** - * @param fullName - * the fullName to set - */ - public void setFullName(String fullName) - { - this.fullName = fullName; - } - /** * @return the cardNumber */ @@ -64,15 +52,6 @@ public String getCardNumber() return cardNumber; } - /** - * @param cardNumber - * the cardNumber to set - */ - public void setCardNumber(String cardNumber) - { - this.cardNumber = cardNumber; - } - /** * @return the crypticCardNumber */ @@ -81,15 +60,6 @@ public String getCrypticCardNumber() return crypticCardNumber; } - /** - * @param crypticCardNumber - * the crypticCardNumber to set - */ - public void setCrypticCardNumber(String crypticCardNumber) - { - this.crypticCardNumber = crypticCardNumber; - } - /** * @return the expDateMonth */ @@ -98,15 +68,6 @@ public String getExpDateMonth() return expDateMonth; } - /** - * @param expDateMonth - * the expDateMonth to set - */ - public void setExpDateMonth(String expDateMonth) - { - this.expDateMonth = expDateMonth; - } - /** * @return the expDateYear */ @@ -115,19 +76,10 @@ public String getExpDateYear() return expDateYear; } - /** - * @param expDateYear - * the expDateYear to set - */ - public void setExpDateYear(String expDateYear) - { - this.expDateYear = expDateYear; - } - @Override public String toString() { - return String.format("CreditCard [fullName()=%s, cardNumber()=%s, expMonth()=%s, expYear()=%s]", - getFullName(), getCardNumber(), getExpDateMonth(), getExpDateYear()); + return String.format("CreditCard [fullName()=%s, cardNumber()=%s, crypticCardNumber()=%s, expMonth()=%s, expYear()=%s]", + getFullName(), getCardNumber(), getCrypticCardNumber(), getExpDateMonth(), getExpDateYear()); } } diff --git a/src/test/java/posters/dataobjects/Product.java b/src/test/java/posters/dataobjects/Product.java index baf5931..7f1c37b 100644 --- a/src/test/java/posters/dataobjects/Product.java +++ b/src/test/java/posters/dataobjects/Product.java @@ -1,6 +1,3 @@ -/** - * - */ package posters.dataobjects; import com.xceptance.neodymium.util.Neodymium; @@ -51,24 +48,6 @@ public String getName() return name; } - /** - * @param name - * the name to set - */ - public void setName(String name) - { - this.name = name; - } - - /** - * @param price - * the price to set - */ - public void setUnitPrice(String price) - { - this.unitPrice = price; - } - /** * @return the unitPrice */ @@ -85,15 +64,6 @@ public String getStyle() return style; } - /** - * @param style - * the style to set - */ - public void setStyle(String style) - { - this.style = style; - } - /** * @return the size */ @@ -102,15 +72,6 @@ public String getSize() return size; } - /** - * @param size - * the size to set - */ - public void setSize(String size) - { - this.size = size; - } - /** * @return the amount */ @@ -119,19 +80,10 @@ public int getAmount() return amount; } - /** - * @param amount - * the amount to set - */ - public void setAmount(int amount) - { - this.amount = amount; - } - @Override public String toString() { - return String.format("Product [name()=%s, size()=%s, style()=%s, price()=%s]", getName(), getSize(), getStyle(), getUnitPrice(), getAmount()); + return String.format("Product [name()=%s, size()=%s, style()=%s, price()=%s, amount()=%x]", getName(), getSize(), getStyle(), getUnitPrice(), getAmount()); } @Override diff --git a/src/test/java/posters/dataobjects/User.java b/src/test/java/posters/dataobjects/User.java index 93bda3d..fb90675 100644 --- a/src/test/java/posters/dataobjects/User.java +++ b/src/test/java/posters/dataobjects/User.java @@ -1,6 +1,3 @@ -/** - * - */ package posters.dataobjects; /** @@ -49,15 +46,6 @@ public String getFirstName() return firstName; } - /** - * @param firstName - * the firstName to set - */ - public void setFirstName(String firstName) - { - this.firstName = firstName; - } - /** * @return the lastName */ @@ -66,15 +54,6 @@ public String getLastName() return lastName; } - /** - * @param lastName - * the lastName to set - */ - public void setLastName(String lastName) - { - this.lastName = lastName; - } - /** * @return the email */ @@ -83,15 +62,6 @@ public String getEmail() return email; } - /** - * @param email - * the email to set - */ - public void setEmail(String email) - { - this.email = email; - } - /** * @return the password */ @@ -100,15 +70,6 @@ public String getPassword() return password; } - /** - * @param password - * the password to set - */ - public void setPassword(String password) - { - this.password = password; - } - @Override public String toString() { diff --git a/src/test/java/posters/pageobjects/components/AddressForm.java b/src/test/java/posters/pageobjects/components/AddressForm.java new file mode 100644 index 0000000..7c20d46 --- /dev/null +++ b/src/test/java/posters/pageobjects/components/AddressForm.java @@ -0,0 +1,113 @@ +package posters.pageobjects.components; + +import static com.codeborne.selenide.Condition.exactText; +import static com.codeborne.selenide.Condition.visible; +import static com.codeborne.selenide.Selenide.$; +import static com.codeborne.selenide.Selenide.$$; + +import com.codeborne.selenide.SelenideElement; +import com.xceptance.neodymium.util.Neodymium; + +import posters.dataobjects.Address; + +public class AddressForm extends AbstractComponent +{ + private final String title; + + private SelenideElement nameField = $("#fullName"); + + private SelenideElement companyField = $("#company"); + + private SelenideElement addressField = $("#addressLine"); + + private SelenideElement cityField = $("#city"); + + private SelenideElement stateField = $("#state"); + + private SelenideElement zipField = $("#zip"); + + private SelenideElement countryField = $("#country"); + + private SelenideElement continueButton = $("button.btn"); + + public AddressForm(String title) + { + this.title = title; + } + + public void isComponentAvailable() + { + nameField.shouldBe(visible); + zipField.shouldBe(visible); + } + + public void validateStructure() + { + $(".header-container>h2").shouldHave(exactText(title)); + + // Name + // Asserts the label next to the name field shows the right text + $("label[for='fullName']").shouldHave(exactText(Neodymium.localizedText("General.addresses.fullname"))); + // Asserts the name field is there + nameField.shouldBe(visible); + // Company + // Asserts the label next to the company field shows the right text + $("label[for='company']").shouldHave(exactText(Neodymium.localizedText("General.addresses.company"))); + // Asserts the company field is there + companyField.shouldBe(visible); + // Address + // Asserts the label next to the address field shows the right text + $("label[for='addressLine']").shouldHave(exactText(Neodymium.localizedText("General.addresses.address"))); + // Asserts the address field is there + addressField.shouldBe(visible); + // City + // Asserts the label next to the city field shows the right text + $("label[for='city']").shouldHave(exactText(Neodymium.localizedText("General.addresses.city"))); + // Asserts the city field is there + cityField.shouldBe(visible); + // State + // Asserts the label next to the state field shows the right text + $("label[for='state']").shouldHave(exactText(Neodymium.localizedText("General.addresses.state"))); + // Asserts the state field is there + stateField.shouldBe(visible); + // Zip + // Asserts the label next to the zip field shows the right text + $("label[for='zip']").shouldHave(exactText(Neodymium.localizedText("General.addresses.zip"))); + // Asserts the zip field is there + zipField.shouldBe(visible); + // Country + // Asserts the label next to the country field shows the right text + $("label[for='country']").shouldHave(exactText(Neodymium.localizedText("General.addresses.country"))); + // Asserts the country field is there + countryField.shouldBe(visible); + // Radio Button + // Assert the radio buttons are there + $$("input[name='billEqualShipp']").shouldHaveSize(2); + // Continue Button + // Asserts the Continue button is there + continueButton.shouldBe(visible); + } + + public void fillAddressForm(Address address) + { + // Enter the name parameter + nameField.val(address.getFirstName() + " " + address.getLastName()); + // Enter the company parameter + companyField.val(address.getCompany()); + // Enter the street parameter + addressField.val(address.getStreet()); + // Enter the city parameter + cityField.val(address.getCity()); + // Enter the state parameter + stateField.val(address.getState()); + // Enter the zip parameter + zipField.val(address.getZip()); + // Select the country whose label equals the parameter + countryField.selectOption(address.getCountry()); + } + + public void confirmAddressForm() + { + continueButton.click(); + } +} diff --git a/src/test/java/posters/pageobjects/components/CheckoutHeader.java b/src/test/java/posters/pageobjects/components/CheckoutHeader.java index 253e961..97dc196 100644 --- a/src/test/java/posters/pageobjects/components/CheckoutHeader.java +++ b/src/test/java/posters/pageobjects/components/CheckoutHeader.java @@ -1,6 +1,3 @@ -/** - * - */ package posters.pageobjects.components; import static com.codeborne.selenide.Condition.exist; diff --git a/src/test/java/posters/pageobjects/components/MiniCart.java b/src/test/java/posters/pageobjects/components/MiniCart.java index 2101231..0b2a1f7 100644 --- a/src/test/java/posters/pageobjects/components/MiniCart.java +++ b/src/test/java/posters/pageobjects/components/MiniCart.java @@ -1,6 +1,3 @@ -/** - * - */ package posters.pageobjects.components; import static com.codeborne.selenide.Condition.exactText; @@ -42,8 +39,8 @@ public void isComponentAvailable() @Step("open the mini cart") public void openMiniCart() { - // Click the mini cart icon - headerCart.scrollTo().click(); + // Hover over the cart icon + headerCart.hover(); // Wait for mini cart to appear // Wait for the mini cart to show miniCart.waitUntil(visible, Neodymium.configuration().selenideTimeout()); @@ -52,8 +49,6 @@ public void openMiniCart() @Step("close the mini cart") public void closeMiniCart() { - // Click the mini cart icon again - headerCart.scrollTo().click(); // Move the mouse out of the area $("#brand").hover(); // Wait for mini cart to disappear @@ -66,8 +61,9 @@ public CartPage openCartPage() { // Open the cart // Click on the button to go to the Cart - miniCart.find(".goToCart").scrollTo().click(); - return new CartPage(); + openMiniCart(); + miniCart.find(".goToCart").click(); + return new CartPage().isExpectedPage(); } @Step("get the total product count from mini cart") @@ -85,7 +81,6 @@ public void validateTotalCount(int totalCount) @Step("get the subtotal price from mini cart") public String getSubtotal() { - // Store the mini cart subtotal // Open mini cart openMiniCart(); @@ -104,7 +99,7 @@ public void validateSubtotal(String subtotal) // Open mini cart openMiniCart(); // Verify subtotal equals specified subtotal - // Compare the subTotal to the parameter + // Compare the subtotal to the parameter subOrderPrice.shouldHave(exactText(subtotal)); // Close Mini Cart closeMiniCart(); @@ -115,14 +110,14 @@ public void validateSubtotal(String subtotal) * @param product */ - @Step("validate \"{product}\" in the mini cart") + @Step("validate '{product}' in the mini cart") public void validateMiniCart(int position, Product product) { validateMiniCart(position, product.getName(), product.getStyle(), product.getSize(), product.getAmount(), PriceHelper.format(product.getTotalPrice())); } - @Step("validate \"{product}\" in the mini cart by name") + @Step("validate '{product}' in the mini cart by name") public void validateMiniCartByProduct(Product product) { SelenideElement productContainer = $$(".cartItems").filter(matchText(product.getCartRowRegex())).shouldHaveSize(1).first(); @@ -140,7 +135,7 @@ public void validateMiniCartByProduct(Product product) * @param productAmount * @param productTotalPrice */ - @Step("validate \"{product}\" in the mini cart") + @Step("validate '{product}' in the mini cart") public void validateMiniCart(int position, Product product, int productAmount, String productTotalPrice) { validateMiniCart(position, product.getName(), product.getStyle(), product.getSize(), productAmount, productTotalPrice); diff --git a/src/test/java/posters/pageobjects/components/Pagination.java b/src/test/java/posters/pageobjects/components/Pagination.java index 3272814..69ffddf 100644 --- a/src/test/java/posters/pageobjects/components/Pagination.java +++ b/src/test/java/posters/pageobjects/components/Pagination.java @@ -41,6 +41,6 @@ public CategoryPage clickOnRandomSite(Random random) chosenPaginationLink.scrollTo(); chosenPaginationLink.click(); - return new CategoryPage(); + return new CategoryPage().isExpectedPage(); } } diff --git a/src/test/java/posters/pageobjects/components/PaymentForm.java b/src/test/java/posters/pageobjects/components/PaymentForm.java new file mode 100644 index 0000000..6b3d548 --- /dev/null +++ b/src/test/java/posters/pageobjects/components/PaymentForm.java @@ -0,0 +1,58 @@ +package posters.pageobjects.components; + +import static com.codeborne.selenide.Condition.visible; + +import static com.codeborne.selenide.Selenide.$; + +import com.codeborne.selenide.SelenideElement; + +import io.qameta.allure.Step; +import posters.dataobjects.CreditCard; + +public class PaymentForm extends AbstractComponent +{ + private SelenideElement creditCardNumber = $("#creditCardNumber"); + + private SelenideElement creditCardName = $("#name"); + + private SelenideElement expirationMonth = $("#expirationDateMonth"); + + private SelenideElement expirationYear = $("#expirationDateYear"); + + private SelenideElement addPaymentButton = $("#btnAddPayment"); + + @Override + @Step("ensure payment form is available on the page") + public void isComponentAvailable() + { + creditCardNumber.shouldBe(visible); + } + + @Step("validate payment form structure") + public void validateStructure() + { + creditCardName.shouldBe(visible); + expirationMonth.shouldBe(visible); + expirationYear.shouldBe(visible); + addPaymentButton.shouldBe(visible); + } + + @Step("fill and send payment form") + public void sendPaymentForm(CreditCard card) + { + // Credit Card Number + // Fills the card number field with the parameter + creditCardNumber.val(card.getCardNumber()); + // Name + // Fills the card holder field with the parameter + creditCardName.val(card.getFullName()); + // Expiration + // Chooses the expiration month matching the parameter + expirationMonth.selectOption(card.getExpDateMonth()); + // Chooses the expiration year matching the parameter + expirationYear.selectOption(card.getExpDateYear()); + // Opens the order overview page + // Clicks the Continue button + addPaymentButton.scrollTo().click(); + } +} diff --git a/src/test/java/posters/pageobjects/components/Search.java b/src/test/java/posters/pageobjects/components/Search.java index dea7f79..95cce0a 100644 --- a/src/test/java/posters/pageobjects/components/Search.java +++ b/src/test/java/posters/pageobjects/components/Search.java @@ -20,21 +20,21 @@ public void isComponentAvailable() searchField.should(exist); } - @Step("search for \"{searchTerm}\" without result") + @Step("search for '{searchTerm}' without result") public NoHitsPage noResult(String searchTerm) { search(searchTerm); return new NoHitsPage(); } - @Step("search for \"{searchTerm}\" with result") + @Step("search for '{searchTerm}' with result") public CategoryPage categoryPageResult(String searchTerm) { search(searchTerm); - return new CategoryPage(); + return new CategoryPage().isExpectedPage(); } - @Step("search for \"{searchTerm}\"") + @Step("search for '{searchTerm}'") public void search(String searchTerm) { openSearch(); diff --git a/src/test/java/posters/pageobjects/components/SuccessMessage.java b/src/test/java/posters/pageobjects/components/SuccessMessage.java index 67abbe7..cd0047d 100644 --- a/src/test/java/posters/pageobjects/components/SuccessMessage.java +++ b/src/test/java/posters/pageobjects/components/SuccessMessage.java @@ -18,7 +18,7 @@ public void isComponentAvailable() successMessage.should(exist); } - @Step("validate that the success message \"{message}\" is visible") + @Step("validate that the success message '{message}' is visible") public void validateSuccessMessage(String message) { // Wait until javascript makes the success message visible diff --git a/src/test/java/posters/pageobjects/components/TopNavigation.java b/src/test/java/posters/pageobjects/components/TopNavigation.java index dc1236a..b9bfada 100644 --- a/src/test/java/posters/pageobjects/components/TopNavigation.java +++ b/src/test/java/posters/pageobjects/components/TopNavigation.java @@ -1,6 +1,3 @@ -/** - * - */ package posters.pageobjects.components; import static com.codeborne.selenide.Condition.exist; @@ -44,17 +41,17 @@ public CategoryPage clickSubCategoryByPosition(int categoryPosition, int subCate // Clicks the subcategory with position @{subCategoryPosition} // belonging to the category with position @{categoryPosition} topCat.find(".dropdown-menu a", subCategoryPosition - 1).click(); - return new CategoryPage(); + return new CategoryPage().isExpectedPage(); } - @Step("click on \"{categoryName}\" category") + @Step("click on '{categoryName}' category") public CategoryPage clickCategory(String categoryName) { $(By.linkText(categoryName)).scrollTo().click(); - return new CategoryPage(); + return new CategoryPage().isExpectedPage(); } - @Step("click on a \"{subCategoryName}\" subcategory within \"{categoryName}\"") + @Step("click on a '{subCategoryName}' subcategory within '{categoryName}'") public CategoryPage clickSubCategoryByNames(String categoryName, String subCategoryName) { // Open the category page @@ -69,13 +66,13 @@ public CategoryPage clickSubCategoryByNames(String categoryName, String subCateg * @param subCategoryName * @return */ - @Step("click on a product by name \"{productName}\"") + @Step("click on a product by name '{productName}'") public CategoryPage clickSubcategoryByName(String subCategoryName) { categoryMenu.find(".dropdown-menu li > a[title='" + subCategoryName + "']").parent().parent().parent().hover(); categoryMenu.find(By.linkText(subCategoryName)).click(); - return new CategoryPage(); + return new CategoryPage().isExpectedPage(); } @Step("get a random sub category name ") diff --git a/src/test/java/posters/pageobjects/components/UserMenu.java b/src/test/java/posters/pageobjects/components/UserMenu.java index 885611b..61070d5 100644 --- a/src/test/java/posters/pageobjects/components/UserMenu.java +++ b/src/test/java/posters/pageobjects/components/UserMenu.java @@ -1,6 +1,3 @@ -/** - * - */ package posters.pageobjects.components; import static com.codeborne.selenide.Condition.cssClass; @@ -60,7 +57,7 @@ public LoginPage openLogin() { openUserMenu(); userMenu.find(".goToLogin").scrollTo().click(); - return new LoginPage(); + return new LoginPage().isExpectedPage(); } @Step("open account page from user menu") @@ -68,7 +65,7 @@ public AccountOverviewPage openAccountOverview() { openUserMenu(); userMenu.find(".goToAccountOverview").scrollTo().click(); - return new AccountOverviewPage(); + return new AccountOverviewPage().isExpectedPage(); } @Step("open register page from user menu") @@ -76,13 +73,13 @@ public RegisterPage openRegister() { openUserMenu(); userMenu.find(".goToRegistration").scrollTo().click(); - return new RegisterPage(); + return new RegisterPage().isExpectedPage(); } /** * @param firstName */ - @Step("validate that \"{firstName}\" is logged in") + @Step("validate that '{firstName}' is logged in") public void validateLoggedInName(String firstName) { // Click on the mini user menu symbol diff --git a/src/test/java/posters/pageobjects/pages/AbstractPageObject.java b/src/test/java/posters/pageobjects/pages/AbstractPageObject.java index 1229a3e..8d38231 100644 --- a/src/test/java/posters/pageobjects/pages/AbstractPageObject.java +++ b/src/test/java/posters/pageobjects/pages/AbstractPageObject.java @@ -16,8 +16,9 @@ public abstract class AbstractPageObject { public Title title = new Title(); - public void isExpectedPage() + public AbstractPageObject isExpectedPage() { + return this; } abstract public void validateStructure(); diff --git a/src/test/java/posters/pageobjects/pages/browsing/AbstractBrowsingPage.java b/src/test/java/posters/pageobjects/pages/browsing/AbstractBrowsingPage.java index 1a4ddfe..55bc1d8 100644 --- a/src/test/java/posters/pageobjects/pages/browsing/AbstractBrowsingPage.java +++ b/src/test/java/posters/pageobjects/pages/browsing/AbstractBrowsingPage.java @@ -23,7 +23,7 @@ public abstract class AbstractBrowsingPage extends AbstractPageObject public TopNavigation topNav = new TopNavigation(); public UserMenu userMenu = new UserMenu(); - + public SuccessMessage successMessage = new SuccessMessage(); public ErrorMessage errorMessage = new ErrorMessage(); diff --git a/src/test/java/posters/pageobjects/pages/browsing/CategoryPage.java b/src/test/java/posters/pageobjects/pages/browsing/CategoryPage.java index 574b9d8..d9f1fd1 100644 --- a/src/test/java/posters/pageobjects/pages/browsing/CategoryPage.java +++ b/src/test/java/posters/pageobjects/pages/browsing/CategoryPage.java @@ -1,6 +1,3 @@ -/** - * - */ package posters.pageobjects.pages.browsing; import static com.codeborne.selenide.CollectionCondition.sizeGreaterThan; @@ -32,12 +29,14 @@ public class CategoryPage extends AbstractBrowsingPage @Override @Step("ensure this is a category page") - public void isExpectedPage() + public CategoryPage isExpectedPage() { + super.isExpectedPage(); productOverview.should(exist); + return this; } - @Step("validate category name \"{categoryName}\" on category page") + @Step("validate category name '{categoryName}' on category page") public void validateCategoryName(String categoryName) { // Category name @@ -65,13 +64,13 @@ public void validateStructure() * @return */ @Step("click on a product by position in grid") - public ProductdetailPage clickProductByPosition(int row, int column) + public ProductDetailPage clickProductByPosition(int row, int column) { // Open the product detail page // Clicks a product by position. Because of the html code, this requires x and y coordinates. SelenideElement rowContainer = $$("#productOverview > .row").get(row - 1); rowContainer.find(".thumbnail", column - 1).scrollTo().click(); - return new ProductdetailPage(); + return new ProductDetailPage().isExpectedPage(); } /** @@ -91,28 +90,28 @@ public String getProductNameByPosition(int row, int column) * @return */ @Step("click on a product by position") - public ProductdetailPage clickProductByPosition(int position) + public ProductDetailPage clickProductByPosition(int position) { final int index = position - 1; // Open the product detail page // Click on the product's image and open the product overview page // Click the product link to open the product detail page $("#product" + index + " img").scrollTo().click(); - return new ProductdetailPage(); + return new ProductDetailPage().isExpectedPage(); } /** * @param productName * @return */ - @Step("click on a product by name \"{productName}\"") - public ProductdetailPage clickProductByName(String productName) + @Step("click on a product by name '{productName}'") + public ProductDetailPage clickProductByName(String productName) { // Open the product detail page // Click on the product's image and open the product overview page // Click the product link to open the product detail page $("#productOverview .thumbnails .thumbnail a > img.pImage[title='" + productName + "']").scrollTo().click(); - return new ProductdetailPage(); + return new ProductDetailPage().isExpectedPage(); } /** @@ -131,7 +130,7 @@ public String getProductNameByPosition(int position) * @param searchTerm * @param searchTermExpectedCount */ - @Step("validate search results for \"{searchTerm}\" on category page") + @Step("validate search results for '{searchTerm}' on category page") public void validateSearchHits(String searchTerm, int searchTermExpectedCount) { $("#titleSearchText").should(exist); @@ -157,7 +156,7 @@ public void validateSearchHits(String searchTerm, int searchTermExpectedCount) /** * @param productName */ - @Step("validate product \"{productName}\" is visible on category page") + @Step("validate product '{productName}' is visible on category page") public void validateProductVisible(String productName) { $("#productOverview .thumbnails .thumbnail a > img.pImage[title='" + productName + "']").shouldBe(visible); @@ -166,7 +165,7 @@ public void validateProductVisible(String productName) /** * @param categoryName */ - @Step("validate category page of category \"{categoryName}\"") + @Step("validate category page of category '{categoryName}'") public void validate(String categoryName) { validateStructure(); @@ -176,7 +175,7 @@ public void validate(String categoryName) /** * @param categoryName */ - @Step("validate category page of category \"{categoryName}\" and assert visually") + @Step("validate category page of category '{categoryName}' and assert visually") public void validateAndVisualAssert(String categoryName) { validateStructureAndVisual(); diff --git a/src/test/java/posters/pageobjects/pages/browsing/HomePage.java b/src/test/java/posters/pageobjects/pages/browsing/HomePage.java index e6ea557..1f22965 100644 --- a/src/test/java/posters/pageobjects/pages/browsing/HomePage.java +++ b/src/test/java/posters/pageobjects/pages/browsing/HomePage.java @@ -17,9 +17,11 @@ public class HomePage extends AbstractBrowsingPage { @Override @Step("ensure this is a home page") - public void isExpectedPage() + public HomePage isExpectedPage() { + super.isExpectedPage(); $("#titleIndex").should(exist); + return this; } @Step("validate home page structure") @@ -99,11 +101,9 @@ public void validateAndVisualAssert() footer.validate(); } - public ProductdetailPage clickOnPresentedProduct(String productName) + public ProductDetailPage clickOnPresentedProduct(String productName) { $$("#productList .thumbnail .pName").filter(exactText(productName)).shouldHaveSize(1).first().click(); - ProductdetailPage productdetailPage = new ProductdetailPage(); - productdetailPage.isExpectedPage(); - return productdetailPage; + return new ProductDetailPage().isExpectedPage(); } } diff --git a/src/test/java/posters/pageobjects/pages/browsing/ProductdetailPage.java b/src/test/java/posters/pageobjects/pages/browsing/ProductDetailPage.java similarity index 91% rename from src/test/java/posters/pageobjects/pages/browsing/ProductdetailPage.java rename to src/test/java/posters/pageobjects/pages/browsing/ProductDetailPage.java index 4f198d8..3d64f0c 100644 --- a/src/test/java/posters/pageobjects/pages/browsing/ProductdetailPage.java +++ b/src/test/java/posters/pageobjects/pages/browsing/ProductDetailPage.java @@ -1,6 +1,3 @@ -/** - * - */ package posters.pageobjects.pages.browsing; import static com.codeborne.selenide.Condition.exactText; @@ -17,7 +14,7 @@ /** * @author pfotenhauer */ -public class ProductdetailPage extends AbstractBrowsingPage +public class ProductDetailPage extends AbstractBrowsingPage { private SelenideElement addToCartButton = $("#btnAddToCart"); @@ -29,9 +26,11 @@ public class ProductdetailPage extends AbstractBrowsingPage @Override @Step("ensure this is a product detail page") - public void isExpectedPage() + public ProductDetailPage isExpectedPage() { + super.isExpectedPage(); $("#addToCartForm").should(exist); + return this; } @Override @@ -82,7 +81,7 @@ public void addToCart() } - @Step("add product with size:\"{size}\" and style:\"{style}\" to cart") + @Step("add product with size:'{size}' and style:'{style}' to cart") public void addToCart(String size, String style) { // Style @@ -132,17 +131,17 @@ public Product getProduct() /** * @param productName */ - @Step("validate the product detail page of \"{productName}\"") + @Step("validate the product detail page of '{productName}'") public void validate(String productName) { validateStructure(); validateProductName(productName); - }; + } /** * @param productName */ - @Step("validate the product detail page of \"{productName}\" and assert visually") + @Step("validate the product detail page of '{productName}' and assert visually") public void validateAndVisualAssert(String productName) { validateStructureAndVisual(); diff --git a/src/test/java/posters/pageobjects/pages/checkout/AbstractCheckoutPage.java b/src/test/java/posters/pageobjects/pages/checkout/AbstractCheckoutPage.java index d6b616f..17d448d 100644 --- a/src/test/java/posters/pageobjects/pages/checkout/AbstractCheckoutPage.java +++ b/src/test/java/posters/pageobjects/pages/checkout/AbstractCheckoutPage.java @@ -1,6 +1,3 @@ -/** - * - */ package posters.pageobjects.pages.checkout; import posters.pageobjects.components.CheckoutHeader; diff --git a/src/test/java/posters/pageobjects/pages/checkout/BillingAddressPage.java b/src/test/java/posters/pageobjects/pages/checkout/BillingAddressPage.java index 29230c7..f784298 100644 --- a/src/test/java/posters/pageobjects/pages/checkout/BillingAddressPage.java +++ b/src/test/java/posters/pageobjects/pages/checkout/BillingAddressPage.java @@ -1,6 +1,3 @@ -/** - * - */ package posters.pageobjects.pages.checkout; import static com.codeborne.selenide.Condition.exist; @@ -9,8 +6,11 @@ import static com.codeborne.selenide.Selenide.$; import com.codeborne.selenide.SelenideElement; +import com.xceptance.neodymium.util.Neodymium; import io.qameta.allure.Step; +import posters.pageobjects.components.AddressForm; +import posters.dataobjects.Address; /** * @author pfotenhauer @@ -19,11 +19,14 @@ public class BillingAddressPage extends AbstractCheckoutPage { private SelenideElement headline = $("#titleBillAddr"); + private AddressForm billingAddressForm = new AddressForm(Neodymium.localizedText("CheckoutPages.billingAddressFormTitle")); + @Override @Step("ensure this is a billing address page") - public void isExpectedPage() + public BillingAddressPage isExpectedPage() { headline.should(exist); + return this; } @Override @@ -38,6 +41,7 @@ public void validateStructure() // First address // Makes sure at least one address is visible $("#billAddr0").shouldBe(visible); + billingAddressForm.isComponentAvailable(); } /** @@ -56,6 +60,18 @@ public PaymentPage selectBillingAddress(int position) // Clicks the continue button $("#btnUseBillAddress").scrollTo().click(); - return new PaymentPage(); + return new PaymentPage().isExpectedPage(); + } + + @Step("fill the billing address") + public PaymentPage fillBillingAddress(Address billingAddress) + { + // Fill billing address + billingAddressForm.fillAddressForm(billingAddress); + + // Send billing addresses by clicking the button Continue + $("#btnAddBillAddr").scrollTo().click(); + + return new PaymentPage().isExpectedPage(); } } diff --git a/src/test/java/posters/pageobjects/pages/checkout/CartPage.java b/src/test/java/posters/pageobjects/pages/checkout/CartPage.java index 6c72082..98cc3d8 100644 --- a/src/test/java/posters/pageobjects/pages/checkout/CartPage.java +++ b/src/test/java/posters/pageobjects/pages/checkout/CartPage.java @@ -1,6 +1,3 @@ -/** - * - */ package posters.pageobjects.pages.checkout; import static com.codeborne.selenide.Condition.exactText; @@ -22,7 +19,7 @@ import io.qameta.allure.Step; import posters.dataobjects.Product; import posters.pageobjects.pages.browsing.AbstractBrowsingPage; -import posters.pageobjects.pages.browsing.ProductdetailPage; +import posters.pageobjects.pages.browsing.ProductDetailPage; import posters.pageobjects.utility.PriceHelper; /** @@ -36,16 +33,17 @@ public class CartPage extends AbstractBrowsingPage @Override @Step("ensure this is a cart page") - public void isExpectedPage() + public CartPage isExpectedPage() { - cartTable.should(exist); + super.isExpectedPage(); + $("#titleCart").shouldBe(visible); + return this; } @Step("validate subtotal in the cart") public void validateSubtotal(String subtotal) { $$("#cartSummaryList li").findBy(text("Subtotal")).find(".text-right").shouldHave(exactText(subtotal)); - } @Override @@ -75,7 +73,6 @@ public void validateContainsProduct(Product product) { SelenideElement productContainer = $$("div.hidden-xs").filter((matchText(product.getRowRegex()))).shouldHaveSize(1).first() .parent().parent(); - productContainer.find(".productName").shouldHave(exactText(product.getName())); productContainer.find(".productSize").shouldHave(exactText(product.getSize())); productContainer.find(".productStyle").shouldHave(exactText(product.getStyle())); @@ -94,7 +91,7 @@ public void validateShippingCosts(String shippingCosts) /** * @param shippingCosts */ - @Step("validate cart page with shipping costs: \"{shippingCosts}\"") + @Step("validate cart page with shipping costs: '{shippingCosts}'") public void validate(String shippingCosts) { validateStructure(); @@ -105,7 +102,7 @@ public void validate(String shippingCosts) * @param position * @param product */ - @Step("validate \"{product}\" in on the cart page") + @Step("validate '{product}' in on the cart page") public void validateCartItem(int position, Product product) { validateCartItem(position, product.getName(), product.getStyle(), product.getSize(), product.getAmount(), @@ -117,7 +114,7 @@ public void validateCartItem(int position, Product product) * @param product * @param productAmount */ - @Step("validate \"{product}\" in on the cart page") + @Step("validate '{product}' in on the cart page") public void validateCartItem(int position, Product product, int productAmount) { validateCartItem(position, product.getName(), product.getStyle(), product.getSize(), @@ -229,7 +226,7 @@ public String getProductTotalUnitPrice(int position) public Product getProduct(int position) { return new Product(getProductName(position), getProductUnitPrice(position), getProductStyle(position), getProductSize(position), Integer.parseInt(getProductCount(position))); - }; + } /** * @param position @@ -314,10 +311,10 @@ public void validateSubAndLineItemTotalAfterRemove(String oldSubTotal, String ol * @param position */ @Step("click on a product on the cart page") - public ProductdetailPage openProductPage(int position) + public ProductDetailPage openProductPage(int position) { $("#product" + (position - 1) + " img").scrollTo().click(); - return new ProductdetailPage(); + return new ProductDetailPage().isExpectedPage(); } private void clickCheckoutButton() @@ -329,14 +326,14 @@ private void clickCheckoutButton() public NewShippingAddressPage openNewShippingPage() { clickCheckoutButton(); - return new NewShippingAddressPage(); + return new NewShippingAddressPage().isExpectedPage(); } @Step("open shipping address from the cart page") public ShippingAddressPage openShippingPage() { clickCheckoutButton(); - return new ShippingAddressPage(); + return new ShippingAddressPage().isExpectedPage(); } /** diff --git a/src/test/java/posters/pageobjects/pages/checkout/NewBillingAddressPage.java b/src/test/java/posters/pageobjects/pages/checkout/NewBillingAddressPage.java index 17aa1ad..dc1a7cc 100644 --- a/src/test/java/posters/pageobjects/pages/checkout/NewBillingAddressPage.java +++ b/src/test/java/posters/pageobjects/pages/checkout/NewBillingAddressPage.java @@ -1,12 +1,6 @@ -/** - * - */ package posters.pageobjects.pages.checkout; -import static com.codeborne.selenide.Condition.exactText; import static com.codeborne.selenide.Condition.exist; -import static com.codeborne.selenide.Condition.matchText; -import static com.codeborne.selenide.Condition.visible; import static com.codeborne.selenide.Selenide.$; import com.codeborne.selenide.SelenideElement; @@ -14,6 +8,7 @@ import io.qameta.allure.Step; import posters.dataobjects.Address; +import posters.pageobjects.components.AddressForm; /** * @author pfotenhauer @@ -22,27 +17,16 @@ public class NewBillingAddressPage extends AbstractCheckoutPage { private SelenideElement headline = $("#titleBillAddr"); - private SelenideElement nameField = $("#fullName"); - - private SelenideElement companyField = $("#company"); - - private SelenideElement addressField = $("#addressLine"); - - private SelenideElement cityField = $("#city"); - - private SelenideElement stateField = $("#state"); - - private SelenideElement zipField = $("#zip"); - - private SelenideElement countryField = $("#country"); - - private SelenideElement addBillingButton = $("#btnAddBillAddr"); + private AddressForm newBillingAddressForm = new AddressForm(Neodymium.localizedText("CheckoutPages.newBillingAddressFormTitle")); @Override @Step("ensure this is a new billing address page") - public void isExpectedPage() + public NewBillingAddressPage isExpectedPage() { + super.isExpectedPage(); headline.should(exist); + newBillingAddressForm.isComponentAvailable(); + return this; } @Override @@ -50,111 +34,20 @@ public void isExpectedPage() public void validateStructure() { super.validateStructure(); - - // Headline - // Assert the headline is there and starts with a capital letter - headline.should(matchText("[A-Z].{3,}")); - // Form - // Asserts the form is there at all - $("#formAddBillAddr").shouldBe(visible); - // Name - // Asserts the label next to the name field shows the right text - $("label[for=\"fullName\"]").shouldHave(exactText(Neodymium.localizedText("General.addresses.fullname"))); - // Asserts the name field is there - nameField.shouldBe(visible); - // Company - // Asserts the label next to the company field shows the right text - $("label[for=\"company\"]").shouldHave(exactText(Neodymium.localizedText("General.addresses.company"))); - // Asserts the company field is there - companyField.shouldBe(visible); - // Address - // Asserts the label next to the address field shows the right text - $("label[for=\"addressLine\"]").shouldHave(exactText(Neodymium.localizedText("General.addresses.address"))); - // Asserts the address field is there - addressField.shouldBe(visible); - // City - // Asserts the label next to the city field shows the right text - $("label[for=\"city\"]").shouldHave(exactText(Neodymium.localizedText("General.addresses.city"))); - // Asserts the city field is there - cityField.shouldBe(visible); - // State - // Asserts the label next to the state field shows the right text - $("label[for=\"state\"]").shouldHave(exactText(Neodymium.localizedText("General.addresses.state"))); - // Asserts the state field is there - stateField.shouldBe(visible); - // Zip - // Asserts the label next to the zip field shows the right text - $("label[for=\"zip\"]").shouldHave(exactText(Neodymium.localizedText("General.addresses.zip"))); - // Asserts the zip field is there - zipField.shouldBe(visible); - // Country - // Asserts the label next to the country field shows the right text - $("label[for=\"country\"]").shouldHave(exactText(Neodymium.localizedText("General.addresses.country"))); - // Asserts the country field is there - countryField.shouldBe(visible); - // Continue Button - // Asserts the Continue button is there - addBillingButton.shouldBe(visible); + newBillingAddressForm.validateStructure(); } /** * // * - * @param name - * First and last name you want to use // T - * @param company - * The company you want to use * @param address * The address you want to use - * @param city - * The City you want to use - * @param state - * The state you want to use - * @param zip - * The Zip you want to use, has to be in numbers format - * @param country - * The country you want to use, currently only United States or Germany */ @Step("fill and send new billing address form") - public NewPaymentPage sendBillingAddressForm(String name, String company, String address, String city, - String state, String zip, String country) - { - // Name - // Enter the name parameter - nameField.val(name); - // Company - // Enter the company parameter - companyField.val(company); - // Address - // Enter the address parameter - addressField.val(address); - // City - // Enter the city parameter - cityField.val(city); - // State - // Enter the state parameter - stateField.val(state); - // Zip - // Enter the zip parameter - zipField.val(zip); - // Country - // Select the country whose label equals the parameter - countryField.selectOption(country); - // Open the billing addresses or payment options page, depending on which radio button you checked - // Click on Continue - addBillingButton.scrollTo().click(); - - return new NewPaymentPage(); - } - - /** - * @param billingAddress - * @return - */ - public NewPaymentPage sendBillingAddressForm(Address billingAddress) + public NewPaymentPage sendBillingAddressForm(Address address) { - return sendBillingAddressForm(billingAddress.getFullName(), billingAddress.getCompany(), billingAddress.getAddressLine(), - billingAddress.getCity(), billingAddress.getState(), billingAddress.getZip(), - billingAddress.getCountry()); + newBillingAddressForm.fillAddressForm(address); + newBillingAddressForm.confirmAddressForm(); + return new NewPaymentPage().isExpectedPage(); } } diff --git a/src/test/java/posters/pageobjects/pages/checkout/NewPaymentPage.java b/src/test/java/posters/pageobjects/pages/checkout/NewPaymentPage.java index 81247aa..dcc58b0 100644 --- a/src/test/java/posters/pageobjects/pages/checkout/NewPaymentPage.java +++ b/src/test/java/posters/pageobjects/pages/checkout/NewPaymentPage.java @@ -1,19 +1,14 @@ -/** - * - */ package posters.pageobjects.pages.checkout; -import static com.codeborne.selenide.Condition.exactText; import static com.codeborne.selenide.Condition.exist; import static com.codeborne.selenide.Condition.matchText; -import static com.codeborne.selenide.Condition.visible; import static com.codeborne.selenide.Selenide.$; import com.codeborne.selenide.SelenideElement; -import com.xceptance.neodymium.util.Neodymium; import io.qameta.allure.Step; import posters.dataobjects.CreditCard; +import posters.pageobjects.components.PaymentForm; /** * @author pfotenhauer @@ -22,21 +17,15 @@ public class NewPaymentPage extends AbstractCheckoutPage { private SelenideElement headline = $("#titlePayment"); - private SelenideElement creditCardNumber = $("#creditCardNumber"); - - private SelenideElement creditCardName = $("#name"); - - private SelenideElement expirationMonth = $("#expirationDateMonth"); - - private SelenideElement expirationYear = $("#expirationDateYear"); - - private SelenideElement addPaymentButton = $("#btnAddPayment"); + private PaymentForm paymentForm = new PaymentForm(); @Override @Step("ensure this is a new payment page") - public void isExpectedPage() + public NewPaymentPage isExpectedPage() { + super.isExpectedPage(); headline.should(exist); + return this; } @Override @@ -51,65 +40,17 @@ public void validateStructure() // Form // Make sure the form is there to begin with $("#formAddPayment").should(exist); - // Credit Card Number - // Makes sure the label next to the card number field shows the correct text - $("label[for=\"creditCardNumber\"]").shouldHave(exactText(Neodymium.localizedText("General.payment.cardnumber"))); - // Makes sure the card number field is there - creditCardNumber.shouldBe(visible); - // Name - // Makes sure the label next to the card holder field shows the correct text - $("label[for=\"name\"]").shouldHave(exactText(Neodymium.localizedText("General.payment.cardholdername"))); - // Makes sure the card holder field is there - creditCardName.shouldBe(visible); - // Expiration - // Makes sure the label next to the expiration date fields shows the correct text - $("label[for=\"expirationDateMonth\"]").shouldHave(exactText(Neodymium.localizedText("General.payment.expirationdate"))); - // Makes sure the expiration month field is there - expirationMonth.shouldBe(visible); - // Makes sure the expiration year field is there - expirationYear.shouldBe(visible); - // Continue Button - // Makes sure the continue button is there - addPaymentButton.should(exist); - } - - /** - * @param number - * The credit card number, has to be 16 numbers - * @param name - * The full name - * @param month - * Expiration Month in numbers - * @param year - * Expiration year - */ - @Step("fill and send new payment form") - public PlaceOrderPage sendPaymentForm(String number, String name, String month, String year) - { - // Credit Card Number - // Fills the card number field with the parameter - creditCardNumber.val(number); - // Name - // Fills the card holder field with the parameter - creditCardName.val(name); - // Expiration - // Chooses the expiration month matching the parameter - expirationMonth.selectOption(month); - // Chooses the expiration year matching the parameter - expirationYear.selectOption(year); - // Opens the order overview page - // Clicks the Continue button - addPaymentButton.scrollTo().click(); - - return new PlaceOrderPage(); + paymentForm.validateStructure(); } /** * @param creditcard * @return */ - public PlaceOrderPage sendPaymentForm(CreditCard creditcard) + @Step("fill and send payment form") + public PlaceOrderPage sendPaymentForm(CreditCard card) { - return sendPaymentForm(creditcard.getCardNumber(), creditcard.getFullName(), creditcard.getExpDateMonth(), creditcard.getExpDateYear()); + paymentForm.sendPaymentForm(card); + return new PlaceOrderPage().isExpectedPage(); } } diff --git a/src/test/java/posters/pageobjects/pages/checkout/NewShippingAddressPage.java b/src/test/java/posters/pageobjects/pages/checkout/NewShippingAddressPage.java index 358a7b6..084e08d 100644 --- a/src/test/java/posters/pageobjects/pages/checkout/NewShippingAddressPage.java +++ b/src/test/java/posters/pageobjects/pages/checkout/NewShippingAddressPage.java @@ -1,20 +1,14 @@ -/** - * - */ package posters.pageobjects.pages.checkout; -import static com.codeborne.selenide.Condition.exactText; import static com.codeborne.selenide.Condition.exist; -import static com.codeborne.selenide.Condition.matchText; -import static com.codeborne.selenide.Condition.visible; import static com.codeborne.selenide.Selenide.$; -import static com.codeborne.selenide.Selenide.$$; import com.codeborne.selenide.SelenideElement; import com.xceptance.neodymium.util.Neodymium; import io.qameta.allure.Step; import posters.dataobjects.Address; +import posters.pageobjects.components.AddressForm; /** * @author pfotenhauer @@ -23,27 +17,16 @@ public class NewShippingAddressPage extends AbstractCheckoutPage { private SelenideElement headline = $("#titleDelAddr"); - private SelenideElement nameField = $("#fullName"); - - private SelenideElement companyField = $("#company"); - - private SelenideElement addressField = $("#addressLine"); - - private SelenideElement cityField = $("#city"); - - private SelenideElement stateField = $("#state"); - - private SelenideElement zipField = $("#zip"); - - private SelenideElement countryField = $("#country"); - - private SelenideElement addShippingButton = $("#btnAddDelAddr"); + private AddressForm newShippingAddressForm = new AddressForm(Neodymium.localizedText("CheckoutPages.newShippingAddressFormTitle")); @Override @Step("ensure this is a new shipping address page") - public void isExpectedPage() + public NewShippingAddressPage isExpectedPage() { + super.isExpectedPage(); headline.should(exist); + newShippingAddressForm.isComponentAvailable(); + return this; } @Override @@ -51,102 +34,22 @@ public void isExpectedPage() public void validateStructure() { super.validateStructure(); - - // Headline - // Assert the headline is there and starts with a capital letter - headline.should(matchText("[A-Z].{3,}")); - // Form - // Asserts the form is there at all - $("#formAddDelAddr").shouldBe(visible); - // Name - // Asserts the label next to the name field shows the right text - $("label[for=\"fullName\"]").shouldHave(exactText(Neodymium.localizedText("General.addresses.fullname"))); - // Asserts the name field is there - nameField.shouldBe(visible); - // Company - // Asserts the label next to the company field shows the right text - $("label[for=\"company\"]").shouldHave(exactText(Neodymium.localizedText("General.addresses.company"))); - // Asserts the company field is there - companyField.shouldBe(visible); - // Address - // Asserts the label next to the address field shows the right text - $("label[for=\"addressLine\"]").shouldHave(exactText(Neodymium.localizedText("General.addresses.address"))); - // Asserts the address field is there - addressField.shouldBe(visible); - // City - // Asserts the label next to the city field shows the right text - $("label[for=\"city\"]").shouldHave(exactText(Neodymium.localizedText("General.addresses.city"))); - // Asserts the city field is there - cityField.shouldBe(visible); - // State - // Asserts the label next to the state field shows the right text - $("label[for=\"state\"]").shouldHave(exactText(Neodymium.localizedText("General.addresses.state"))); - // Asserts the state field is there - stateField.shouldBe(visible); - // Zip - // Asserts the label next to the zip field shows the right text - $("label[for=\"zip\"]").shouldHave(exactText(Neodymium.localizedText("General.addresses.zip"))); - // Asserts the zip field is there - zipField.shouldBe(visible); - // Country - // Asserts the label next to the country field shows the right text - $("label[for=\"country\"]").shouldHave(exactText(Neodymium.localizedText("General.addresses.country"))); - // Asserts the country field is there - countryField.shouldBe(visible); - // Radio Button - // Assert the radio buttons are there - $$("input[name=\"billEqualShipp\"]").shouldHaveSize(2); - // Continue Button - // Asserts the Continue button is there - addShippingButton.shouldBe(visible); + newShippingAddressForm.validateStructure(); } /** * // * - * @param name - * First and last name you want to use // T - * @param company - * The company you want to use * @param address * The address you want to use - * @param city - * The City you want to use - * @param state - * The state you want to use - * @param zip - * The Zip you want to use, has to be in numbers format - * @param country - * The country you want to use, currently only United States or Germany * @param sameBillingAddress * Decision whether or not use the same billing address */ @Step("fill and send new shipping address form") - public NewBillingAddressPage sendShippingAddressForm(String name, String company, String address, String city, - String state, String zip, String country, boolean sameBillingAddress) + public NewBillingAddressPage sendShippingAddressForm(Address address, boolean sameBillingAddress) { - // Name - // Enter the name parameter - nameField.val(name); - // Company - // Enter the company parameter - companyField.val(company); - // Address - // Enter the address parameter - addressField.val(address); - // City - // Enter the city parameter - cityField.val(city); - // State - // Enter the state parameter - stateField.val(state); - // Zip - // Enter the zip parameter - zipField.val(zip); - // Country - // Select the country whose label equals the parameter - countryField.selectOption(country); - // Radio Button + newShippingAddressForm.fillAddressForm(address); + // Click the radio button for Yes or No if (sameBillingAddress) { @@ -158,20 +61,8 @@ public NewBillingAddressPage sendShippingAddressForm(String name, String company } // Open the billing addresses or payment options page, depending on which radio button you checked // Click on Continue - addShippingButton.scrollTo().click(); - - return new NewBillingAddressPage(); - } + newShippingAddressForm.confirmAddressForm(); - /** - * @param shippingAddress - * @param sameBillingAddress - * @return - */ - public NewBillingAddressPage sendShippingAddressForm(Address shippingAddress, boolean sameBillingAddress) - { - return sendShippingAddressForm(shippingAddress.getFullName(), shippingAddress.getCompany(), shippingAddress.getAddressLine(), - shippingAddress.getCity(), shippingAddress.getState(), shippingAddress.getZip(), - shippingAddress.getCountry(), sameBillingAddress); + return new NewBillingAddressPage().isExpectedPage(); } } diff --git a/src/test/java/posters/pageobjects/pages/checkout/PaymentPage.java b/src/test/java/posters/pageobjects/pages/checkout/PaymentPage.java index e719355..aa8f613 100644 --- a/src/test/java/posters/pageobjects/pages/checkout/PaymentPage.java +++ b/src/test/java/posters/pageobjects/pages/checkout/PaymentPage.java @@ -1,16 +1,14 @@ -/** - * - */ package posters.pageobjects.pages.checkout; import static com.codeborne.selenide.Condition.exist; import static com.codeborne.selenide.Condition.matchText; -import static com.codeborne.selenide.Condition.visible; import static com.codeborne.selenide.Selenide.$; import com.codeborne.selenide.SelenideElement; import io.qameta.allure.Step; +import posters.dataobjects.CreditCard; +import posters.pageobjects.components.PaymentForm; /** * @author pfotenhauer @@ -19,21 +17,15 @@ public class PaymentPage extends AbstractCheckoutPage { private SelenideElement headline = $("#titlePayment"); - private SelenideElement creditCardNumber = $("#creditCardNumber"); - - private SelenideElement creditCardName = $("#name"); - - private SelenideElement expirationMonth = $("#expirationDateMonth"); - - private SelenideElement expirationYear = $("#expirationDateYear"); - - private SelenideElement addPaymentButton = $("#btnAddPayment"); + private PaymentForm paymentForm = new PaymentForm(); @Override @Step("ensure this is a payment page") - public void isExpectedPage() + public PaymentPage isExpectedPage() { + super.isExpectedPage(); headline.should(exist); + return this; } @Override @@ -45,9 +37,7 @@ public void validateStructure() // Headline // Makes sure the headline is there and starts with a capital letter headline.should(matchText("[A-Z].{3,}")); - // First credit card - // Makes sure at least one credit card is saved - $("#payment0").shouldBe(visible); + paymentForm.validateStructure(); } /** @@ -66,27 +56,13 @@ public PlaceOrderPage selectCreditCard(int position) // Clicks the continue button $("#btnUsePayment").scrollTo().click(); - return new PlaceOrderPage(); + return new PlaceOrderPage().isExpectedPage(); } @Step("fill and send payment form") - public PlaceOrderPage sendPaymentForm(String number, String name, String month, String year) + public PlaceOrderPage sendPaymentForm(CreditCard card) { - // Credit Card Number - // Fills the card number field with the parameter - creditCardNumber.val(number); - // Name - // Fills the card holder field with the parameter - creditCardName.val(name); - // Expiration - // Chooses the expiration month matching the parameter - expirationMonth.selectOption(month); - // Chooses the expiration year matching the parameter - expirationYear.selectOption(year); - // Opens the order overview page - // Clicks the Continue button - addPaymentButton.scrollTo().click(); - - return new PlaceOrderPage(); + paymentForm.sendPaymentForm(card); + return new PlaceOrderPage().isExpectedPage(); } } diff --git a/src/test/java/posters/pageobjects/pages/checkout/PlaceOrderPage.java b/src/test/java/posters/pageobjects/pages/checkout/PlaceOrderPage.java index 4386026..d56ddde 100644 --- a/src/test/java/posters/pageobjects/pages/checkout/PlaceOrderPage.java +++ b/src/test/java/posters/pageobjects/pages/checkout/PlaceOrderPage.java @@ -1,6 +1,3 @@ -/** - * - */ package posters.pageobjects.pages.checkout; import static com.codeborne.selenide.Condition.exactText; @@ -27,9 +24,9 @@ public class PlaceOrderPage extends AbstractCheckoutPage { private SelenideElement headline = $("#titleOrderOverview"); - private SelenideElement shippingAddressForm = $("#shippingAddr"); + private SelenideElement shippingAddressContainer = $("#shippingAddr"); - private SelenideElement billingAddressForm = $("#billingAddr"); + private SelenideElement billingAddressContainer = $("#billingAddr"); private SelenideElement paymentForm = $("#payment"); @@ -37,9 +34,11 @@ public class PlaceOrderPage extends AbstractCheckoutPage @Override @Step("ensure this is a place order page") - public void isExpectedPage() + public PlaceOrderPage isExpectedPage() { + super.isExpectedPage(); headline.should(exist); + return this; } @Override @@ -51,8 +50,8 @@ public void validateStructure() // Headline // Headline is there and starts with a capital letter headline.should(matchText("[A-Z].{3,}")); - shippingAddressForm.shouldBe(visible); - billingAddressForm.shouldBe(visible); + shippingAddressContainer.shouldBe(visible); + billingAddressContainer.shouldBe(visible); paymentForm.shouldBe(visible); orderButton.shouldBe(visible); } @@ -61,7 +60,7 @@ public void validateStructure() * @param product * The product */ - @Step("validate order contains product \"{product.name}\"") + @Step("validate order contains product '{product.name}'") public void validateContainsProduct(Product product) { SelenideElement productContainer = $$("div.hidden-xs").filter((matchText(product.getRowRegex()))).shouldHaveSize(1).first() @@ -81,7 +80,7 @@ public void validateSubtotal(String subtotal) $$("#checkoutSummaryList li").findBy(text("Subtotal")).find(".text-right").shouldBe(exactText(subtotal)); } - @Step("validate product \"{productName}\" on place order page") + @Step("validate product '{productName}' on place order page") public void validateProduct(int position, String productName, int productCount, String productStyle, String productSize) { final int index = position - 1; @@ -107,49 +106,52 @@ public void validateProduct(int position, String productName, int productCount, public void validateAddressesAndPayment(Address shippingAddress, Address billingAddress, CreditCard creditcard) { // Shipping address - // Name - // Makes sure the shipping address name matches the parameter - shippingAddressForm.find(".name").shouldHave(exactText(shippingAddress.getFullName())); + // fullName + // Makes sure the shipping address fullName matches the parameter + String firstName = shippingAddress.getFirstName(); + String lastName = shippingAddress.getLastName(); + String fullName = firstName + " " + lastName; + shippingAddressContainer.find(".name").shouldHave(exactText(fullName)); // Company // Makes sure the shipping address company matches the parameter - shippingAddressForm.find(".company").shouldHave(exactText(shippingAddress.getCompany())); + shippingAddressContainer.find(".company").shouldHave(exactText(shippingAddress.getCompany())); // Address // Makes sure the shipping address matches the parameter - shippingAddressForm.find(".addressLine").shouldHave(exactText(shippingAddress.getAddressLine())); + shippingAddressContainer.find(".addressLine").shouldHave(exactText(shippingAddress.getStreet())); // City // Makes sure the shipping address city matches the parameter - shippingAddressForm.find(".city").shouldHave(exactText(shippingAddress.getCity())); + shippingAddressContainer.find(".city").shouldHave(exactText(shippingAddress.getCity())); // State // Makes sure the shipping address state matches the parameter - shippingAddressForm.find(".state").shouldHave(exactText(shippingAddress.getState())); + shippingAddressContainer.find(".state").shouldHave(exactText(shippingAddress.getState())); // ZIP // Makes sure the shipping address ZIP matches the parameter - shippingAddressForm.find(".zip").shouldHave(exactText(" " + shippingAddress.getZip())); + shippingAddressContainer.find(".zip").shouldHave(exactText(" " + shippingAddress.getZip())); // Country // Makes sure the shipping address country matches the parameter - shippingAddressForm.find(".country").shouldHave(exactText(shippingAddress.getCountry())); + shippingAddressContainer.find(".country").shouldHave(exactText(shippingAddress.getCountry())); // Billing address // Name // Makes sure the billing address name matches the parameter - billingAddressForm.find(".name").shouldHave(exactText(billingAddress.getFullName())); + billingAddressContainer.find(".name").shouldHave(exactText(fullName)); // Company // Makes sure the billing address company matches the parameter - billingAddressForm.find(".company").shouldHave(exactText(billingAddress.getCompany())); + billingAddressContainer.find(".company").shouldHave(exactText(billingAddress.getCompany())); // Address // Makes sure the billing address matches the parameter - billingAddressForm.find(".addressLine").shouldHave(exactText(billingAddress.getAddressLine())); + billingAddressContainer.find(".addressLine").shouldHave(exactText(billingAddress.getStreet())); // City // Makes sure the billing address city matches the parameter - billingAddressForm.find(".city").shouldHave(exactText(billingAddress.getCity())); + billingAddressContainer.find(".city").shouldHave(exactText(billingAddress.getCity())); // State // Makes sure the billing address state matches the parameter - billingAddressForm.find(".state").shouldHave(exactText(billingAddress.getState())); + billingAddressContainer.find(".state").shouldHave(exactText(billingAddress.getState())); // ZIP // Makes sure the billing address ZIP matches the parameter - billingAddressForm.find(".zip").shouldHave(exactText(billingAddress.getZip())); + billingAddressContainer.find(".zip").shouldHave(exactText(billingAddress.getZip())); // Country // Makes sure the billing address country matches the parameter - billingAddressForm.find(".country").shouldHave(exactText(billingAddress.getCountry())); + billingAddressContainer.find(".country").shouldHave(exactText(billingAddress.getCountry())); // Payment // Name // Makes sure the credit card holder matches the parameter @@ -177,6 +179,6 @@ public HomePage placeOrder() // Clicks the Order button orderButton.scrollTo().click(); - return new HomePage(); + return new HomePage().isExpectedPage(); } } diff --git a/src/test/java/posters/pageobjects/pages/checkout/ShippingAddressPage.java b/src/test/java/posters/pageobjects/pages/checkout/ShippingAddressPage.java index 2833013..d262a18 100644 --- a/src/test/java/posters/pageobjects/pages/checkout/ShippingAddressPage.java +++ b/src/test/java/posters/pageobjects/pages/checkout/ShippingAddressPage.java @@ -1,6 +1,3 @@ -/** - * - */ package posters.pageobjects.pages.checkout; import static com.codeborne.selenide.Condition.exist; @@ -9,8 +6,11 @@ import static com.codeborne.selenide.Selenide.$; import com.codeborne.selenide.SelenideElement; +import com.xceptance.neodymium.util.Neodymium; import io.qameta.allure.Step; +import posters.dataobjects.Address; +import posters.pageobjects.components.AddressForm; /** * @author pfotenhauer @@ -19,27 +19,15 @@ public class ShippingAddressPage extends AbstractCheckoutPage { private SelenideElement headline = $("#titleDelAddr"); - private SelenideElement nameField = $("#fullName"); - - private SelenideElement companyField = $("#company"); - - private SelenideElement addressField = $("#addressLine"); - - private SelenideElement cityField = $("#city"); - - private SelenideElement stateField = $("#state"); - - private SelenideElement zipField = $("#zip"); - - private SelenideElement countryField = $("#country"); - - private SelenideElement addShippingButton = $("#btnAddDelAddr"); + private AddressForm shippingAddressForm = new AddressForm(Neodymium.localizedText("CheckoutPages.shippingAddressFormTitle")); @Override @Step("ensure this is a shipping address page") - public void isExpectedPage() + public ShippingAddressPage isExpectedPage() { + super.isExpectedPage(); headline.should(exist); + return this; } @Override @@ -48,12 +36,11 @@ public void validateStructure() { super.validateStructure(); - // Headline // Assert the headline is there and starts with a capital letter headline.should(matchText("[A-Z].{3,}")); - // First address // Makes sure at least one address is visible $("#delAddr0").shouldBe(visible); + shippingAddressForm.isComponentAvailable(); } /** @@ -65,55 +52,42 @@ public void validateStructure() public BillingAddressPage selectShippingAddress(int position) { final int index = position - 1; - // Select address // Checks the radio button belonging to the delivery address with index @{index} $("#delAddr" + index + " input").scrollTo().click(); // Open the billing address page in the checkout process // Clicks the continue button $("#btnUseAddressContinue").scrollTo().click(); - return new BillingAddressPage(); + return new BillingAddressPage().isExpectedPage(); } - @Step("fill and send shipping address form") - public BillingAddressPage sendShippingAddressForm(String name, String company, String address, String city, - String state, String zip, String country, boolean sameBillingAddress) + @Step("fill and send shipping address without different billing address") + public PaymentPage fillShippingAddressWithSameAsBilling(Address shippingAddress) { - // Name - // Enter the name parameter - nameField.val(name); - // Company - // Enter the company parameter - companyField.val(company); - // Address - // Enter the address parameter - addressField.val(address); - // City - // Enter the city parameter - cityField.val(city); - // State - // Enter the state parameter - stateField.val(state); - // Zip - // Enter the zip parameter - zipField.val(zip); - // Country - // Select the country whose label equals the parameter - countryField.selectOption(country); - // Radio Button - // Click the radio button for Yes or No - if (sameBillingAddress) - { - $("#billEqualShipp-Yes").scrollTo().click(); - } - else - { - $("#billEqualShipp-No").scrollTo().click(); - } - // Open the billing addresses or payment options page, depending on which radio button you checked - // Click on Continue - addShippingButton.scrollTo().click(); - - return new BillingAddressPage(); + // Fill shipping address + shippingAddressForm.fillAddressForm(shippingAddress); + + // Click checkbox YES + $("#billEqualShipp-Yes").scrollTo().click(); + + // Send shipping addresses by clicking the button Continue + $("#btnAddDelAddr").scrollTo().click(); + + return new PaymentPage().isExpectedPage(); + } + + @Step("fill and send shipping address with different billing address") + public BillingAddressPage fillShippingAddressWithDifferentBilling(Address shippingAddress) + { + // Fill shipping address + shippingAddressForm.fillAddressForm(shippingAddress); + + // Click checkbox NO + $("#billEqualShipp-No").scrollTo().click(); + + // Send shipping addresses by clicking the button Continue + $("#btnAddDelAddr").scrollTo().click(); + + return new BillingAddressPage().isExpectedPage(); } } diff --git a/src/test/java/posters/pageobjects/pages/user/AccountOverviewPage.java b/src/test/java/posters/pageobjects/pages/user/AccountOverviewPage.java index 36994c3..1af8276 100644 --- a/src/test/java/posters/pageobjects/pages/user/AccountOverviewPage.java +++ b/src/test/java/posters/pageobjects/pages/user/AccountOverviewPage.java @@ -20,9 +20,11 @@ public class AccountOverviewPage extends AbstractBrowsingPage @Override @Step("ensure this is an account overview page") - public void isExpectedPage() + public AccountOverviewPage isExpectedPage() { + super.isExpectedPage(); headline.should(exist); + return this; } @Override @@ -57,12 +59,12 @@ public PersonalDataPage openPersonalData() // Open the personal data page // Click on the link to Personal Data personalDataLink.scrollTo().click(); - return new PersonalDataPage(); + return new PersonalDataPage().isExpectedPage(); } public OrderHistoryPage openOrderHistory() { $("#linkOrderOverview").scrollTo().click(); - return new OrderHistoryPage(); + return new OrderHistoryPage().isExpectedPage(); } } diff --git a/src/test/java/posters/pageobjects/pages/user/DeleteAccountPage.java b/src/test/java/posters/pageobjects/pages/user/DeleteAccountPage.java index 740499d..8178db7 100644 --- a/src/test/java/posters/pageobjects/pages/user/DeleteAccountPage.java +++ b/src/test/java/posters/pageobjects/pages/user/DeleteAccountPage.java @@ -1,6 +1,3 @@ -/** - * - */ package posters.pageobjects.pages.user; import static com.codeborne.selenide.Condition.exactText; @@ -29,9 +26,11 @@ public class DeleteAccountPage extends AbstractBrowsingPage @Override @Step("ensure this is a delete account page") - public void isExpectedPage() + public DeleteAccountPage isExpectedPage() { + super.isExpectedPage(); deleteForm.should(exist); + return this; } @Override @@ -45,7 +44,7 @@ public void validateStructure() deleteForm.find(".h2").should(matchText("[A-Z].{3,}")); // Password field // Asserts the label belonging to the password field displays the correct text - $("label[for=\"password\"]").shouldBe(exactText(Neodymium.localizedText("AccountPages.yourPassword"))); + $("label[for='password']").shouldBe(exactText(Neodymium.localizedText("AccountPages.yourPassword"))); // Asserts the field to enter your password is there passwordField.shouldBe(visible); // Button @@ -62,6 +61,6 @@ public HomePage deleteAccount(String password) // Delete account and open the homepage // click the confirmation button deleteButton.scrollTo().click(); - return new HomePage(); + return new HomePage().isExpectedPage(); } } diff --git a/src/test/java/posters/pageobjects/pages/user/LoginPage.java b/src/test/java/posters/pageobjects/pages/user/LoginPage.java index ff48f73..9070d4f 100644 --- a/src/test/java/posters/pageobjects/pages/user/LoginPage.java +++ b/src/test/java/posters/pageobjects/pages/user/LoginPage.java @@ -1,6 +1,3 @@ -/** - * - */ package posters.pageobjects.pages.user; import static com.codeborne.selenide.Condition.exactText; @@ -35,9 +32,11 @@ public class LoginPage extends AbstractBrowsingPage @Override @Step("ensure this is a login page") - public void isExpectedPage() + public LoginPage isExpectedPage() { + super.isExpectedPage(); loginForm.should(exist); + return this; } @Override @@ -94,7 +93,7 @@ public void sendFormWithData(String email, String password) public HomePage sendLoginform(String email, String password) { sendFormWithData(email, password); - return new HomePage(); + return new HomePage().isExpectedPage(); } /** @@ -114,7 +113,7 @@ public HomePage sendLoginform(User user) public LoginPage sendFalseLoginform(User user) { sendFormWithData(user.getEmail(), user.getPassword()); - return new LoginPage(); + return new LoginPage().isExpectedPage(); } /** @@ -124,7 +123,7 @@ public LoginPage sendFalseLoginform(User user) public RegisterPage openRegister() { registerLink.scrollTo().click(); - return new RegisterPage(); + return new RegisterPage().isExpectedPage(); } @Step("validate successful registration message") diff --git a/src/test/java/posters/pageobjects/pages/user/OrderHistoryPage.java b/src/test/java/posters/pageobjects/pages/user/OrderHistoryPage.java index e79a19b..cb7fd25 100644 --- a/src/test/java/posters/pageobjects/pages/user/OrderHistoryPage.java +++ b/src/test/java/posters/pageobjects/pages/user/OrderHistoryPage.java @@ -18,16 +18,18 @@ public class OrderHistoryPage extends AbstractBrowsingPage @Override @Step("ensure this is an order history page") - public void isExpectedPage() + public OrderHistoryPage isExpectedPage() { + super.isExpectedPage(); headline.should(exist); + return this; } @Step("validate product is in the order") public void validateContainsProduct(Product product) { - SelenideElement productContainer = $$(".productInfo").filter((matchText(product.getRowRegex()))).shouldHaveSize(1).first() - .parent(); + SelenideElement productContainer = $$(".productInfo").filter((matchText(product.getRowRegex()))) + .shouldHaveSize(1).first().parent(); productContainer.find(".productName").shouldBe(exactText(product.getName())); productContainer.find(".productStyle").shouldBe(exactText(product.getStyle())); diff --git a/src/test/java/posters/pageobjects/pages/user/PersonalDataPage.java b/src/test/java/posters/pageobjects/pages/user/PersonalDataPage.java index bdebae5..eea2048 100644 --- a/src/test/java/posters/pageobjects/pages/user/PersonalDataPage.java +++ b/src/test/java/posters/pageobjects/pages/user/PersonalDataPage.java @@ -1,6 +1,3 @@ -/** - * - */ package posters.pageobjects.pages.user; import static com.codeborne.selenide.Condition.exist; @@ -24,9 +21,11 @@ public class PersonalDataPage extends AbstractBrowsingPage @Override @Step("ensure this is a personal data page") - public void isExpectedPage() + public PersonalDataPage isExpectedPage() { + super.isExpectedPage(); headline.should(exist); + return this; } @Override @@ -56,6 +55,6 @@ public DeleteAccountPage openDeleteAccount() // Open the delete account page // Clicks the button to get to the Delete Account page deleteButton.scrollTo().click(); - return new DeleteAccountPage(); + return new DeleteAccountPage().isExpectedPage(); } } diff --git a/src/test/java/posters/pageobjects/pages/user/RegisterPage.java b/src/test/java/posters/pageobjects/pages/user/RegisterPage.java index 064340b..f4f3395 100644 --- a/src/test/java/posters/pageobjects/pages/user/RegisterPage.java +++ b/src/test/java/posters/pageobjects/pages/user/RegisterPage.java @@ -1,6 +1,3 @@ -/** - * - */ package posters.pageobjects.pages.user; import static com.codeborne.selenide.Condition.exactText; @@ -38,9 +35,11 @@ public class RegisterPage extends AbstractBrowsingPage @Override @Step("ensure this is a register page") - public void isExpectedPage() + public RegisterPage isExpectedPage() { + super.isExpectedPage(); registerForm.should(exist); + return this; } @Override @@ -54,23 +53,23 @@ public void validateStructure() registerForm.find(".h2").should(matchText("[A-Z].{3,}")); // Form // Asserts the label belonging to the last name field displays the correct text - $("label[for=\"lastName\"]").shouldHave(exactText(Neodymium.localizedText("AccountPages.lastname"))); + $("label[for='lastName']").shouldHave(exactText(Neodymium.localizedText("AccountPages.lastname"))); // Make sure the field to type in the last name is visible. lastnameField.shouldBe(visible); // Asserts the label belonging to the first name field displays the correct text - $("label[for=\"firstName\"]").shouldHave(exactText(Neodymium.localizedText("AccountPages.firstname"))); + $("label[for='firstName']").shouldHave(exactText(Neodymium.localizedText("AccountPages.firstname"))); // Make sure the field to type in the first name is visible. firstnameField.shouldBe(visible); // Asserts the label belonging to the email field displays the correct text - $("label[for=\"eMail\"]").shouldHave(exactText(Neodymium.localizedText("AccountPages.email"))); + $("label[for='eMail']").shouldHave(exactText(Neodymium.localizedText("AccountPages.email"))); // Make sure the field to type in the e-Mail is visible. emailField.shouldBe(visible); // Asserts the label belonging to the password field displays the correct text - $("label[for=\"password\"]").shouldHave(exactText(Neodymium.localizedText("AccountPages.password"))); + $("label[for='password']").shouldHave(exactText(Neodymium.localizedText("AccountPages.password"))); // Make sure the field to type in the password is visible. passwordField.shouldBe(visible); // Asserts the label belonging to the second password field displays the correct text - $("label[for=\"passwordAgain\"]").shouldHave(exactText(Neodymium.localizedText("AccountPages.passwordRepeat"))); + $("label[for='passwordAgain']").shouldHave(exactText(Neodymium.localizedText("AccountPages.passwordRepeat"))); // Make sure the field to type in the password again is visible. passwordRepeatField.shouldBe(visible); // Register button @@ -79,40 +78,27 @@ public void validateStructure() } /** - * @param eMail - * The email of the account you want to log into - * @param password - * The password of the account you want to log into + * @param user + * The User data of the account you want to log into */ @Step("fill and send register form") - public LoginPage sendRegisterForm(String firstName, String lastName, String eMail, String password, String passwordRepeat) + public LoginPage sendRegisterForm(User user) { // Fill out the registration form // Type the last name parameter into the last name field. - lastnameField.val(lastName); + lastnameField.val(user.getLastName()); // Type the first name parameter into the first name field. - firstnameField.val(firstName); + firstnameField.val(user.getFirstName()); // Type the email parameter into the email field. - emailField.val(eMail); + emailField.val(user.getEmail()); // Type the password parameter into the password field. - passwordField.val(password); + passwordField.val(user.getPassword()); // Type the second password parameter into the second password field. - passwordRepeatField.val(passwordRepeat); + passwordRepeatField.val(user.getPassword()); // Register and open the login page if successful // Click on the Register Button registerButton.scrollTo().click(); - return new LoginPage(); - } - - /** - * @param user - * @param passwordRepeat - * @return - */ - @Step("send register form for {user}") - public LoginPage sendRegisterForm(User user, String passwordRepeat) - { - return sendRegisterForm(user.getFirstName(), user.getLastName(), user.getEmail(), user.getPassword(), passwordRepeat); + return new LoginPage().isExpectedPage(); } } diff --git a/src/test/java/posters/pageobjects/utility/PriceHelper.java b/src/test/java/posters/pageobjects/utility/PriceHelper.java index 1bc6563..85f6692 100644 --- a/src/test/java/posters/pageobjects/utility/PriceHelper.java +++ b/src/test/java/posters/pageobjects/utility/PriceHelper.java @@ -1,6 +1,3 @@ -/** - * - */ package posters.pageobjects.utility; import java.text.DecimalFormat;