Skip to content

Commit 2592e61

Browse files
committed
[Feature/Add_Relative_Locators] Add test to near relative locator
1 parent 2f5fe33 commit 2592e61

File tree

2 files changed

+85
-19
lines changed

2 files changed

+85
-19
lines changed

src/test/java/automationpractice/forms/ChallengingDomForm.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,18 @@ public class ChallengingDomForm extends Form {
1111
private final String locatorCellRow7Column5 = "//tr[7]/td[5]";
1212
private final String locatorCellRow5Column3 = "//tr[5]/td[3]";
1313
private final String locatorCellRow5Column7 = "//tr[5]/td[7]";
14+
private final String locatorCellRow4Column5 = "//tr[4]/td[5]";
15+
private final String locatorCellRow1Column1 = "//tr[1]/td[1]";
16+
private final String locatorCellRow2Column1 = "//tr[2]/td[1]";
1417

1518
private ILabel cellInRow3Column5 = getElementFactory().getLabel(By.xpath(locatorCellRow3Column5), "CellInRow3Column5");
1619
private ILabel cellInRow5Column5 = getElementFactory().getLabel(By.xpath(locatorCellRow5Column5), "CellInRow5Column5");
1720
private ILabel cellInRow7Column5 = getElementFactory().getLabel(By.xpath(locatorCellRow7Column5), "CellInRow7Column5");
1821
private ILabel cellInRow5Column7 = getElementFactory().getLabel(By.xpath(locatorCellRow5Column7), "CellInRow5Column7");
1922
private ILabel cellInRow5Column3 = getElementFactory().getLabel(By.xpath(locatorCellRow5Column3), "CellInRow5Column3");
23+
private ILabel cellInRow4Column5 = getElementFactory().getLabel(By.xpath(locatorCellRow4Column5), "CellInRow4Column5");
24+
private ILabel cellInRow1Column1 = getElementFactory().getLabel(By.xpath(locatorCellRow1Column1), "CellInRow1Column1");
25+
private ILabel cellInRow2Column1 = getElementFactory().getLabel(By.xpath(locatorCellRow2Column1), "CellInRow2Column1");
2026

2127
public ChallengingDomForm() {
2228
super(By.xpath("//h3[contains(text(),'Challenging DOM')]"), "Challenging DOM");
@@ -42,6 +48,30 @@ public ILabel getCellInRow5Column3() {
4248
return cellInRow5Column3;
4349
}
4450

51+
public ILabel getCellInRow4Column5() {
52+
return cellInRow4Column5;
53+
}
54+
55+
public ILabel getCellInRow1Column1() {
56+
return cellInRow1Column1;
57+
}
58+
59+
public ILabel getCellInRow2Column1() {
60+
return cellInRow2Column1;
61+
}
62+
63+
public String getLocatorCellRow4Column5() {
64+
return locatorCellRow4Column5;
65+
}
66+
67+
public String getLocatorCellRow1Column1() {
68+
return locatorCellRow1Column1;
69+
}
70+
71+
public String getLocatorCellRow2Column1() {
72+
return locatorCellRow2Column1;
73+
}
74+
4575
public String getLocatorCellRow5Column5() {
4676
return locatorCellRow5Column5;
4777
}

src/test/java/tests/integration/LocatorTests.java

Lines changed: 55 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
public 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

Comments
 (0)