0% found this document useful (0 votes)
39 views

Practice Workspace Selenium Locators

This document defines a test class for testing a website called Demoblaze. The test class contains a before method to initialize the driver and navigate to the site under test. It also contains a test method that adds an item to the cart, verifies the item and price in the cart, and quits the driver.

Uploaded by

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

Practice Workspace Selenium Locators

This document defines a test class for testing a website called Demoblaze. The test class contains a before method to initialize the driver and navigate to the site under test. It also contains a test method that adds an item to the cart, verifies the item and price in the cart, and quits the driver.

Uploaded by

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

package Demoblaze_Test;

import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;
import java.util.List;

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import utils.EventHandler;

import org.testng.annotations.AfterMethod;
import org.openqa.selenium.support.events.EventFiringDecorator;
import org.openqa.selenium.support.events.WebDriverListener;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class Test_demoblaze{


public static WebDriver driver;
public final int IMPLICIT_WAIT_TIME=10;
public final int PAGE_LOAD_TIME=5;
@BeforeMethod
public WebDriver beforeMethod() throws MalformedURLException{
ChromeOptions chromeOptions = new ChromeOptions();
driver = new RemoteWebDriver(new URL("http://localhost:4444/"),
chromeOptions);
driver.get("https://www.demoblaze.com/");
WebDriverListener listener = new EventHandler();
driver = new EventFiringDecorator<>(listener).decorate(driver);
return driver;

}
@Test
public void shouldAnswerWithTrue() throws InterruptedException
{
WebElement element = driver.findElement(By.linkText("Laptops"));
element.click();
Thread.sleep(5000);
driver.findElement(By.linkText("MacBook air")).click();
Thread.sleep(5000);
driver.findElement(By.linkText("Add to cart")).click();
Thread.sleep(2000);
driver.switchTo().alert().accept();
Thread.sleep(2000);
driver.findElement(By.linkText("Cart")).click();
Thread.sleep(5000);

WebElement nameElement =
driver.findElement(By.xpath("/html/body/div[6]/div/div[1]/div/table/tbody/tr[1]/
td[2]"));
WebElement priceElement =
driver.findElement(By.xpath("/html/body/div[6]/div/div[1]/div/table/tbody/tr[1]/
td[3]"));
String name = nameElement.getText();
String price = priceElement.getText();
System.out.println("Name: " + name + ", Price: " + price);
Thread.sleep(5000);
driver.quit();
}
}

You might also like