-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchTest.java
More file actions
62 lines (53 loc) · 2.33 KB
/
SearchTest.java
File metadata and controls
62 lines (53 loc) · 2.33 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
53
54
55
56
57
58
59
60
61
62
package tests;
import java.time.Duration;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import PageObectModel.SearchProduct;
@Test
public class SearchTest {
private WebDriver driver;
private SearchProduct searchPage;
@BeforeClass
void setup() {
driver = new ChromeDriver();
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
driver.get("https://tutorialsninja.com/demo/");
driver.manage().window().maximize();
searchPage = new SearchProduct(driver);
}
public void testProductSearchValid() {
searchPage.searchPro("Tablets"); // Change to invalid input to test failure case
if (searchPage.isProductDisplayed()) {
System.out.println("✅ Product found!");
Assert.assertTrue(searchPage.isProductDisplayed(), "Product should be displayed.");
} else if (searchPage.isNoResultsDisplayed()) {
System.out.println("⚠ No results found!");
Assert.assertTrue(searchPage.isNoResultsDisplayed(), "There is no product that matches the search criteria.");
} else {
System.out.println("❌ Unexpected behavior! Neither product nor error message appeared.");
Assert.fail("Search behaviour is incorrect.");
}
}
public void testProductSearchInValid() {
searchPage.searchPro("@#"); // Change to invalid input to test failure case
if (searchPage.isProductDisplayed()) {
System.out.println("✅ Product found!");
Assert.assertTrue(searchPage.isProductDisplayed(), "Product should be displayed.");
} else if (searchPage.isNoResultsDisplayed()) {
System.out.println("⚠ No results found!");
Assert.assertTrue(searchPage.isNoResultsDisplayed(), "There is no product that matches the search criteria.");
} else {
System.out.println("❌ Unexpected behavior! Neither product nor error message appeared.");
Assert.fail("Search behaviour is incorrect.");
}
}
@AfterClass
public void teardown() {
driver.quit();
}
}