Automated Testing with Java, Selenium, and TestNG

Introduction

In this article, I will explore how to create a Java Maven project using Selenium and TestNG to automate testing on the ASOS website. This hands-on guide will help you demonstrate your proficiency in Java, Selenium, and TestNG by achieving specific tasks.

Prerequisites

Before diving into the implementation, ensure you have the following prerequisites set up:

  • Java Development Kit (JDK) installed.
  • Maven installed.
  • Integrated Development Environment (IDE) tool like IntelliJ or Eclipse
  • Basic understanding of Java, Selenium, and TestNG

In my previous articles, I have explained how to create a sample Maven Project by adding TestNG.

Setting Up the Project

  1. Create a Maven Project: Start by creating a new Maven project using your IDE. Here I use the Eclipse tool.
  2. Add Dependencies: Include the necessary dependencies for Selenium and TestNG in your pom.xml file.

Task Implementation

1. First, you have to create a Java class. Here I create a Java class, like “My store”

Automated Testing with Java, Selenium, and TestNG

2. Scripting the First Test Case: Asserting the "WOMEN" Category

In this task, we use Selenium's WebDriver to open the ASOS website and navigate to it. The TestNG @Test annotation is utilized for this purpose.

Then, we locate the "WOMEN" category element using XPath and assert that it is displayed on the page. To assert the presence of the "WOMEN" category, we need to locate the corresponding element on the ASOS website and verify its visibility.

Finally, we close the browser using driver.quit().

Automated Testing with Java, Selenium, and TestNG

3. Next, we test the search functionality. This not only evaluates the basic functionality but also demonstrates the ability to interact with dynamic elements.

This task involves locating the search input element on the ASOS website, entering the item name to be searched, and pressing the Enter key. Replace "your item name" with the actual item you want to search for.

Automated Testing with Java, Selenium, and TestNG

4. Next, let's run the script to navigate to the product page for the accessories, select item, select quantity, and add them to the shopping cart.

Automated Testing with Java, Selenium, and TestNG

5. Here, you need to locate the element that displays the title in the shopping cart and validate it.

Automated Testing with Java, Selenium, and TestNG

6. If you want to delete selected items from the cart, this task involves navigating to the shopping cart, identifying, and clicking on the delete button for each item to remove them all.

Automated Testing with Java, Selenium, and TestNG

Make sure to replace comments with the current code needed for each step. These examples are basic, and you might need to adjust them based on the current structure of the ASOS website and the elements you want to interact with.


Similar Articles