0% found this document useful (0 votes)
13 views10 pages

Project Krishna 32311929

The document is a Java Selenium test script for automating user interactions on a Magento e-commerce website. It includes methods for account creation, login, product search, adding items to the cart, and managing account information. The script utilizes WebDriver and WebDriverWait for browser automation and synchronization during the test execution.
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)
13 views10 pages

Project Krishna 32311929

The document is a Java Selenium test script for automating user interactions on a Magento e-commerce website. It includes methods for account creation, login, product search, adding items to the cart, and managing account information. The script utilizes WebDriver and WebDriverWait for browser automation and synchronization during the test execution.
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/ 10

package luma;

import java.time.Duration;

import org.openqa.selenium.*;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.support.ui.*;

import org.testng.annotations.*;

public class luma3 {

WebDriver driver;

WebDriverWait wait;

@BeforeTest

public void setup() {

driver = new ChromeDriver();

wait = new WebDriverWait(driver, Duration.ofSeconds(10));

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

driver.get("https://magento.softwaretestingboard.com/");

@Test(priority = 1)

public void testMagentoFlow() throws InterruptedException {

createAccount();

logout();

login();

searchProduct();

filterProductByCategory();

selectProductAndAddToCart();
updateQuantityInCart();

proceedToCheckout();

addToWishlist();

removeItemFromCart();

viewMyOrders();

viewDownloadableProducts();

viewWishlist();

viewAddressBook();

viewAccountInfo();

viewStoredPayment();

viewProductReview();

editAccountInformation();

changePassword();

changeEmail();

logout();

public void createAccount() {

driver.findElement(By.linkText("Create an Account")).click();

wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("firstname"))).sendKeys("Kris
hna");

driver.findElement(By.id("lastname")).sendKeys("C S");

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

driver.findElement(By.id("password")).sendKeys("krishna@123");

driver.findElement(By.id("password-confirmation")).sendKeys("krishna@123");

driver.findElement(By.cssSelector("button[title='Create an Account']")).click();

try {
wait.until(ExpectedConditions.titleContains("My Account"));

System.out.println("Account created successfully.");

} catch (TimeoutException e) {

if (driver.getPageSource().contains("There is already an account with this email


address")) {

System.out.println("Account already exists. Proceeding to login...");

driver.get("https://magento.softwaretestingboard.com/customer/account/login/");

login();

} else {

throw e;

public void login() {

driver.findElement(By.linkText("Sign In")).click();

wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("email"))).sendKeys("kichukri
[email protected]");

driver.findElement(By.id("pass")).sendKeys("krishna@123");

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

wait.until(ExpectedConditions.titleContains("My Account"));

public void searchProduct() {

driver.findElement(By.id("search")).sendKeys("jacket");

driver.findElement(By.cssSelector("button[title='Search']")).click();

wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".product-
items")));
}

public void filterProductByCategory() {

driver.findElement(By.linkText("Men")).click();

wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Tops"))).click();

public void selectProductAndAddToCart() {

driver.get("https://magento.softwaretestingboard.com/men/tops-men/jackets-
men.html");

WebElement product =
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(".product-item-info
a.product-item-link")));

product.click();

wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.swatch-
attribute.size .swatch-option"))).click();

wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.swatch-
attribute.color .swatch-option"))).click();

driver.findElement(By.id("product-addtocart-button")).click();

wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div.message-
success")));

public void updateQuantityInCart() {

driver.findElement(By.cssSelector(".showcart")).click();

wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(".viewcart"))).click();

WebElement qtyField =
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.input-text.qty")));

qtyField.clear();

qtyField.sendKeys("2");
driver.findElement(By.cssSelector("button.update")).click();

public void proceedToCheckout() {

driver.findElement(By.cssSelector(".showcart")).click();

wait.until(ExpectedConditions.elementToBeClickable(By.id("top-cart-btn-
checkout"))).click();

public void addToWishlist() {

driver.get("https://magento.softwaretestingboard.com/hero-hoodie.html");

wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.action.towishlist"))).cl
ick();

wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div.message-
success")));

public void removeItemFromCart() {

WebElement cartIcon =
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(".showcart")));

cartIcon.click();

WebElement deleteIcon =
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.action.delete")));

deleteIcon.click();

WebElement confirmDelete =
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("button.action-
primary.action-accept")));
confirmDelete.click();

wait.until(ExpectedConditions.or(

ExpectedConditions.textToBePresentInElementLocated(By.cssSelector(".subtitle.empty"),
"You have no items in your shopping cart."),

ExpectedConditions.invisibilityOf(confirmDelete)

));

// ----- Account Section Navigation -----

public void navigateToAccountSection(String menuText) {

WebElement welcome =
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(".customer-welcome")));

welcome.click();

wait.until(ExpectedConditions.elementToBeClickable(By.linkText("My Account"))).click();

wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".block-
account")));

try {

wait.until(ExpectedConditions.elementToBeClickable(By.linkText(menuText))).click();

} catch (Exception e) {

wait.until(ExpectedConditions.elementToBeClickable(By.partialLinkText(menuText))).click();

public void viewMyOrders() {

navigateToAccountSection("My Orders");
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".order-
products")));

public void viewDownloadableProducts() {

navigateToAccountSection("My Downloadable Products");

wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".downloadable-
products")));

public void viewWishlist() {

navigateToAccountSection("My Wish List");

wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".wishlist")));

public void viewAddressBook() {

navigateToAccountSection("Address Book");

wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".box-address-
billing")));

public void viewAccountInfo() {

navigateToAccountSection("Account Information");

wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("firstname")));

public void viewStoredPayment() {

navigateToAccountSection("Stored Payment Methods");


wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".stored-
payments")));

public void viewProductReview() {

navigateToAccountSection("My Product Reviews");

wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".review-
items")));

public void editAccountInformation() {

navigateToAccountSection("Account Information");

WebElement firstNameField =
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("firstname")));

firstNameField.clear();

firstNameField.sendKeys("AnjuUpdated");

driver.findElement(By.cssSelector("button[title='Save']")).click();

public void changePassword() {

navigateToAccountSection("Account Information");

WebElement checkbox = driver.findElement(By.id("change-password"));

if (!checkbox.isSelected()) checkbox.click();

driver.findElement(By.id("current-password")).sendKeys("Anjus@123456");

driver.findElement(By.id("password")).sendKeys("NewPass@123");

driver.findElement(By.id("password-confirmation")).sendKeys("NewPass@123");

driver.findElement(By.cssSelector("button[title='Save']")).click();

}
public void changeEmail() {

navigateToAccountSection("Account Information");

WebElement checkbox = driver.findElement(By.id("change-email"));

if (!checkbox.isSelected()) checkbox.click();

WebElement emailField = driver.findElement(By.id("email"));

emailField.clear();

emailField.sendKeys("[email protected]");

driver.findElement(By.id("current-password")).sendKeys("NewPass@123");

driver.findElement(By.cssSelector("button[title='Save']")).click();

public void logout() {

try {

WebElement welcome =
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(".customer-welcome")));

welcome.click();

wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Sign Out"))).click();

} catch (Exception e) {

System.out.println("Logout failed or already logged out.");

@AfterTest

public void teardown() {

if (driver != null) {

driver.quit();

}
}

You might also like