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

How can I use JavaScript to find a keyword on a webpage that is not located within an <a> tag or its href attribute?

I'm on a mission to locate a specific keyword within a webpage. Sounds simple, right? Well, here's the tricky part - I need to disregard any instances of this keyword that are nested within an <a> tag. For example: <p>Here is some s ...

When trying to access data within objects using JSON iteration, it may lead to encountering an issue of reading a

Attempting to retrieve specific data from a JSON file obtained from a website has proven challenging. While iterating through the collection of objects, undefined values are constantly encountered. Unfortunately, if the JSON is poorly structured, modificat ...

Incorporate distinct items into an array using reactjs

I'm facing an issue where clicking on a certain element multiple times adds it to my array multiple times. I need help in figuring out how to add only unique elements to the array. Can anyone offer some guidance? Thank you in advance. const handleCli ...

Displaying numbers as characters in AngularJS: Use $index variable

Within my ng-repeat, I have two <li> tags repeating a specific number of times. The $index is being used to determine the position of each <li>. You can view a sample on this fiddle: http://jsfiddle.net/sh0ber/cHQLH However, I would like one ...

Building a JavaScript application with Node.js and MySQL to seamlessly interact with both offline and online databases

As I develop a JavaScript web-app, my plan is to utilize Node.js for connecting the app with an existing MySQL database. My initial question pertains to the structure of the Node code: should it be written in the same .js file as my application or kept se ...

Fade the current Div out and fade in the following Div while also animating its child element

Looking to achieve a fade in and out effect for 3 divs, with the child element animating its way up from the bottom right once the divs have faded in. I've been working on it but haven't made much progress, does anyone have any ideas? Check out ...

I am facing an issue with my Angular 11 CLI application while trying to set it up with Jest. The specific error message I am encountering is: "TypeError: Cannot read property

Having issues with my Angular 11 cli app and Jest integration. Whenever I run npm run test, specifically jest --updateSnapshot, I encounter the following error in my terminal: Error: TypeError: Cannot read property 'paths' of undefined Here is ...

Displaying client-side filtered rows in a jqGrid with postData filter upon initial loading

Our website includes a jqGrid that initially retrieves its rows using the built-in ajax fetch feature, returning a json object. We then apply filtering and searching on the client side by creating custom functions to generate postData filters. However, we ...

Disable functionality not functioning properly on button attribute

I've created a demo on JSFiddle here: http://jsfiddle.net/qJdaA/2/. The goal of this code is to disable the button with the ID #monitor if no checkboxes are checked. var checked = $('#status_table tr [id^="monitor_"]:checked'); if (checked. ...

Struggling to create a BMI Calculator using JS, the result is consistently displaying as 'NaN'

Having trouble creating a BMI Calculator using JavaScript. The issue I'm facing is that the calculation always returns 'NaN'. I've tried using parseInt(), parseFloat(), and Number() but couldn't solve the problem. It seems that the ...

What could be the reason why both the add and remove functions are unable to work simultaneously within a JavaScript function?

Hi there! I recently started diving into JavaScript and encountered a little hiccup. I've been working on a dice game where images change randomly whenever a button is clicked. The images transition from one to another, but I wanted to add a rolling ...

Generating Unique Random Numbers with JavaScript

Is there a way to generate 5 unique random lottery numbers using JavaScript? I've been working on the code below, but can't seem to figure out how to ensure there are no duplicate numbers in the final selection. I tried adding conditionals and lo ...

Creating a CSS full-width navigation menu

Recently, I came across a menu code on the web that seemed great. However, I wanted to make my menu responsive and full width. Since I am new to CSS and HTML, adjusting the menu code has been a bit of a challenge for me. .menu, .menu ul { list-style: ...

Having difficulty generating a footer for a page that includes a Material-UI Drawer component

Looking to create a standard full-width footer at the bottom of my page, I need help with the implementation. Utilizing the "Permanent drawer" from Material-UI Drawer for reference here. If you're interested in experimenting with it, CodeSandbox link ...

Incorrect Results from Angular Code Coverage

Currently using Angular.js, Karma, Karma-coverage (Istanbul), and Jasmine for my stack. While conducting Code Coverage analysis on my app, I encountered an issue which leads to my question - Service A is showing up as covered by tests (in green) even thou ...

Are you struggling with Grails - Ajax submission not functioning properly?

Trying to update a div when a form is submitted, but it seems like something is missing. Here's the HTML code: <%@ page contentType="text/html;charset=UTF-8" %> <html> <head> <meta name="layout" content="main" /> ...

Having difficulty adding multiple items to the state array

I am currently working on a parent component that iterates over an array and passes props to a child component. In the child component (shown below), I have checkboxes with Font Awesome icons for users to mark their selections. When a user checks a box, I ...

What is the best way to showcase data from input fields within a bootstrap modal dialog?

After the user has entered their details and clicks submit, I would like to present the information in a Bootstrap modal with a confirmation button below. This serves as a preview of the data before it is saved to the database. Here's what I have so ...

Synk: the presence of a self-signed certificate within the certificate chain

Recently, I've been encountering the error message Synk Protect is showing "self-signed certificate in certificate chain" when I try to run npm install on a project of mine. Would appreciate any help or tips on how to identify which out of the 984 pac ...

Python script using Selenium has lost track of the number of elements within a specified range

I have a script that is intended to retrieve the HTML content of multiple pages on a website, exceeding a thousand in number. However, for some unknown reason, the script stops after a random number of page retrievals and proceeds to the next page without ...