BN 2
BN 2
BN 2
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
try {
// Find the Luma logo element by its XPath or CSS selector
WebElement lumaLogo = driver.findElement(By.cssSelector(".logo"));
// Sleep for a few seconds to see the redirection (this is just for
demonstration)
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
// Close the browser
driver.quit();
}
}
}
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
try {
// Click on the "What's New" link to navigate to the section
WebElement whatsNewLink = driver.findElement(By.linkText("What's
New"));
whatsNewLink.click();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
// Close the browser
driver.quit();
}
}
}
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
try {
// Click on the "Men" link to navigate to the section
WebElement menLink = driver.findElement(By.linkText("Men"));
menLink.click();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
// Close the browser
driver.quit();
}
}
}
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
try {
// Click on the "Sale" link to navigate to the section
WebElement saleLink = driver.findElement(By.linkText("Sale"));
saleLink.click();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
// Close the browser
driver.quit();
}
}
}
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
try {
// Navigate to the "Men" section
WebElement menLink = driver.findElement(By.linkText("Men"));
menLink.click();
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
// Close the browser
driver.quit();
}
}
}
2) PRODUCT BROWSING :
TEST 2.1 : Verify product categories on Shop page
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.List;
try {
// Find all elements representing product categories
List<WebElement> categoryElements =
driver.findElements(By.cssSelector(".category"));
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
import java.util.List;
try {
// Apply filter by category (e.g., "Men")
Select categoryDropdown = new
Select(driver.findElement(By.id("category")));
categoryDropdown.selectByVisibleText("Men");
Thread.sleep(3000); // Wait for products to filter
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
// Close the browser
driver.quit();
}
}
}
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
try {
// Find a product thumbnail (e.g., the first one)
WebElement productThumbnail =
driver.findElement(By.cssSelector(".product-item .product-image"));
if (productDetailsTitle.getText().equals(productName)) {
System.out.println("Clicked on product thumbnail successfully
redirects to product details page for: " + productName);
} else {
System.out.println("Failed to redirect to correct product
details page.");
}
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
// Close the browser
driver.quit();
}
}
}
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
try {
// Find a product thumbnail (e.g., the first one)
WebElement productThumbnail =
driver.findElement(By.cssSelector(".product-item .product-image"));
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
// Close the browser
driver.quit();
}
}
}
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.util.List;
try {
// Find and click on the first product thumbnail to add it to the
cart
WebElement firstProductThumbnail =
driver.findElement(By.cssSelector(".product-item .product-image"));
firstProductThumbnail.click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".produc
t-name")));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".succes
s-msg a")));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".produc
t-name")));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".succes
s-msg a")));
if (cartQuantity.getText().equals("2")) {
System.out.println("Both products are successfully added to the
cart.");
} else {
System.out.println("Failed to add both products to the cart.");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
// Close the browser
driver.quit();
}
}
}
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
try {
// Find and click on the first product thumbnail to add it to the
cart
WebElement firstProductThumbnail =
driver.findElement(By.cssSelector(".product-item .product-image"));
firstProductThumbnail.click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".produc
t-name")));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".succes
s-msg a")));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".cart-
container")));
// Proceed to checkout
WebElement proceedToCheckoutButton =
driver.findElement(By.cssSelector(".cart-totals button.checkout-button"));
proceedToCheckoutButton.click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".checko
ut-title")));
if (checkoutTitle.getText().equals("Checkout")) {
System.out.println("Proceeded to checkout successfully.");
} else {
System.out.println("Failed to proceed to checkout.");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
// Close the browser
driver.quit();
}
}
}
try {
// Fill out the registration form
driver.findElement(By.id("firstname")).sendKeys("John");
driver.findElement(By.id("lastname")).sendKeys("Doe");
driver.findElement(By.id("email_address")).sendKeys("johndoe@example.com");
driver.findElement(By.id("password")).sendKeys("Test@123");
driver.findElement(By.id("confirmation")).sendKeys("Test@123");
} catch (Exception e) {
e.printStackTrace();
} finally {
// Close the browser
driver.quit();
}
}
}
import java.util.HashMap;
import java.util.Map;
try {
// Navigate to the Magento website
driver.get("https://magento.softwaretestingboard.com/");
} catch (Exception e) {
e.printStackTrace();
} finally {
// Close the browser
driver.quit();
}
}
}
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
try {
// Navigate to the Magento website
driver.get("https://magento.softwaretestingboard.com/");
} catch (Exception e) {
e.printStackTrace();
} finally {
// Close the browser
driver.quit();
}
}
}
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
try {
// Navigate to the Magento website login page
driver.get("https://magento.softwaretestingboard.com/customer/account/login/");
} catch (Exception e) {
e.printStackTrace();
} finally {
// Close the browser
driver.quit();
}
}
}
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import java.util.List;
try {
// Navigate to the Magento website
driver.get("https://magento.softwaretestingboard.com/");
if (!element.equals(focusedElement)) {
System.out.println("Failed to focus on element: " +
element.getTagName());
}
} catch (Exception e) {
e.printStackTrace();
} finally {
// Close the browser
driver.quit();
}
}
}