This is the test that implements our test case:
@Test
public void userCanPlaceOrderTest() throws InterruptedException {
HomePage homePage = new HomePage(driver);
homePage.open();
Assert.assertTrue(homePage.isDisplayed());
homePage.selectBooksCategory();
BooksPage booksPage = new BooksPage(driver);
Assert.assertTrue(booksPage.isDisplayed());
booksPage.changeProductsPerPageTo("12");
List<String> resultProductTitles = booksPage.getProductTitles();
booksPage.addProductsToCart();
booksPage.goToShoppingCart();
ShoppingCartPage shoppingCartPage = new ShoppingCartPage(driver);
Assert.assertTrue(shoppingCartPage.isDisplayed());
List<String> cartProductTitles = shoppingCartPage.getProductTitles();
Assert.assertEquals(resultProductTitles, cartProductTitles);
shoppingCartPage.agreeWithTermsAndConditions();
shoppingCartPage.proceedToCheckout();
CheckoutPage checkoutPage = new CheckoutPage(driver);
Assert.assertTrue(checkoutPage.isDisplayed());
checkoutPage.checkoutAsGuest();
checkoutPage.fillInPersonalInfo(FIRST_NAME,
LAST_NAME,
EMAIL,
PHONE_NUMBER);
checkoutPage.fillInBillingAddress(COUNTRY,
STATE,
CITY,
ADDRESS,
POSTAL_CODE);
checkoutPage.confirmBillingAddress();
checkoutPage.confirmShippingAddress();;
checkoutPage.selectShippingMethod();
checkoutPage.fillInPaymentInformation(CARD_TYPE,
CARDHOLDER_NAME,
CARDHOLDER_NUMBER,
CARD_CODE,
CARD_EXPIRY_MONTH,
CARD_EXPIRY_YEAR);
checkoutPage.confirmOrder();
OrderConfirmationPage confirmationPage = new OrderConfirmationPage(driver);
Assert.assertTrue(confirmationPage.isDisplayed());
String confirmationMessage = confirmationPage.getConfirmationMessage();
Assert.assertEquals(confirmationMessage, ORDER_CONFIRMATION);
}
The test uses multiple page classes, each being dedicated to the interaction with a specific site page.
What is next?
It is possible to improve the test and the page classes further so that:
the test is shorter
the site navigation is more clear
the page classes have much less code duplication
the page methods use less parameters
the test uses less assertions
the test uses less variables
What is next is the refactoring phase.