0% found this document useful (0 votes)
2 views3 pages

Ex 1

This Java program uses Selenium WebDriver to automate an e-commerce test on Amazon. It includes steps for setting up the WebDriver, logging in, searching for a product, adding it to the cart, proceeding to checkout, entering shipping and payment information, and confirming the order. The program also handles exceptions and ensures the browser closes after execution.

Uploaded by

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

Ex 1

This Java program uses Selenium WebDriver to automate an e-commerce test on Amazon. It includes steps for setting up the WebDriver, logging in, searching for a product, adding it to the cart, proceeding to checkout, entering shipping and payment information, and confirming the order. The program also handles exceptions and ensures the browser closes after execution.

Uploaded by

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

import org.openqa.selenium.

By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

public class ECommerceFullTest {

public static void main(String[] args) {

// 1. Setup

System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");

WebDriver driver = new ChromeDriver();

driver.manage().window().maximize();

try {

// 2. Open e-commerce website

driver.get("hwww.amazon.in/");

// 3. Login (you can skip this if testing Amazon-style guest purchase)

driver.findElement(By.id("loginLink")).click();

driver.findElement(By.id("username")).sendKeys("[email protected]");

driver.findElement(By.id("password")).sendKeys("password123");

driver.findElement(By.id("loginButton")).click();

// 4. Search for a product

WebElement search = driver.findElement(By.id("searchBox"));

search.sendKeys("Laptop");

driver.findElement(By.id("searchButton")).click();
// 5. Select first product

driver.findElement(By.cssSelector(".product-item:first-child .product-link")).click();

// 6. Add to cart

driver.findElement(By.id("addToCart")).click();

// 7. Go to cart

driver.findElement(By.id("cartIcon")).click();

// 8. Proceed to checkout

driver.findElement(By.id("checkoutButton")).click();

// 9. Enter shipping info (simplified)

driver.findElement(By.id("address")).sendKeys("123 Main Street");

driver.findElement(By.id("city")).sendKeys("Chennai");

driver.findElement(By.id("zip")).sendKeys("600001");

// 10. Enter payment info

driver.findElement(By.id("cardNumber")).sendKeys("4111111111111111");

driver.findElement(By.id("cardExpiry")).sendKeys("12/25");

driver.findElement(By.id("cardCVV")).sendKeys("123");

// 11. Submit order

driver.findElement(By.id("placeOrder")).click();

// 12. Confirm order

WebElement confirmation = driver.findElement(By.id("confirmationMessage"));


if (confirmation.isDisplayed()) {

System.out.println("✅ Test Passed: Order placed successfully.");

} else {

System.out.println("❌ Test Failed: Order confirmation not displayed.");

} catch (Exception e) {

System.out.println("⚠ Test failed due to: " + e.getMessage());

} finally {

// 13. Close browser

driver.quit();

You might also like