-
-
Notifications
You must be signed in to change notification settings - Fork 120
/
LocatorBuilderTest.java
123 lines (101 loc) · 4.51 KB
/
LocatorBuilderTest.java
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package testPackage.locator;
import com.shaft.driver.SHAFT;
import com.shaft.gui.internal.locator.Locator;
import org.openqa.selenium.By;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class LocatorBuilderTest {
private static final ThreadLocal<SHAFT.GUI.WebDriver> driver = new ThreadLocal<>();
@BeforeMethod
public void beforeMethod() {
driver.set(new SHAFT.GUI.WebDriver());
driver.get().browser().navigateToURL("https://shafthq.github.io/");
}
@AfterMethod(alwaysRun = true)
public void afterMethod() {
driver.get().quit();
}
@Test
public void hasTagName() {
By locator = SHAFT.GUI.Locator.hasTagName("h1").build();
driver.get().assertThat().element(locator).text().contains("SHAFT").perform();
}
@Test
public void containsText() {
By locator = Locator.hasTagName("h1").containsText("Unified Test Automation Engine").build();
driver.get().assertThat().element(locator).text().contains("SHAFT").perform();
}
@Test
public void containsAttribute() {
By locator = Locator.hasTagName("h1").containsAttribute("class", "hero").build();
driver.get().assertThat().element(locator).text().contains("SHAFT").perform();
}
@Test
public void containsClass() {
By locator = Locator.hasTagName("h1").containsClass("hero").build();
driver.get().assertThat().element(locator).text().contains("SHAFT").perform();
}
@Test
public void containsIdAndIsFirst() {
By locator = Locator.hasTagName("*").containsId("_docusaurus").isFirst().build();
driver.get().assertThat().element(locator).cssProperty("display").contains("flex").perform();
}
@Test
public void hasAttributeAndContainsIdAndIsFirst() {
By locator = Locator.hasTagName("*").hasAttribute("id").containsId("_docusaurus").isFirst().build();
driver.get().assertThat().element(locator).attribute("display").contains("null").perform();
}
@Test
public void hasIdAndContainsId() {
By locator = Locator.hasTagName("*").hasId("__docusaurus").build();
driver.get().assertThat().element(locator).attribute("display").contains("null").perform();
}
@Test
public void hasAttributeWithValue() {
By locator = SHAFT.GUI.Locator.hasAnyTagName()
.and().hasAttribute("id", "__docusaurus")
.build();
driver.get().assertThat().element(locator).attribute("display").contains("null").perform();
}
@Test
public void hasClass() {
By locator = Locator.hasTagName("h1").hasClass("hero__title").build();
driver.get().assertThat().element(locator).text().contains("SHAFT").perform();
}
@Test
public void hasText() {
By locator = Locator.hasTagName("h1").hasText("SHAFT: Unified Test Automation Engine").build();
driver.get().assertThat().element(locator).attribute("class").contains("hero__title").perform();
}
@Test
public void hasIndex() {
By locator = Locator.hasTagName("p").hasIndex(1).build();
driver.get().assertThat().element(locator).text().contains("Stop reinventing the wheel").perform();
}
@Test
public void isFirst() {
By locator = Locator.hasTagName("p").isFirst().build();
driver.get().assertThat().element(locator).text().contains("Stop reinventing the wheel").perform();
}
@Test
public void isLast() {
By locator = Locator.hasTagName("p").isLast().build();
driver.get().assertThat().element(locator).text().contains("What are you waiting for?").perform();
}
@Test
public void relativeBy() {
By locator = Locator.hasTagName("a").relativeBy().below(Locator.hasTagName("h1").containsText("SHAFT").build());
driver.get().assertThat().element(locator).text().contains("Upgrade Now").perform();
}
@Test
public void axisBy_followingSibling() {
By locator = Locator.hasTagName("h1").containsText("SHAFT").axisBy().followingSibling("p").build();
driver.get().assertThat().element(locator).text().contains("Stop reinventing the wheel").perform();
}
@Test
public void axisBy_chain_precedingSibling() {
By locator = Locator.hasTagName("h1").containsText("SHAFT").axisBy().followingSibling("p").axisBy().precedingSibling("h1").hasIndex(1).build();
driver.get().assertThat().element(locator).text().isEqualTo("SHAFT: Unified Test Automation Engine").perform();
}
}