10
10
import org .testng .asserts .SoftAssert ;
11
11
import tests .BaseTest ;
12
12
import theinternet .TheInternetPage ;
13
-
13
+ import java . util . List ;
14
14
import static aquality .selenium .locators .RelativeBySupplier .with ;
15
15
16
16
public class LocatorTests extends BaseTest {
@@ -22,7 +22,11 @@ public class LocatorTests extends BaseTest {
22
22
private final String nameElementRow5Column7 = "expectedRow5Column7" ;
23
23
private final String nameElementRow5Column5 = "expectedRow5Column5" ;
24
24
private final String nameElementRow2Column1 = "expectedRow2Column1" ;
25
- private final String friendlyMessage = "Actual cell text is not equal expected" ;
25
+ private final String nameElementHeaderOfPage = "Challenging Dom" ;
26
+ private final String friendlyMessageEquallingText = "Actual cell text is not equal expected" ;
27
+ private final String friendlyMessageElementFound = "Element with not reachable distance is exist" ;
28
+ private final int positiveDistance = 300 ;
29
+ private final int negativeDistance = 100 ;
26
30
27
31
@ BeforeMethod
28
32
public void beforeMethod () {
@@ -31,7 +35,6 @@ public void beforeMethod() {
31
35
32
36
@ Test
33
37
public void testAboveLocatorWithDifferentAboveParametersType () {
34
- ILabel cellInRow3Column5 = challengingDomForm .getCellInRow3Column5 ();
35
38
ILabel cellInRow5Column5 = challengingDomForm .getCellInRow5Column5 ();
36
39
37
40
ILabel actualCellRaw3Column5GotWithByXpath =
@@ -56,13 +59,11 @@ public void testAboveLocatorWithDifferentAboveParametersType() {
56
59
actualCellRaw3Column5GotWithWebElement .getText (),
57
60
actualCellRaw3Column5GotWithByXpath .getText (),
58
61
actualWebElementCellRaw3Column5GotBySeleniumRelative .getText (),
59
- cellInRow3Column5 .getText ());
62
+ challengingDomForm . getCellInRow3Column5 () .getText ());
60
63
}
61
64
62
65
@ Test
63
66
public void testBelowLocatorWithDifferentBelowParametersType () {
64
-
65
- ILabel cellInRow7Column5 = challengingDomForm .getCellInRow7Column5 ();
66
67
ILabel cellInRow5Column5 = challengingDomForm .getCellInRow5Column5 ();
67
68
68
69
ILabel actualCellRaw7Column5GotWithByXpath =
@@ -87,14 +88,12 @@ public void testBelowLocatorWithDifferentBelowParametersType() {
87
88
actualCellRaw7Column5GotWithWebElement .getText (),
88
89
actualCellRaw7Column5GotWithByXpath .getText (),
89
90
actualWebElementCellRaw7Column5GotBySeleniumRelative .getText (),
90
- cellInRow7Column5 .getText ());
91
+ challengingDomForm . getCellInRow7Column5 () .getText ());
91
92
}
92
93
93
94
94
95
@ Test
95
96
public void testToLeftOfLocatorWithDifferentToLeftOfParametersType () {
96
-
97
- ILabel cellInRow5Column3 = challengingDomForm .getCellInRow5Column3 ();
98
97
ILabel cellInRow5Column5 = challengingDomForm .getCellInRow5Column5 ();
99
98
100
99
ILabel actualCellRaw5Column3GotWithByXpath =
@@ -119,12 +118,11 @@ public void testToLeftOfLocatorWithDifferentToLeftOfParametersType() {
119
118
actualCellRaw5Column3GotWithWebElement .getText (),
120
119
actualCellRaw5Column3GotWithByXpath .getText (),
121
120
actualWebElementCellRaw5Column3GotBySeleniumRelative .getText (),
122
- cellInRow5Column3 .getText ());
121
+ challengingDomForm . getCellInRow5Column3 () .getText ());
123
122
}
124
123
125
124
@ Test
126
125
public void testToRightOfLocatorWithDifferentToRightOfParametersType () {
127
- ILabel cellInRow5Column7 = challengingDomForm .getCellInRow5Column7 ();
128
126
ILabel cellInRow5Column5 = challengingDomForm .getCellInRow5Column5 ();
129
127
130
128
ILabel actualCellRaw5Column7GotWithByXpath =
@@ -149,7 +147,7 @@ public void testToRightOfLocatorWithDifferentToRightOfParametersType() {
149
147
actualCellRaw5Column7GotWithWebElement .getText (),
150
148
actualCellRaw5Column7GotWithByXpath .getText (),
151
149
actualWebElementCellRaw5Column7GotBySeleniumRelative .getText (),
152
- cellInRow5Column7 .getText ());
150
+ challengingDomForm . getCellInRow5Column7 () .getText ());
153
151
}
154
152
155
153
@ Test
@@ -197,8 +195,8 @@ public void testAboveBelowLeftRight() {
197
195
198
196
checkDifferentTypesWithSoftAssert (
199
197
actualCellRaw5Column5GotWithAqualityElement .getText (),
200
- actualCellRaw5Column5GotWithXpath .getText (),
201
198
actualCellRaw5Column5GotWithWebElement .getText (),
199
+ actualCellRaw5Column5GotWithXpath .getText (),
202
200
actualWebElementCellRaw5Column5GotBySeleniumRelative .getText (),
203
201
cellInRow5Column5 .getText ());
204
202
}
@@ -230,12 +228,72 @@ public void testNear() {
230
228
challengingDomForm .getCellInRow2Column1 ().getText ());
231
229
}
232
230
231
+ @ Test
232
+ public void testNearWithDistance () {
233
+ ILabel actualHeaderNameGotWithAqualityElement =
234
+ elementFactory .getLabel (with (By .xpath (ChallengingDomForm .LOCATOR_CHALLENGING_DOM_FORM ))
235
+ .near (challengingDomForm .getCellInRow1Column1 (), positiveDistance ),
236
+ nameElementHeaderOfPage );
237
+
238
+ ILabel actualHeaderNameGotWithWebElement =
239
+ elementFactory .getLabel (with (By .xpath (ChallengingDomForm .LOCATOR_CHALLENGING_DOM_FORM ))
240
+ .near (challengingDomForm .getCellInRow1Column1 ().getElement (), positiveDistance ),
241
+ nameElementHeaderOfPage );
242
+
243
+ ILabel actualHeaderNameGotWithXpath =
244
+ elementFactory .getLabel (with (By .xpath (ChallengingDomForm .LOCATOR_CHALLENGING_DOM_FORM ))
245
+ .near (By .xpath (challengingDomForm .getLocatorCellRow1Column1 ()), positiveDistance ),
246
+ nameElementHeaderOfPage );
247
+
248
+
249
+ WebElement actualWebElementHeaderNameGotBySeleniumRelative =
250
+ getBrowser ().getDriver ().findElement (RelativeLocator .with (By .xpath (ChallengingDomForm .LOCATOR_CHALLENGING_DOM_FORM ))
251
+ .near (getBrowser ().getDriver ().findElement (By .xpath (challengingDomForm .getLocatorCellRow1Column1 ())),positiveDistance ));
252
+
253
+ checkDifferentTypesWithSoftAssert (
254
+ actualHeaderNameGotWithAqualityElement .getText (),
255
+ actualHeaderNameGotWithWebElement .getText (),
256
+ actualHeaderNameGotWithXpath .getText (),
257
+ actualWebElementHeaderNameGotBySeleniumRelative .getText (),
258
+ challengingDomForm .getHeaderName ().getText ());
259
+ }
260
+
261
+ @ Test
262
+ public void testNearWithDistanceNegative () {
263
+ ILabel actualHeaderNameGotWithAqualityElement =
264
+ elementFactory .getLabel (with (By .xpath (ChallengingDomForm .LOCATOR_CHALLENGING_DOM_FORM ))
265
+ .near (challengingDomForm .getCellInRow1Column1 (), negativeDistance ),
266
+ nameElementHeaderOfPage );
267
+
268
+ ILabel actualHeaderNameGotWithWebElement =
269
+ elementFactory .getLabel (with (By .xpath (ChallengingDomForm .LOCATOR_CHALLENGING_DOM_FORM ))
270
+ .near (challengingDomForm .getCellInRow1Column1 ().getElement (), negativeDistance ),
271
+ nameElementHeaderOfPage );
272
+
273
+ ILabel actualHeaderNameGotWithXpath =
274
+ elementFactory .getLabel (with (By .xpath (ChallengingDomForm .LOCATOR_CHALLENGING_DOM_FORM ))
275
+ .near (By .xpath (challengingDomForm .getLocatorCellRow1Column1 ()), negativeDistance ),
276
+ nameElementHeaderOfPage );
277
+
278
+
279
+ List <WebElement > actualsWebElementsHeaderNameGotBySeleniumRelative =
280
+ getBrowser ().getDriver ().findElements (RelativeLocator .with (By .xpath (ChallengingDomForm .LOCATOR_CHALLENGING_DOM_FORM ))
281
+ .near (getBrowser ().getDriver ().findElement (By .xpath (challengingDomForm .getLocatorCellRow1Column1 ())), negativeDistance ));
282
+
283
+ SoftAssert softAssert = new SoftAssert ();
284
+ softAssert .assertFalse (actualHeaderNameGotWithAqualityElement .state ().isExist (), friendlyMessageElementFound );
285
+ softAssert .assertFalse (actualHeaderNameGotWithWebElement .state ().isExist (), friendlyMessageElementFound );
286
+ softAssert .assertFalse (actualHeaderNameGotWithXpath .state ().isExist (), friendlyMessageElementFound );
287
+ softAssert .assertEquals (actualsWebElementsHeaderNameGotBySeleniumRelative .size (),0 , "Elements with not reachable distance was found" );
288
+ softAssert .assertAll ();
289
+ }
290
+
233
291
public void checkDifferentTypesWithSoftAssert (String textAquality , String textWebElement , String textByXpath , String textSelenium , String expectedText ) {
234
292
SoftAssert softAssert = new SoftAssert ();
235
- softAssert .assertEquals (textAquality , expectedText , friendlyMessage );
236
- softAssert .assertEquals (textByXpath , expectedText , friendlyMessage );
237
- softAssert .assertEquals (textWebElement , expectedText , friendlyMessage );
238
- softAssert .assertEquals (textSelenium , expectedText , friendlyMessage );
293
+ softAssert .assertEquals (textAquality , expectedText , friendlyMessageEquallingText );
294
+ softAssert .assertEquals (textByXpath , expectedText , friendlyMessageEquallingText );
295
+ softAssert .assertEquals (textWebElement , expectedText , friendlyMessageEquallingText );
296
+ softAssert .assertEquals (textSelenium , expectedText , friendlyMessageEquallingText );
239
297
softAssert .assertAll ();
240
298
}
241
299
}
0 commit comments