4
4
import org .openqa .selenium .By ;
5
5
import org .openqa .selenium .WebElement ;
6
6
import org .openqa .selenium .support .locators .RelativeLocator ;
7
+ import org .testng .annotations .BeforeMethod ;
7
8
import org .testng .annotations .Test ;
8
9
import org .testng .asserts .SoftAssert ;
9
10
import tests .BaseTest ;
@@ -15,14 +16,25 @@ public class LocatorTests extends BaseTest {
15
16
private final String labelLocatorCell = "//td" ;
16
17
private final String labelLocatorCellRow5Column5 = "//tr[5]/td[5]" ;
17
18
private final String labelLocatorCellRow3Column5 = "//tr[3]/td[5]" ;
19
+ private final String labelLocatorCellRow7Column5 = "//tr[7]/td[5]" ;
20
+ private final String labelLocatorCellRow5Column3 = "//tr[5]/td[3]" ;
21
+ private final String labelLocatorCellRow5Column7 = "//tr[5]/td[7]" ;
18
22
private final String nameElementRow3Column5 = "expectedRow3Column5GotWithByXpath" ;
23
+ private final String nameElementRow7Column5 = "expectedRow7Column5GotWithByXpath" ;
24
+ private final String nameElementRow5Column3 = "expectedRow5Column3GotWithByXpath" ;
25
+ private final String nameElementRow5Column7 = "expectedRow5Column7GotWithByXpath" ;
26
+ private final String nameElementRow5Column5 = "expectedRow5Column5" ;
19
27
private final String friendlyMessage = "Actual cell text is not equal expected" ;
20
28
29
+ @ BeforeMethod
30
+ public void beforeMethod () {
31
+ navigate (TheInternetPage .CHALLENGING_DOM );
32
+ }
33
+
21
34
@ Test
22
35
public void testAboveLocatorWithDifferentAboveParametersType () {
23
- navigate (TheInternetPage .CHALLENGING_DOM );
24
36
25
- ILabel cellInRow3Column5 = elementFactory .getLabel (By .xpath (labelLocatorCellRow3Column5 ), "CellInRow4Column5 " );
37
+ ILabel cellInRow3Column5 = elementFactory .getLabel (By .xpath (labelLocatorCellRow3Column5 ), "CellInRow3Column5 " );
26
38
ILabel cellInRow5Column5 = elementFactory .getLabel (By .xpath (labelLocatorCellRow5Column5 ), "CellInRow5Column5" );
27
39
28
40
ILabel actualCellRaw3Column5GotWithByXpath =
@@ -48,6 +60,125 @@ public void testAboveLocatorWithDifferentAboveParametersType() {
48
60
cellInRow3Column5 .getText ());
49
61
}
50
62
63
+ @ Test
64
+ public void testBelowLocatorWithDifferentBelowParametersType () {
65
+
66
+ ILabel cellInRow7Column5 = elementFactory .getLabel (By .xpath (labelLocatorCellRow7Column5 ), "CellInRow7Column5" );
67
+ ILabel cellInRow5Column5 = elementFactory .getLabel (By .xpath (labelLocatorCellRow5Column5 ), "CellInRow5Column5" );
68
+
69
+ ILabel actualCellRaw7Column5GotWithByXpath =
70
+ elementFactory .getLabel (with (By .xpath (labelLocatorCell )).below (By .xpath (labelLocatorCellRow5Column5 )),
71
+ nameElementRow7Column5 );
72
+
73
+ ILabel actualCellRaw7Column5GotWithWebElement =
74
+ elementFactory .getLabel (with (By .xpath (labelLocatorCell )).below (cellInRow5Column5 .getElement ()),
75
+ nameElementRow7Column5 );
76
+
77
+ ILabel actualCellRaw7Column5GotWithAqualityElement =
78
+ elementFactory .getLabel (with (By .xpath (labelLocatorCell )).below (cellInRow5Column5 ),
79
+ nameElementRow7Column5 );
80
+
81
+ WebElement actualWebElementCellRaw7Column5GotBySeleniumRelative =
82
+ getBrowser ().getDriver ().findElement (RelativeLocator .with (By .xpath (labelLocatorCell )).below (By .xpath (labelLocatorCellRow5Column5 )));
83
+
84
+ checkDifferentTypesWithSoftAssert (
85
+ actualCellRaw7Column5GotWithAqualityElement .getText (),
86
+ actualCellRaw7Column5GotWithWebElement .getText (),
87
+ actualCellRaw7Column5GotWithByXpath .getText (),
88
+ actualWebElementCellRaw7Column5GotBySeleniumRelative .getText (),
89
+ cellInRow7Column5 .getText ());
90
+ }
91
+
92
+
93
+ @ Test
94
+ public void testToLeftOfLocatorWithDifferentToLeftOfParametersType () {
95
+
96
+ ILabel cellInRow5Column3 = elementFactory .getLabel (By .xpath (labelLocatorCellRow5Column3 ), "CellInRow5Column3" );
97
+ ILabel cellInRow5Column5 = elementFactory .getLabel (By .xpath (labelLocatorCellRow5Column5 ), "CellInRow5Column5" );
98
+
99
+ ILabel actualCellRaw5Column3GotWithByXpath =
100
+ elementFactory .getLabel (with (By .xpath (labelLocatorCell )).toLeftOf (By .xpath (labelLocatorCellRow5Column5 )),
101
+ nameElementRow5Column3 );
102
+
103
+ ILabel actualCellRaw5Column3GotWithWebElement =
104
+ elementFactory .getLabel (with (By .xpath (labelLocatorCell )).toLeftOf (cellInRow5Column5 .getElement ()),
105
+ nameElementRow5Column3 );
106
+
107
+ ILabel actualCellRaw5Column3GotWithAqualityElement =
108
+ elementFactory .getLabel (with (By .xpath (labelLocatorCell )).toLeftOf (cellInRow5Column5 ),
109
+ nameElementRow5Column3 );
110
+
111
+ WebElement actualWebElementCellRaw5Column3GotBySeleniumRelative =
112
+ getBrowser ().getDriver ().findElement (RelativeLocator .with (By .xpath (labelLocatorCell )).toLeftOf (By .xpath (labelLocatorCellRow5Column5 )));
113
+
114
+ checkDifferentTypesWithSoftAssert (
115
+ actualCellRaw5Column3GotWithAqualityElement .getText (),
116
+ actualCellRaw5Column3GotWithWebElement .getText (),
117
+ actualCellRaw5Column3GotWithByXpath .getText (),
118
+ actualWebElementCellRaw5Column3GotBySeleniumRelative .getText (),
119
+ cellInRow5Column3 .getText ());
120
+ }
121
+
122
+ @ Test
123
+ public void testToRightOfLocatorWithDifferentToRightOfParametersType () {
124
+
125
+ ILabel cellInRow5Column7 = elementFactory .getLabel (By .xpath (labelLocatorCellRow5Column7 ), "CellInRow5Column7" );
126
+ ILabel cellInRow5Column5 = elementFactory .getLabel (By .xpath (labelLocatorCellRow5Column5 ), "CellInRow5Column5" );
127
+
128
+ ILabel actualCellRaw5Column7GotWithByXpath =
129
+ elementFactory .getLabel (with (By .xpath (labelLocatorCell )).toRightOf (By .xpath (labelLocatorCellRow5Column5 )),
130
+ nameElementRow5Column7 );
131
+
132
+ ILabel actualCellRaw5Column7GotWithWebElement =
133
+ elementFactory .getLabel (with (By .xpath (labelLocatorCell )).toRightOf (cellInRow5Column5 .getElement ()),
134
+ nameElementRow5Column3 );
135
+
136
+ ILabel actualCellRaw5Column7GotWithAqualityElement =
137
+ elementFactory .getLabel (with (By .xpath (labelLocatorCell )).toRightOf (cellInRow5Column5 ),
138
+ nameElementRow5Column3 );
139
+
140
+ WebElement actualWebElementCellRaw5Column7GotBySeleniumRelative =
141
+ getBrowser ().getDriver ().findElement (RelativeLocator .with (By .xpath (labelLocatorCell )).toRightOf (By .xpath (labelLocatorCellRow5Column5 )));
142
+
143
+ checkDifferentTypesWithSoftAssert (
144
+ actualCellRaw5Column7GotWithAqualityElement .getText (),
145
+ actualCellRaw5Column7GotWithWebElement .getText (),
146
+ actualCellRaw5Column7GotWithByXpath .getText (),
147
+ actualWebElementCellRaw5Column7GotBySeleniumRelative .getText (),
148
+ cellInRow5Column7 .getText ());
149
+ }
150
+
151
+ @ Test
152
+ public void testAboveBelowLeftRight () {
153
+
154
+ ILabel cellInRow3Column5 = elementFactory .getLabel (By .xpath (labelLocatorCellRow3Column5 ), "CellInRow3Column5" );
155
+ ILabel cellInRow5Column7 = elementFactory .getLabel (By .xpath (labelLocatorCellRow5Column7 ), "CellInRow5Column7" );
156
+ ILabel cellInRow5Column5 = elementFactory .getLabel (By .xpath (labelLocatorCellRow5Column5 ), "CellInRow5Column5" );
157
+ ILabel cellInRow5Column3 = elementFactory .getLabel (By .xpath (labelLocatorCellRow5Column3 ), "CellInRow5Column3" );
158
+ ILabel cellInRow7Column5 = elementFactory .getLabel (By .xpath (labelLocatorCellRow7Column5 ), "CellInRow7Column5" );
159
+
160
+
161
+
162
+ ILabel actualCellRaw5Column5GotWithAqualityElement =
163
+ elementFactory .getLabel (with (By .xpath (labelLocatorCell ))
164
+ .above (cellInRow7Column5 )
165
+ .below (cellInRow3Column5 )
166
+ .toRightOf (cellInRow5Column3 )
167
+ .toLeftOf (cellInRow5Column7 )
168
+ .above (cellInRow7Column5 ), nameElementRow5Column5 );
169
+
170
+
171
+ String a = actualCellRaw5Column5GotWithAqualityElement .getText ();
172
+ int ss =2 ;
173
+
174
+
175
+ }
176
+
177
+
178
+
179
+
180
+
181
+
51
182
public void checkDifferentTypesWithSoftAssert (String textAquality , String textWebElement , String textByXpath , String textSelenium , String expectedText ) {
52
183
SoftAssert softAssert = new SoftAssert ();
53
184
softAssert .assertEquals (textAquality , expectedText , friendlyMessage );
0 commit comments