16
16
public class LocatorTests extends BaseTest {
17
17
private final ChallengingDomForm challengingDomForm = new ChallengingDomForm ();
18
18
private final String labelLocatorCell = "//td" ;
19
- private final String nameElementRow3Column5 = "expectedRow3Column5GotWithByXpath " ;
20
- private final String nameElementRow7Column5 = "expectedRow7Column5GotWithByXpath " ;
21
- private final String nameElementRow5Column3 = "expectedRow5Column3GotWithByXpath " ;
22
- private final String nameElementRow5Column7 = "expectedRow5Column7GotWithByXpath " ;
19
+ private final String nameElementRow3Column5 = "expectedRow3Column5 " ;
20
+ private final String nameElementRow7Column5 = "expectedRow7Column5 " ;
21
+ private final String nameElementRow5Column3 = "expectedRow5Column3 " ;
22
+ private final String nameElementRow5Column7 = "expectedRow5Column7 " ;
23
23
private final String nameElementRow5Column5 = "expectedRow5Column5" ;
24
+ private final String nameElementRow2Column1 = "expectedRow2Column1" ;
24
25
private final String friendlyMessage = "Actual cell text is not equal expected" ;
25
26
26
27
@ BeforeMethod
@@ -46,7 +47,9 @@ public void testAboveLocatorWithDifferentAboveParametersType() {
46
47
nameElementRow3Column5 );
47
48
48
49
WebElement actualWebElementCellRaw3Column5GotBySeleniumRelative =
49
- getBrowser ().getDriver ().findElement (RelativeLocator .with (By .xpath (labelLocatorCell )).above (By .xpath (challengingDomForm .getLocatorCellRow5Column5 ())));
50
+ getBrowser ().getDriver ().findElement (RelativeLocator
51
+ .with (By .xpath (labelLocatorCell ))
52
+ .above (By .xpath (challengingDomForm .getLocatorCellRow5Column5 ())));
50
53
51
54
checkDifferentTypesWithSoftAssert (
52
55
actualCellRaw3Column5GotWithAqualityElement .getText (),
@@ -57,7 +60,7 @@ public void testAboveLocatorWithDifferentAboveParametersType() {
57
60
}
58
61
59
62
@ Test
60
- public void testBelowLocatorWithDifferentBelowParametersType () {
63
+ public void testBelowLocatorWithDifferentBelowParametersType () {
61
64
62
65
ILabel cellInRow7Column5 = challengingDomForm .getCellInRow7Column5 ();
63
66
ILabel cellInRow5Column5 = challengingDomForm .getCellInRow5Column5 ();
@@ -75,7 +78,9 @@ public void testBelowLocatorWithDifferentBelowParametersType () {
75
78
nameElementRow7Column5 );
76
79
77
80
WebElement actualWebElementCellRaw7Column5GotBySeleniumRelative =
78
- getBrowser ().getDriver ().findElement (RelativeLocator .with (By .xpath (labelLocatorCell )).below (By .xpath (challengingDomForm .getLocatorCellRow5Column5 ())));
81
+ getBrowser ().getDriver ().findElement (RelativeLocator
82
+ .with (By .xpath (labelLocatorCell ))
83
+ .below (By .xpath (challengingDomForm .getLocatorCellRow5Column5 ())));
79
84
80
85
checkDifferentTypesWithSoftAssert (
81
86
actualCellRaw7Column5GotWithAqualityElement .getText (),
@@ -87,7 +92,7 @@ public void testBelowLocatorWithDifferentBelowParametersType () {
87
92
88
93
89
94
@ Test
90
- public void testToLeftOfLocatorWithDifferentToLeftOfParametersType () {
95
+ public void testToLeftOfLocatorWithDifferentToLeftOfParametersType () {
91
96
92
97
ILabel cellInRow5Column3 = challengingDomForm .getCellInRow5Column3 ();
93
98
ILabel cellInRow5Column5 = challengingDomForm .getCellInRow5Column5 ();
@@ -105,7 +110,9 @@ public void testToLeftOfLocatorWithDifferentToLeftOfParametersType () {
105
110
nameElementRow5Column3 );
106
111
107
112
WebElement actualWebElementCellRaw5Column3GotBySeleniumRelative =
108
- getBrowser ().getDriver ().findElement (RelativeLocator .with (By .xpath (labelLocatorCell )).toLeftOf (By .xpath (challengingDomForm .getLocatorCellRow5Column5 ())));
113
+ getBrowser ().getDriver ().findElement (RelativeLocator
114
+ .with (By .xpath (labelLocatorCell ))
115
+ .toLeftOf (By .xpath (challengingDomForm .getLocatorCellRow5Column5 ())));
109
116
110
117
checkDifferentTypesWithSoftAssert (
111
118
actualCellRaw5Column3GotWithAqualityElement .getText (),
@@ -116,7 +123,7 @@ public void testToLeftOfLocatorWithDifferentToLeftOfParametersType () {
116
123
}
117
124
118
125
@ Test
119
- public void testToRightOfLocatorWithDifferentToRightOfParametersType () {
126
+ public void testToRightOfLocatorWithDifferentToRightOfParametersType () {
120
127
ILabel cellInRow5Column7 = challengingDomForm .getCellInRow5Column7 ();
121
128
ILabel cellInRow5Column5 = challengingDomForm .getCellInRow5Column5 ();
122
129
@@ -133,7 +140,9 @@ public void testToRightOfLocatorWithDifferentToRightOfParametersType () {
133
140
nameElementRow5Column3 );
134
141
135
142
WebElement actualWebElementCellRaw5Column7GotBySeleniumRelative =
136
- getBrowser ().getDriver ().findElement (RelativeLocator .with (By .xpath (labelLocatorCell )).toRightOf (By .xpath (challengingDomForm .getLocatorCellRow5Column5 ())));
143
+ getBrowser ().getDriver ().findElement (RelativeLocator
144
+ .with (By .xpath (labelLocatorCell ))
145
+ .toRightOf (By .xpath (challengingDomForm .getLocatorCellRow5Column5 ())));
137
146
138
147
checkDifferentTypesWithSoftAssert (
139
148
actualCellRaw5Column7GotWithAqualityElement .getText (),
@@ -157,15 +166,16 @@ public void testAboveBelowLeftRight() {
157
166
.below (cellInRow3Column5 )
158
167
.toRightOf (cellInRow5Column3 )
159
168
.toLeftOf (cellInRow5Column7 )
160
- .above (cellInRow7Column5 ), nameElementRow5Column5 );
169
+ .above (cellInRow7Column5 )
170
+ , nameElementRow5Column5 );
161
171
162
172
ILabel actualCellRaw5Column5GotWithWebElement =
163
173
elementFactory .getLabel (with (By .xpath (labelLocatorCell ))
164
- .above (cellInRow7Column5 .getElement ())
165
- .below (cellInRow3Column5 .getElement ())
166
- .toRightOf (cellInRow5Column3 .getElement ())
167
- .toLeftOf (cellInRow5Column7 .getElement ())
168
- .above (cellInRow7Column5 .getElement ())
174
+ .above (cellInRow7Column5 .getElement ())
175
+ .below (cellInRow3Column5 .getElement ())
176
+ .toRightOf (cellInRow5Column3 .getElement ())
177
+ .toLeftOf (cellInRow5Column7 .getElement ())
178
+ .above (cellInRow7Column5 .getElement ())
169
179
, nameElementRow5Column5 );
170
180
171
181
ILabel actualCellRaw5Column5GotWithXpath =
@@ -183,8 +193,7 @@ public void testAboveBelowLeftRight() {
183
193
.below (By .xpath (challengingDomForm .getLocatorCellRow3Column5 ()))
184
194
.toRightOf (By .xpath (challengingDomForm .getLocatorCellRow5Column3 ()))
185
195
.toLeftOf (By .xpath (challengingDomForm .getLocatorCellRow5Column7 ()))
186
- .above (By .xpath (challengingDomForm .getLocatorCellRow7Column5 ()))
187
- );
196
+ .above (By .xpath (challengingDomForm .getLocatorCellRow7Column5 ())));
188
197
189
198
checkDifferentTypesWithSoftAssert (
190
199
actualCellRaw5Column5GotWithAqualityElement .getText (),
@@ -194,6 +203,33 @@ public void testAboveBelowLeftRight() {
194
203
cellInRow5Column5 .getText ());
195
204
}
196
205
206
+ @ Test
207
+ public void testNear () {
208
+ ILabel actualCellRaw2Column1GotWithAqualityElement =
209
+ elementFactory .getLabel (with (By .xpath (labelLocatorCell )).near (challengingDomForm .getCellInRow1Column1 ()),
210
+ nameElementRow2Column1 );
211
+
212
+ ILabel actualCellRaw2Column1GotWithWebElement =
213
+ elementFactory .getLabel (with (By .xpath (labelLocatorCell )).near (challengingDomForm .getCellInRow1Column1 ().getElement ()),
214
+ nameElementRow2Column1 );
215
+
216
+ ILabel actualCellRaw2Column1GotWithXpath =
217
+ elementFactory .getLabel (with (By .xpath (labelLocatorCell )).near (By .xpath (challengingDomForm .getLocatorCellRow1Column1 ())),
218
+ nameElementRow2Column1 );
219
+
220
+
221
+ WebElement actualWebElementCellRaw2Column1GotBySeleniumRelative =
222
+ getBrowser ().getDriver ().findElement (RelativeLocator .with (By .xpath (labelLocatorCell ))
223
+ .near (By .xpath (challengingDomForm .getLocatorCellRow1Column1 ())));
224
+
225
+ checkDifferentTypesWithSoftAssert (
226
+ actualCellRaw2Column1GotWithAqualityElement .getText (),
227
+ actualCellRaw2Column1GotWithWebElement .getText (),
228
+ actualCellRaw2Column1GotWithXpath .getText (),
229
+ actualWebElementCellRaw2Column1GotBySeleniumRelative .getText (),
230
+ challengingDomForm .getCellInRow2Column1 ().getText ());
231
+ }
232
+
197
233
public void checkDifferentTypesWithSoftAssert (String textAquality , String textWebElement , String textByXpath , String textSelenium , String expectedText ) {
198
234
SoftAssert softAssert = new SoftAssert ();
199
235
softAssert .assertEquals (textAquality , expectedText , friendlyMessage );
0 commit comments