Collection Uses In Automation Testing Framework With Scenarios

If you are going to attend any interview for the Automation testing role then there will be a common question waiting for you what are the various Collection Uses In the Automation Testing Framework explain with scenario.

Collection Uses In Automation Testing Framework

Then Here is the Answer. Please also add some more scenarios if you have:

List:

The list is used when we want to represent a group of individual objects as a single entity, where duplicates are allowed and insertion order must be preserved.

Scenario:

Finding all the links and finding all the requested tags are common examples where we can use List Interface. List Interface in Automation Testing is used with findelements() methods. findelements() methods return the list of Webelements.

List<WebElement> plants = driver.findElements(By.tagName("li"));
for (WebElement element : elements)
{
   System.out.println("Paragraph text:" + element.getText());
}

ArrayList:

ArrayList can be useful in scenarios where you need to manage a dynamic list of elements, such as storing test data, maintaining a list of elements to interact with on a webpage, or managing dynamic sets of parameters.

Scenario: Finding all the links and Storing the links for further actions.

Example:

// Find a collection of web elements using Selenium
List<WebElement> links = driver.findElements(By.tagName("a"));
 
// Store web elements in an ArrayList for further actions
ArrayList<WebElement> arrayListOfLinks = new ArrayList<>(links);

Vector:

Vector can be used when you need a thread-safe implementation of a list. where thread safety is a priority.

Scenario: A simple web application representing a shared shopping cart where multiple users can add and remove items concurrently. In this scenario, you might use Vector to ensure thread safety while accessing and modifying the shared shopping cart.

LinkedList:

LinkedList can be used where you need to efficiently manage a dynamic list of elements and frequently insert or remove items in the middle of the list.

Scenario:

Suppose you are testing the functionality of managing a booking queue for a travel agency’s website. The booking queue represents a list of pending bookings that need to be processed in the order they were received. You need to efficiently add new bookings to the queue and process them sequentially.

Using a LinkedList in this scenario allows for efficient insertion and removal of bookings from the queue. The sequential processing of bookings ensures that they are processed in the order they were received, which is essential for maintaining fairness and consistency in the booking system.

Map:

Map stores the data in Key and value format. In automation testing map can be used to pass the user data value for the login page or registration Page

For Example, we are passing the user details like name, e-mail, contact no etc in a data table in the feature file, while using the BDD Approach. Then in the step-definition file, we must convert the data table into Map and we can retrieve the values from the map.

HashMap

Scenario 1: Managing Shopping Cart Items
Consider a situation where you are automating tests for the shopping cart functionality of an e-commerce website. After adding items to the cart, you need to store and organize the items for further verification and validation.

Scenario 2: Managing Flight Search Results
Consider a situation where you are automating tests for the flight search functionality of a travel website. After performing a search for flights, you need to store and organize the search results for further verification and validation.

Hashtable

Scenario 1: Managing User Credentials
Consider a situation where you are automating tests for the user authentication functionality of an e-commerce website. You need to store and manage user credentials securely for various test scenarios.

Scenario 2: Managing Flight Booking Information
Consider a situation where you are automating tests for the flight booking functionality of a travel website. After successfully booking a flight, you need to store and manage booking information, such as the booking reference and passenger details, for various test scenarios.

LinkedHashMap

Scenario 1: Managing Hotel Booking History
Consider a situation where you are automating tests for the hotel booking functionality of a travel website. After booking hotels, you need to store and manage booking history, such as the booking date and hotel details, for various test scenarios.

Scenario 2: Managing Order Summary Details
Consider a situation where you are automating tests for the order placement functionality of an e-commerce website. After placing orders, you need to store and manage the order summary details, such as the product names and quantities, for various test scenarios.

TreeMap

Scenario 1: Sorting and Verifying Product Prices
Consider a situation where you are automating tests for the product listing functionality of an e-commerce website. After retrieving a list of products and their prices, you need to store and verify the prices in sorted order.

Scenario 2: Managing and Verifying Flight Schedules
Consider a situation where you are automating tests for the flight schedule functionality of a travel application. After retrieving flight schedules for different routes, you need to store and verify the schedules based on departure times.

Set :

Duplicates are not allowed in the set. So it will store unique elements. Mainly used for Searching Operations.

The most common use of Set Interface is to handle all opened windows which are the child windows by web driver. To handle we use the getWindowHandles( ) method which returns the Set of String. By iterating through this set, we can identify and store the handles of all currently open windows.

// getWindowHandle method to get ID of new window (child window)
Set<String> Child_id = driver.getWindowHandles();
 
// for each loop
for (String a : Child_id) 
{
	// it will print IDs of both window
	System.out.println(a);
}

Queue:

Queue Interface is used when we want to do some kind of operation in FIFO form, Like Sending a message to 10 Persons as per the sheet order.
Example:

  • When we want to send the mail to all Tester’s mailid available in excel sheet.
  • When we want to update the Excel sheet data cell-wise.

The addition of more examples will be appreciated.

I love open-source technologies and am very passionate about software development. I like to share my knowledge with others, especially on technology that's why I have given all the examples as simple as possible to understand for beginners. All the code posted on my blog is developed, compiled, and tested in my development environment. If you find any mistakes or bugs, Please drop an email to softwaretestingo.com@gmail.com, or You can join me on Linkedin.

Leave a Comment