0% found this document useful (0 votes)
10 views7 pages

Se2 Exp8

The document outlines an experiment aimed at automating web browser interactions using Selenium, detailing its components such as WebDriver, IDE, and Grid. It provides a code example for a property management test, demonstrating tasks like form submission and data entry. The conclusion emphasizes Selenium's effectiveness for web automation and testing, highlighting its cross-browser support and integration capabilities.

Uploaded by

dmsuhagiyab22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views7 pages

Se2 Exp8

The document outlines an experiment aimed at automating web browser interactions using Selenium, detailing its components such as WebDriver, IDE, and Grid. It provides a code example for a property management test, demonstrating tasks like form submission and data entry. The conclusion emphasizes Selenium's effectiveness for web automation and testing, highlighting its cross-browser support and integration capabilities.

Uploaded by

dmsuhagiyab22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Denish Suhagiya

Reg No - 221070071
Experiment - 8

Aim:

To automate web browser interactions using Selenium for tasks such as form
submission, web scraping, testing web applications, and validating UI behavior.

Theory:

Selenium is an open-source automation tool used for controlling web browsers through
programs and performing browser-based automation. It supports various programming
languages like Python, Java, C#, and JavaScript and is compatible with major browsers
such as Chrome, Firefox, Safari, and Edge.

Selenium primarily consists of the following components:

1.​ Selenium WebDriver – Provides APIs to interact with web elements and control
the browser programmatically.​

2.​ Selenium IDE – A browser extension for record-and-playback of interactions with


the browser.​

3.​ Selenium Grid – Used to run tests on different machines and browsers in
parallel.​

Key functionalities include:

●​ Locating elements using XPath, CSS selectors, IDs, etc.​

●​ Performing actions like click, send keys, drag and drop.​

●​ Managing waits, handling alerts, switching between windows and frames.​

By automating repetitive tasks, Selenium enhances testing efficiency, ensures better


test coverage, and enables continuous integration workflows in software development.
Denish Suhagiya
Reg No - 221070071

Code -

const { Builder, By, until, Key } = require("selenium-webdriver");​


const fs = require("fs");​
const path = require("path");​

// Main test function that runs all property management tests​
(async function adminPropertyManagementTest() {​
// Initialize the WebDriver​
let driver = await new Builder().forBrowser("chrome").build();​

try {​
console.log("Starting comprehensive admin property management test...");​

// Login process​
await driver.get("http://localhost:3000/login");​
console.log("Navigated to login page");​
await driver.sleep(2000);​

// Login form elements​
let emailInput = await findElement(driver, [​
By.css('input[type="email"]'),​
By.id("email"),​
]);​
await emailInput.sendKeys("[email protected]");​
console.log("Email entered");​

let passwordInput = await findElement(driver, [​
By.css('input[type="password"]'),​
By.id("password"),​
]);​
await passwordInput.sendKeys("Hartik@123");​
console.log("Password entered");​

let loginButton = await findElement(driver, [​
By.css('button[type="submit"]'),​
By.xpath('//button[contains(text(), "Login")]'),​
]);​
await loginButton.click();​
console.log("Login button clicked");​
await driver.sleep(2000);​

// Navigate to Dashboard​
console.log("Navigating to Admin Dashboard...");​
Denish Suhagiya
Reg No - 221070071

let dashboardLink = await findElement(driver, [​


By.linkText("Dashboard"),​
By.partialLinkText("Dashboard"),​
By.css('a[href*="Dashboard"]'),​
]);​
await dashboardLink.click();​
console.log("Clicked on Dashboard");​
await driver.sleep(2000);​

// ====== PROPERTY ADDITION TEST ======​
console.log("\n=== STARTING PROPERTY ADDITION TEST ===\n");​

// Navigate to List Property page​
let listPropertyLink = await findElement(driver, [​
By.linkText("List Property"),​
By.partialLinkText("List Property"),​
By.css('a[href*="property"]'),​
]);​
await listPropertyLink.click();​
console.log("Navigated to property listing section");​
await driver.sleep(2000);​

// Generate a unique property name using timestamp​
const timestamp = new Date().getTime();​
const uniquePropertyName = `Test Property ${timestamp}`;​

// Fill out property form​
console.log("Filling out property form with test data...");​

// Property Name​
const nameField = await findElement(driver, [​
By.id("name"),​
By.css('input[placeholder*="product name" i]'),​
]);​
await nameField.clear();​
await nameField.sendKeys(uniquePropertyName);​
console.log(`Property name entered: ${uniquePropertyName}`);​

// Location​
const locationField = await findElement(driver, [​
By.id("brand"),​
By.css('input[placeholder*="Product brand" i]'),​
]);​
await locationField.clear();​
await locationField.sendKeys("Mumbai");​
Denish Suhagiya
Reg No - 221070071

console.log("Location entered");​

// Property Tags​
const tagsField = await findElement(driver, [​
By.css('input[placeholder*="Product Tags" i]'),​
]);​
await tagsField.clear();​
await tagsField.sendKeys("Furnished");​
console.log("Tags entered");​

// BHK​
const bhksField = await findElement(driver, [​
By.css('input[placeholder*="Product Bhks" i]'),​
]);​
await bhksField.clear();​
await bhksField.sendKeys("3BHK");​
console.log("BHKs information entered");​

// Price​
const priceField = await findElement(driver, [​
By.id("price"),​
By.css('input[placeholder*="$2999" i]'),​
]);​
await priceField.clear();​
await priceField.sendKeys("25000");​
console.log("Price entered");​

// Category (Star Rating)​
const categorySelect = await findElement(driver, [​
By.id("category"),​
By.css("select:nth-of-type(1)"),​
]);​
await driver.executeScript("arguments[0].click();", categorySelect);​
await driver.sleep(500);​
await driver.executeScript("arguments[0].value = '5';", categorySelect);​
console.log("Selected 5-star rating");​

// Amenities​
const amenitiesSelect = await findElement(driver, [​
By.id("amenities"),​
By.css("select:nth-of-type(2)"),​
]);​
await driver.executeScript("arguments[0].click();", amenitiesSelect);​
await driver.sleep(500);​
await driver.executeScript("arguments[0].value = '1';", amenitiesSelect);​
Denish Suhagiya
Reg No - 221070071

console.log("Selected Electricity as amenity");​



// Area​
const areaField = await findElement(driver, [​
By.css('input[placeholder*="Type area" i]'),​
]);​
await areaField.clear();​
await areaField.sendKeys("1500");​
console.log("Area entered");​

// Description​
const descriptionField = await findElement(driver, [​
By.id("description"),​
By.css("textarea"),​
]);​
await descriptionField.clear();​
await descriptionField.sendKeys(​
"This is a test property created by automated testing."​
);​
console.log("Description entered");​

// Submit the form​
const submitBtn = await findElement(driver, [​
By.xpath('//button[contains(text(), "Add product")]'),​
By.css(".bg-slate-700"),​
]);​
await submitBtn.click();​
console.log("Property form submitted");​
await driver.sleep(3000);​

// Verify success - Check if form was reset​
const nameFieldValue = await nameField.getAttribute("value");​
if (nameFieldValue === "") {​
console.log("Property addition successful - Form was reset");​
} else {​
console.log("Property may not have been added - Form not reset");​
}

Output -
Denish Suhagiya
Reg No - 221070071
Denish Suhagiya
Reg No - 221070071

Conclusion:

Selenium proves to be a powerful and flexible tool for web automation and testing. Its
cross-browser and cross-platform support, combined with its ability to integrate with
various programming languages and frameworks, makes it ideal for end-to-end testing
of web applications. Through practical implementation, users gain hands-on experience
with automated workflows, improving the reliability and scalability of web-based
systems.

You might also like