1616public class LocatorTests extends BaseTest {
1717 private final ChallengingDomForm challengingDomForm = new ChallengingDomForm ();
1818 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 " ;
2323 private final String nameElementRow5Column5 = "expectedRow5Column5" ;
24+ private final String nameElementRow2Column1 = "expectedRow2Column1" ;
2425 private final String friendlyMessage = "Actual cell text is not equal expected" ;
2526
2627 @ BeforeMethod
@@ -46,7 +47,9 @@ public void testAboveLocatorWithDifferentAboveParametersType() {
4647 nameElementRow3Column5 );
4748
4849 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 ())));
5053
5154 checkDifferentTypesWithSoftAssert (
5255 actualCellRaw3Column5GotWithAqualityElement .getText (),
@@ -57,7 +60,7 @@ public void testAboveLocatorWithDifferentAboveParametersType() {
5760 }
5861
5962 @ Test
60- public void testBelowLocatorWithDifferentBelowParametersType () {
63+ public void testBelowLocatorWithDifferentBelowParametersType () {
6164
6265 ILabel cellInRow7Column5 = challengingDomForm .getCellInRow7Column5 ();
6366 ILabel cellInRow5Column5 = challengingDomForm .getCellInRow5Column5 ();
@@ -75,7 +78,9 @@ public void testBelowLocatorWithDifferentBelowParametersType () {
7578 nameElementRow7Column5 );
7679
7780 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 ())));
7984
8085 checkDifferentTypesWithSoftAssert (
8186 actualCellRaw7Column5GotWithAqualityElement .getText (),
@@ -87,7 +92,7 @@ public void testBelowLocatorWithDifferentBelowParametersType () {
8792
8893
8994 @ Test
90- public void testToLeftOfLocatorWithDifferentToLeftOfParametersType () {
95+ public void testToLeftOfLocatorWithDifferentToLeftOfParametersType () {
9196
9297 ILabel cellInRow5Column3 = challengingDomForm .getCellInRow5Column3 ();
9398 ILabel cellInRow5Column5 = challengingDomForm .getCellInRow5Column5 ();
@@ -105,7 +110,9 @@ public void testToLeftOfLocatorWithDifferentToLeftOfParametersType () {
105110 nameElementRow5Column3 );
106111
107112 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 ())));
109116
110117 checkDifferentTypesWithSoftAssert (
111118 actualCellRaw5Column3GotWithAqualityElement .getText (),
@@ -116,7 +123,7 @@ public void testToLeftOfLocatorWithDifferentToLeftOfParametersType () {
116123 }
117124
118125 @ Test
119- public void testToRightOfLocatorWithDifferentToRightOfParametersType () {
126+ public void testToRightOfLocatorWithDifferentToRightOfParametersType () {
120127 ILabel cellInRow5Column7 = challengingDomForm .getCellInRow5Column7 ();
121128 ILabel cellInRow5Column5 = challengingDomForm .getCellInRow5Column5 ();
122129
@@ -133,7 +140,9 @@ public void testToRightOfLocatorWithDifferentToRightOfParametersType () {
133140 nameElementRow5Column3 );
134141
135142 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 ())));
137146
138147 checkDifferentTypesWithSoftAssert (
139148 actualCellRaw5Column7GotWithAqualityElement .getText (),
@@ -157,15 +166,16 @@ public void testAboveBelowLeftRight() {
157166 .below (cellInRow3Column5 )
158167 .toRightOf (cellInRow5Column3 )
159168 .toLeftOf (cellInRow5Column7 )
160- .above (cellInRow7Column5 ), nameElementRow5Column5 );
169+ .above (cellInRow7Column5 )
170+ , nameElementRow5Column5 );
161171
162172 ILabel actualCellRaw5Column5GotWithWebElement =
163173 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 ())
169179 , nameElementRow5Column5 );
170180
171181 ILabel actualCellRaw5Column5GotWithXpath =
@@ -183,8 +193,7 @@ public void testAboveBelowLeftRight() {
183193 .below (By .xpath (challengingDomForm .getLocatorCellRow3Column5 ()))
184194 .toRightOf (By .xpath (challengingDomForm .getLocatorCellRow5Column3 ()))
185195 .toLeftOf (By .xpath (challengingDomForm .getLocatorCellRow5Column7 ()))
186- .above (By .xpath (challengingDomForm .getLocatorCellRow7Column5 ()))
187- );
196+ .above (By .xpath (challengingDomForm .getLocatorCellRow7Column5 ())));
188197
189198 checkDifferentTypesWithSoftAssert (
190199 actualCellRaw5Column5GotWithAqualityElement .getText (),
@@ -194,6 +203,33 @@ public void testAboveBelowLeftRight() {
194203 cellInRow5Column5 .getText ());
195204 }
196205
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+
197233 public void checkDifferentTypesWithSoftAssert (String textAquality , String textWebElement , String textByXpath , String textSelenium , String expectedText ) {
198234 SoftAssert softAssert = new SoftAssert ();
199235 softAssert .assertEquals (textAquality , expectedText , friendlyMessage );
0 commit comments