A guide on implementing multiline properties in a property file for Selenium WebDriver

At the moment, I am focusing on utilizing Selenium WebDriver with code that is developed in Java.

In the snippet below, I have successfully verified if the dropdown values match the UI for one dropdown. Now, I aim to extend this capability to check multiple dropdown options sequentially.

The property file contains the dropdown options as follows: visualizationId=Day,Week,Month,Quarter,Semester,Year,RD Tech Group,ICC,Center,Software Pack,Product,Project,Customer PRs,Severity,Priority

This code effectively confirms whether these options are available in the UI.

If there are many entries like visualizationId=Day,Week,Month,Quarter,Semester,Year,RD Tech Group,ICC,Center,Software Pack,Product,Project,Customer PRs,Severity,Priority

periodId=Last 4 Weeks,Last 52 Weeks,Date Range,Week Range,Month Range,Year To Date

I am looking to perform the same validation process for all of them.

The Code implementation for this scenario is shown below:

@Test()
public void Filterselection_1() throws Exception{

BufferedReader in = new BufferedReader(new FileReader("C:\\FilterSection\\visualization.txt"));
String line;
line = in.readLine();
in.close();

String[] expectedDropDownItemsInArray = line.split("=")[1].split(",");

// Create expected list :: This will contain expected drop-down values
ArrayList<String> expectedDropDownItems = new ArrayList<String>();
for(int i=0; i<expectedDropDownItemsInArray.length; i++)
    expectedDropDownItems.add(expectedDropDownItemsInArray[i]);
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("document.getElementById('visualizationId').style.display='block';");

// Create a webelement for the drop-down
WebElement visualizationDropDownElement = driver.findElement(By.id("visualizationId"));

// Instantiate Select class with the drop-down webelement
Select visualizationDropDown = new Select(visualizationDropDownElement);

// Retrieve all drop-down values and store in actual list
List<WebElement> valuesUnderVisualizationDropDown  = visualizationDropDown.getOptions();

List<String> actualDropDownItems = new ArrayList<String>();

for(WebElement value : valuesUnderVisualizationDropDown){
    actualDropDownItems.add(value.getText());
}

// Print expected and actual list
System.out.println("expectedDropDownItems : " +expectedDropDownItems);       
System.out.println("actualDropDownItems : " +actualDropDownItems);

// Verify both the lists having same size
if(actualDropDownItems.size() != expectedDropDownItems.size())
  System.out.println("Property file is NOT updated with the drop-down values");

// Compare expected and actual list
for (int i = 0; i < actualDropDownItems.size(); i++) {
    if (!expectedDropDownItems.get(i).equals(actualDropDownItems.get(i)))
    System.out.println("Drop-down values are NOT in correct order");

}

String[] expectedDropDownItemsInArray1 = line.split("=")[1].split(",");

// Create expected list :: This will contain expected drop-down values

ArrayList<String> expectedDropDownItems1 = new ArrayList<String>();
for(int i=0; i<expectedDropDownItemsInArray1.length; i++)
    expectedDropDownItems1.add(expectedDropDownItemsInArray1[i]);// Same VisualizationId values it is taking but it need to take 2nd i.e PeriodId drop down and it need to check

JavascriptExecutor executor1 = (JavascriptExecutor)driver;
executor1.executeScript("document.getElementById('periodId').style.display='block';");

// Create a webelement for the drop-down
WebElement periodDropDownElement = driver.findElement(By.id("periodId"));

// Instantiate Select class with the drop-down webelement
Select periodDropDown = new Select(periodDropDownElement);

// Retrieve all drop-down values and store in actual list
List<WebElement> valuesUnderPeriodDropDown  = periodDropDown.getOptions();

List<String> actualDropDownItems1 = new ArrayList<String>();

for(WebElement value : valuesUnderPeriodDropDown){
    actualDropDownItems1.add(value.getText());
}

// Print expected and actual list
System.out.println("expectedDropDownItems : " +expectedDropDownItems1);       
System.out.println("actualDropDownItems : " +actualDropDownItems1);

// Verify both the lists having same size
if(actualDropDownItems1.size() != expectedDropDownItems1.size())
  System.out.println("Property file is NOT updated with the drop-down values");

// Compare expected and actual list
for (int i = 0; i < actualDropDownItems1.size(); i++) {
    if (!expectedDropDownItems1.get(i).equals(actualDropDownItems1.get(i)))
    System.out.println("Drop-down values are NOT in correct order");

}   

}

Answer №1

Below is an example of how the visualization.properties file should be structured:

The properties file consists of two main components: property name and property value. In the visualization.properties file, visualizationId and periodId serve as the property names with their corresponding values assigned using the = operator.

To update your existing code to read dropdown values from the visualization.properties file:

public void Filterselection_1() throws Exception{

Properties APPTEXT = new Properties();
FileInputStream fs = new FileInputStream("C:\\FilterSection\\visualization.properties");
APPTEXT.load(fs);
String[] expectedDropDownItemsInArray = APPTEXT.getProperty("visualizationId").trim().split(",");

// Create expected list :: This will contain expected drop-down values
ArrayList<String> expectedDropDownItems = new ArrayList<String>();
for(int i=0; i<expectedDropDownItemsInArray.length; i++)
    expectedDropDownItems.add(expectedDropDownItemsInArray[i]);
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("document.getElementById('visualizationId').style.display='block';");

// Create a webelement for the drop-down
WebElement visualizationDropDownElement = driver.findElement(By.id("visualizationId"));

// Instantiate Select class with the drop-down webelement
Select visualizationDropDown = new Select(visualizationDropDownElement);

// Retrieve all drop-down values and store in actual list
List<WebElement> valuesUnderVisualizationDropDown  = visualizationDropDown.getOptions();

List<String> actualDropDownItems = new ArrayList<String>();

for(WebElement value : valuesUnderVisualizationDropDown){
    actualDropDownItems.add(value.getText());
}

// Print expected and actual list
System.out.println("expectedDropDownItems : " +expectedDropDownItems);       
System.out.println("actualDropDownItems : " +actualDropDownItems);

// Verify both the lists having same size
if(actualDropDownItems.size() != expectedDropDownItems.size())
  System.out.println("Property file is NOT updated with the drop-down values");

// Compare expected and actual list
for (int i = 0; i < actualDropDownItems.size(); i++) {
    if (!expectedDropDownItems.get(i).equals(actualDropDownItems.get(i)))
    System.out.println("Drop-down values are NOT in correct order");

}

Note :

APPTEXT.getProperty("visualizationId")
will return Day,Week,Month,Quarter,Semester,Year,RD Tech Group,ICC,Center,Software Pack,Product,Project,Customer PRs,Severity,Priority value.


To obtain the value corresponding to periodId, use - APPTEXT.getProperty("periodId")

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the method to gather logs with a Warning level in Python?

Recently, I encountered an issue with my code where it was supposed to collect 3 log files with loglevel Warning, but instead, it collected 25 files with level info. I'm puzzled by how this happened and where I went wrong. mail_url = 'https://ma ...

Bootstrap table malfunctioning following completion of ajax request

I am currently facing an issue with my ajax call in my MVC project. Whenever the user clicks on a value using the select, it updates two tables in the project. However, I have noticed that on every other call, the button functionality on the tables breaks. ...

Having trouble populating the container with page content using AJAX, PHP, and JS?

Whenever I attempt to use the buttons to change the content, I keep receiving a 'There is no such page!' message. Below is the index.html: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- ...

Ways to retrieve and upload a blob from a file object

After receiving a file object via an HTML input on-change event in my component.html: onFileSelected(event) { this.selectedFile = event.target.files[0]; } Now, I need to send a POST request to upload the image to the database. The database only acc ...

Expo + tRPC: Oops! Looks like the application context couldn't be retrieved. Don't forget to wrap your App inside the `withTRPC` HoC for

I'm currently working on a straightforward tRPC server setup: // server.ts import { initTRPC } from "@trpc/server"; import { z } from "zod"; const t = initTRPC.create(); export const appRouter = t.router({ greeting: t.procedu ...

Passing parameters to an Angular 2 component

When it comes to passing a string parameter to my component, I need the flexibility to adjust the parameters of services based on the passed value. Here's how I handle it: In my index.html, I simply call my component and pass the required parameter. ...

What is the correct way to implement Axios interceptor in TypeScript?

I have implemented an axios interceptor: instance.interceptors.response.use(async (response) => { return response.data; }, (err) => { return Promise.reject(err); }); This interceptor retrieves the data property from the response. The re ...

Modify the `value` of the `<input type=color>` element

Hello there! I have been working on a feature where I need users to select a color and have that choice reflected in the value field. Initially, I assumed this could be achieved easily through Bootstrap's features since my project is based on Bootstr ...

Error: module 'next/react' not found

Recently delving into next.js, I encountered an error after creating a project with npx create-next-app. Oddly enough, the app still runs despite this issue. { "resource": "/E:/codes/news-website/news-website/pages/index.js", ...

Choosing between exclusive choices across multiple selection elements in Vue 3

In my Vue component, there are 5 distinct values stored in the options variable. I want users to select only one value from each of the 5 select options I provide. This means that once a user selects a value in one input select component, that same value c ...

Keying objects based on the values of an array

Given the array: const arr = ['foo', 'bar', 'bax']; I am looking to create an object using the array entries: const obj = { foo: true, bar: true, bax: false, fax: true, // TypeScript should display an error here becau ...

Using jQuery to append content with a variable as the source

Recently delving into jQuery and encountering an issue with getting my variable inside src when using append. Either it's not functional at all, or just displaying the variable name in string form in the console. Here is the code causing trouble: va ...

Clicking the search result that matches in Selenium using C#

When searching on YouTube, I want to be able to click on the video associated with a specific channel name. However, even when the channel matches, I am unable to click on the video itself. I need assistance in having the video open when the channel name ...

Customizing the default settings of a d3 funnel chart

I recently used the following link to create a funnel chart using D3: jakezatecky/d3-funnel Everything was working perfectly. However, I wanted to adjust the block heights in proportion to their weight as mentioned in the tutorial by changing the D3 defau ...

Monochrome Effect Triggered by Cursor Hover

I'm attempting to use Javascript with HTML5 canvas to convert an image to greyscale, but I seem to be missing something in my code. Can anyone spot the error? I feel like I'm very close! function grayscaleConversion(str) { // Access the Canv ...

Refreshing a page following an AJAX request made with jQuery

I am working on a JSP page that shows student details. When a student is selected from the dropdown box, it triggers an onchange event to retrieve the minimum and maximum marks for that student. <form name="listBean"> <c:forEach var="Item" i ...

Using a function as an argument within an Angular directive

Looking for a solution to pass a promise-returning function into a directive? Here's what I'm currently doing: In the parent controller, I've created a callback: $scope.myCb = function(data) { console.log(data); } Directive Scope: sco ...

Attempting to create a login and registration form

Hello, I am attempting to create a form that can generate new user accounts and passwords. These values should be stored from the input tag when the user clicks on the register button. Unfortunately, I am encountering an issue where clicking the register ...

Measuring Euler Angles with 9-Axis Analog Sensor Data

I am trying to calculate Euler angles using analog sensor data in JavaScript. The sensor data consists of gyro, accelerometer, and magnetometer readings in three dimensions. I find the mathematical aspect a bit challenging, so any assistance or advice woul ...

It seems that BeautifulSoup and Selenium are unable to locate the div or text elements on the website

I have been attempting to utilize BeautifulSoup or Selenium in order to retrieve the Head to Head text or its corresponding div element on betexplorer (link provided below), but my efforts have unfortunately proved to be unsuccessful. Despite being able to ...