-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathE_commerceTest.java
More file actions
52 lines (42 loc) · 1.81 KB
/
Copy pathE_commerceTest.java
File metadata and controls
52 lines (42 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class ECommerceTest {
WebDriver driver;
@BeforeTest
public void setup() {
System.setProperty("webdriver.chrome.driver", "path/to/java/chromedriver"); // Update with your path
driver = new ChromeDriver();
driver.manage().window().maximize();
}
@Test(priority = 1)
public void testLogin() {
driver.get("https://google.com/login");
WebElement username = driver.findElement(By.id("username"));
WebElement password = driver.findElement(By.id("password"));
WebElement loginBtn = driver.findElement(By.id("loginButton"));
username.sendKeys("testuser");
password.sendKeys("testpassword");
loginBtn.click();
String expectedUrl = "https://google.com/dashboard";
Assert.assertEquals(driver.getCurrentUrl(), expectedUrl, "Login Failed!");
}
@Test(priority = 2, dependsOnMethods = {"testLogin"})
public void testProductSearch() {
WebElement searchBox = driver.findElement(By.id("searchBar")); // Update with actual search bar ID
WebElement searchButton = driver.findElement(By.id("searchButton")); // Update with actual button ID
searchBox.sendKeys("Laptop"); // Enter product name
searchButton.click();
WebElement firstResult = driver.findElement(By.className("product-item")); // Change as per website's HTML
Assert.assertTrue(firstResult.isDisplayed(), "Product Search Failed!");
}
@AfterTest
public void tearDown() {
driver.quit();
}
}