44import org .openqa .selenium .By ;
55import org .openqa .selenium .WebElement ;
66import org .openqa .selenium .support .locators .RelativeLocator ;
7+ import org .testng .annotations .BeforeMethod ;
78import org .testng .annotations .Test ;
89import org .testng .asserts .SoftAssert ;
910import tests .BaseTest ;
@@ -15,14 +16,25 @@ public class LocatorTests extends BaseTest {
1516 private final String labelLocatorCell = "//td" ;
1617 private final String labelLocatorCellRow5Column5 = "//tr[5]/td[5]" ;
1718 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]" ;
1822 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" ;
1927 private final String friendlyMessage = "Actual cell text is not equal expected" ;
2028
29+ @ BeforeMethod
30+ public void beforeMethod () {
31+ navigate (TheInternetPage .CHALLENGING_DOM );
32+ }
33+
2134 @ Test
2235 public void testAboveLocatorWithDifferentAboveParametersType () {
23- navigate (TheInternetPage .CHALLENGING_DOM );
2436
25- ILabel cellInRow3Column5 = elementFactory .getLabel (By .xpath (labelLocatorCellRow3Column5 ), "CellInRow4Column5 " );
37+ ILabel cellInRow3Column5 = elementFactory .getLabel (By .xpath (labelLocatorCellRow3Column5 ), "CellInRow3Column5 " );
2638 ILabel cellInRow5Column5 = elementFactory .getLabel (By .xpath (labelLocatorCellRow5Column5 ), "CellInRow5Column5" );
2739
2840 ILabel actualCellRaw3Column5GotWithByXpath =
@@ -48,6 +60,125 @@ public void testAboveLocatorWithDifferentAboveParametersType() {
4860 cellInRow3Column5 .getText ());
4961 }
5062
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+
51182 public void checkDifferentTypesWithSoftAssert (String textAquality , String textWebElement , String textByXpath , String textSelenium , String expectedText ) {
52183 SoftAssert softAssert = new SoftAssert ();
53184 softAssert .assertEquals (textAquality , expectedText , friendlyMessage );
0 commit comments