# E - Commerce

package guvinewtask;

import [org.openqa.selenium.By](http://org.openqa.selenium.By); import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import [org.openqa.selenium.chrome](http://org.openqa.selenium.chrome).ChromeDriver; import [org.openqa.selenium.support](http://org.openqa.selenium.support).ui.ExpectedConditions; import [org.openqa.selenium.support](http://org.openqa.selenium.support).ui.WebDriverWait; import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import java.time.Duration;

public class BaseTest { protected WebDriver driver; protected WebDriverWait wait;

@BeforeClass public void setup() { driver = new ChromeDriver(); driver.manage().window().maximize(); wait = new WebDriverWait(driver, Duration.ofSeconds(10)); driver.get("[https://www.bestbuy.com/](https://www.bestbuy.com/)"); }

@AfterClass public void tearDown() { if (driver != null) { driver.quit(); } } }

class LoginTest extends BaseTest { @Test public void testLogin() { driver.get("[https://www.bestbuy.com/identity/signin](https://www.bestbuy.com/identity/signin)"); WebElement emailInput = wait.until(ExpectedConditions.visibilityOfElementLocated([By.id](http://By.id)("fld-e"))); WebElement passwordInput = driver.findElement([By.id](http://By.id)("fld-p1"));

emailInput.sendKeys("[suganyukanss@gmail.com](mailto:suganyukanss@gmail.com)"); passwordInput.sendKeys("Suganya@123"); passwordInput.submit();

Assert.assertTrue(driver.getPageSource().contains("Welcome"), "Login failed"); } }

class NavigationTest extends BaseTest { @Test public void testMainMenuNavigation() { WebElement menuOption = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button\[text()='Menu'\]"))); [menuOption.click](http://menuOption.click)();

WebElement departmentLink = wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Shop by Department"))); [departmentLink.click](http://departmentLink.click)();

Assert.assertTrue(driver.getCurrentUrl().contains("departments")); } }

class CartTest extends BaseTest { @Test public void testAddItemToCart() { WebElement searchBox = wait.until(ExpectedConditions.visibilityOfElementLocated([By.id](http://By.id)("gh-search-input"))); searchBox.sendKeys("Laptop"); searchBox.submit();

WebElement firstItem = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(".sku-item"))); [firstItem.click](http://firstItem.click)();

WebElement addToCartButton = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(".add-to-cart-button"))); [addToCartButton.click](http://addToCartButton.click)();

WebElement cartCount = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".cart-count"))); Assert.assertTrue(Integer.parseInt(cartCount.getText()) &gt; 0, "Cart is empty"); } }

class CheckoutTest extends BaseTest { @Test public void testCheckout() { WebElement cartIcon = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("a\[href\*='cart'\]"))); [cartIcon.click](http://cartIcon.click)();

WebElement checkoutButton = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("button\[data-button-id='checkout'\]"))); [checkoutButton.click](http://checkoutButton.click)();

WebElement paymentInfo = wait.until(ExpectedConditions.visibilityOfElementLocated([By.id](http://By.id)("credit-card-number"))); paymentInfo.sendKeys("4111111111111111");

WebElement submitOrder = driver.findElement([By.id](http://By.id)("submit-order")); [submitOrder.click](http://submitOrder.click)();

Assert.assertTrue(driver.getPageSource().contains("Order Confirmation"), "Checkout failed"); } }

Facing issues in this portal could not able to redirect in the automation server - displayed error message when its start automating - in manual UI also not working properly - if we click cart button its redirect to this blank page

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1731224599782/6242b73d-8f7d-4606-91ba-f9b2c445cde2.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1731224618632/a32bf4fd-f1e9-4308-bd10-2b3d7b2548e9.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1737105855849/76cb9623-0c83-43d3-9224-6b9beed759f1.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1737105884209/7f3ce986-da05-421a-8c19-5b38e1641d56.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1737105923982/621700bd-d38c-4d10-8b5e-2101d34e3beb.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1737105944025/c5e6a015-5b6b-4475-a79d-0067e218f031.png align="center")
