Skip to content

Commit 2f5fe33

Browse files
committed
[Feature/Add_Relative_Locators] Add ChallengingDomForm class as page
1 parent 2d6ed48 commit 2f5fe33

File tree

2 files changed

+97
-39
lines changed

2 files changed

+97
-39
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package automationpractice.forms;
2+
3+
import aquality.selenium.elements.interfaces.ILabel;
4+
import aquality.selenium.forms.Form;
5+
import org.openqa.selenium.By;
6+
7+
public class ChallengingDomForm extends Form {
8+
9+
private final String locatorCellRow5Column5 = "//tr[5]/td[5]";
10+
private final String locatorCellRow3Column5 = "//tr[3]/td[5]";
11+
private final String locatorCellRow7Column5 = "//tr[7]/td[5]";
12+
private final String locatorCellRow5Column3 = "//tr[5]/td[3]";
13+
private final String locatorCellRow5Column7 = "//tr[5]/td[7]";
14+
15+
private ILabel cellInRow3Column5 = getElementFactory().getLabel(By.xpath(locatorCellRow3Column5), "CellInRow3Column5");
16+
private ILabel cellInRow5Column5 = getElementFactory().getLabel(By.xpath(locatorCellRow5Column5), "CellInRow5Column5");
17+
private ILabel cellInRow7Column5 = getElementFactory().getLabel(By.xpath(locatorCellRow7Column5), "CellInRow7Column5");
18+
private ILabel cellInRow5Column7 = getElementFactory().getLabel(By.xpath(locatorCellRow5Column7), "CellInRow5Column7");
19+
private ILabel cellInRow5Column3 = getElementFactory().getLabel(By.xpath(locatorCellRow5Column3), "CellInRow5Column3");
20+
21+
public ChallengingDomForm() {
22+
super(By.xpath("//h3[contains(text(),'Challenging DOM')]"), "Challenging DOM");
23+
}
24+
25+
public ILabel getCellInRow3Column5() {
26+
return cellInRow3Column5;
27+
}
28+
29+
public ILabel getCellInRow5Column5() {
30+
return cellInRow5Column5;
31+
}
32+
33+
public ILabel getCellInRow7Column5() {
34+
return cellInRow7Column5;
35+
}
36+
37+
public ILabel getCellInRow5Column7() {
38+
return cellInRow5Column7;
39+
}
40+
41+
public ILabel getCellInRow5Column3() {
42+
return cellInRow5Column3;
43+
}
44+
45+
public String getLocatorCellRow5Column5() {
46+
return locatorCellRow5Column5;
47+
}
48+
49+
public String getLocatorCellRow3Column5() {
50+
return locatorCellRow3Column5;
51+
}
52+
53+
public String getLocatorCellRow7Column5() {
54+
return locatorCellRow7Column5;
55+
}
56+
57+
public String getLocatorCellRow5Column3() {
58+
return locatorCellRow5Column3;
59+
}
60+
61+
public String getLocatorCellRow5Column7() {
62+
return locatorCellRow5Column7;
63+
}
64+
}

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

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package tests.integration;
22

33
import aquality.selenium.elements.interfaces.ILabel;
4+
import automationpractice.forms.ChallengingDomForm;
45
import org.openqa.selenium.By;
56
import org.openqa.selenium.WebElement;
67
import org.openqa.selenium.support.locators.RelativeLocator;
@@ -13,12 +14,8 @@
1314
import static aquality.selenium.locators.RelativeBySupplier.with;
1415

1516
public class LocatorTests extends BaseTest {
17+
private final ChallengingDomForm challengingDomForm = new ChallengingDomForm();
1618
private final String labelLocatorCell = "//td";
17-
private final String labelLocatorCellRow5Column5 = "//tr[5]/td[5]";
18-
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]";
2219
private final String nameElementRow3Column5 = "expectedRow3Column5GotWithByXpath";
2320
private final String nameElementRow7Column5 = "expectedRow7Column5GotWithByXpath";
2421
private final String nameElementRow5Column3 = "expectedRow5Column3GotWithByXpath";
@@ -33,12 +30,11 @@ public void beforeMethod() {
3330

3431
@Test
3532
public void testAboveLocatorWithDifferentAboveParametersType() {
36-
37-
ILabel cellInRow3Column5 = elementFactory.getLabel(By.xpath(labelLocatorCellRow3Column5), "CellInRow3Column5");
38-
ILabel cellInRow5Column5 = elementFactory.getLabel(By.xpath(labelLocatorCellRow5Column5), "CellInRow5Column5");
33+
ILabel cellInRow3Column5 = challengingDomForm.getCellInRow3Column5();
34+
ILabel cellInRow5Column5 = challengingDomForm.getCellInRow5Column5();
3935

4036
ILabel actualCellRaw3Column5GotWithByXpath =
41-
elementFactory.getLabel(with(By.xpath(labelLocatorCell)).above(By.xpath(labelLocatorCellRow5Column5)),
37+
elementFactory.getLabel(with(By.xpath(labelLocatorCell)).above(By.xpath(challengingDomForm.getLocatorCellRow5Column5())),
4238
nameElementRow3Column5);
4339

4440
ILabel actualCellRaw3Column5GotWithWebElement =
@@ -50,7 +46,7 @@ public void testAboveLocatorWithDifferentAboveParametersType() {
5046
nameElementRow3Column5);
5147

5248
WebElement actualWebElementCellRaw3Column5GotBySeleniumRelative =
53-
getBrowser().getDriver().findElement(RelativeLocator.with(By.xpath(labelLocatorCell)).above(By.xpath(labelLocatorCellRow5Column5)));
49+
getBrowser().getDriver().findElement(RelativeLocator.with(By.xpath(labelLocatorCell)).above(By.xpath(challengingDomForm.getLocatorCellRow5Column5())));
5450

5551
checkDifferentTypesWithSoftAssert(
5652
actualCellRaw3Column5GotWithAqualityElement.getText(),
@@ -63,11 +59,11 @@ public void testAboveLocatorWithDifferentAboveParametersType() {
6359
@Test
6460
public void testBelowLocatorWithDifferentBelowParametersType () {
6561

66-
ILabel cellInRow7Column5 = elementFactory.getLabel(By.xpath(labelLocatorCellRow7Column5), "CellInRow7Column5");
67-
ILabel cellInRow5Column5 = elementFactory.getLabel(By.xpath(labelLocatorCellRow5Column5), "CellInRow5Column5");
62+
ILabel cellInRow7Column5 = challengingDomForm.getCellInRow7Column5();
63+
ILabel cellInRow5Column5 = challengingDomForm.getCellInRow5Column5();
6864

6965
ILabel actualCellRaw7Column5GotWithByXpath =
70-
elementFactory.getLabel(with(By.xpath(labelLocatorCell)).below(By.xpath(labelLocatorCellRow5Column5)),
66+
elementFactory.getLabel(with(By.xpath(labelLocatorCell)).below(By.xpath(challengingDomForm.getLocatorCellRow5Column5())),
7167
nameElementRow7Column5);
7268

7369
ILabel actualCellRaw7Column5GotWithWebElement =
@@ -79,7 +75,7 @@ public void testBelowLocatorWithDifferentBelowParametersType () {
7975
nameElementRow7Column5);
8076

8177
WebElement actualWebElementCellRaw7Column5GotBySeleniumRelative =
82-
getBrowser().getDriver().findElement(RelativeLocator.with(By.xpath(labelLocatorCell)).below(By.xpath(labelLocatorCellRow5Column5)));
78+
getBrowser().getDriver().findElement(RelativeLocator.with(By.xpath(labelLocatorCell)).below(By.xpath(challengingDomForm.getLocatorCellRow5Column5())));
8379

8480
checkDifferentTypesWithSoftAssert(
8581
actualCellRaw7Column5GotWithAqualityElement.getText(),
@@ -93,11 +89,11 @@ public void testBelowLocatorWithDifferentBelowParametersType () {
9389
@Test
9490
public void testToLeftOfLocatorWithDifferentToLeftOfParametersType () {
9591

96-
ILabel cellInRow5Column3 = elementFactory.getLabel(By.xpath(labelLocatorCellRow5Column3), "CellInRow5Column3");
97-
ILabel cellInRow5Column5 = elementFactory.getLabel(By.xpath(labelLocatorCellRow5Column5), "CellInRow5Column5");
92+
ILabel cellInRow5Column3 = challengingDomForm.getCellInRow5Column3();
93+
ILabel cellInRow5Column5 = challengingDomForm.getCellInRow5Column5();
9894

9995
ILabel actualCellRaw5Column3GotWithByXpath =
100-
elementFactory.getLabel(with(By.xpath(labelLocatorCell)).toLeftOf(By.xpath(labelLocatorCellRow5Column5)),
96+
elementFactory.getLabel(with(By.xpath(labelLocatorCell)).toLeftOf(By.xpath(challengingDomForm.getLocatorCellRow5Column5())),
10197
nameElementRow5Column3);
10298

10399
ILabel actualCellRaw5Column3GotWithWebElement =
@@ -109,7 +105,7 @@ public void testToLeftOfLocatorWithDifferentToLeftOfParametersType () {
109105
nameElementRow5Column3);
110106

111107
WebElement actualWebElementCellRaw5Column3GotBySeleniumRelative =
112-
getBrowser().getDriver().findElement(RelativeLocator.with(By.xpath(labelLocatorCell)).toLeftOf(By.xpath(labelLocatorCellRow5Column5)));
108+
getBrowser().getDriver().findElement(RelativeLocator.with(By.xpath(labelLocatorCell)).toLeftOf(By.xpath(challengingDomForm.getLocatorCellRow5Column5())));
113109

114110
checkDifferentTypesWithSoftAssert(
115111
actualCellRaw5Column3GotWithAqualityElement.getText(),
@@ -121,12 +117,11 @@ public void testToLeftOfLocatorWithDifferentToLeftOfParametersType () {
121117

122118
@Test
123119
public void testToRightOfLocatorWithDifferentToRightOfParametersType () {
124-
125-
ILabel cellInRow5Column7 = elementFactory.getLabel(By.xpath(labelLocatorCellRow5Column7), "CellInRow5Column7");
126-
ILabel cellInRow5Column5 = elementFactory.getLabel(By.xpath(labelLocatorCellRow5Column5), "CellInRow5Column5");
120+
ILabel cellInRow5Column7 = challengingDomForm.getCellInRow5Column7();
121+
ILabel cellInRow5Column5 = challengingDomForm.getCellInRow5Column5();
127122

128123
ILabel actualCellRaw5Column7GotWithByXpath =
129-
elementFactory.getLabel(with(By.xpath(labelLocatorCell)).toRightOf(By.xpath(labelLocatorCellRow5Column5)),
124+
elementFactory.getLabel(with(By.xpath(labelLocatorCell)).toRightOf(By.xpath(challengingDomForm.getLocatorCellRow5Column5())),
130125
nameElementRow5Column7);
131126

132127
ILabel actualCellRaw5Column7GotWithWebElement =
@@ -138,7 +133,7 @@ public void testToRightOfLocatorWithDifferentToRightOfParametersType () {
138133
nameElementRow5Column3);
139134

140135
WebElement actualWebElementCellRaw5Column7GotBySeleniumRelative =
141-
getBrowser().getDriver().findElement(RelativeLocator.with(By.xpath(labelLocatorCell)).toRightOf(By.xpath(labelLocatorCellRow5Column5)));
136+
getBrowser().getDriver().findElement(RelativeLocator.with(By.xpath(labelLocatorCell)).toRightOf(By.xpath(challengingDomForm.getLocatorCellRow5Column5())));
142137

143138
checkDifferentTypesWithSoftAssert(
144139
actualCellRaw5Column7GotWithAqualityElement.getText(),
@@ -150,12 +145,11 @@ public void testToRightOfLocatorWithDifferentToRightOfParametersType () {
150145

151146
@Test
152147
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");
148+
ILabel cellInRow3Column5 = challengingDomForm.getCellInRow3Column5();
149+
ILabel cellInRow5Column7 = challengingDomForm.getCellInRow5Column7();
150+
ILabel cellInRow5Column5 = challengingDomForm.getCellInRow5Column5();
151+
ILabel cellInRow5Column3 = challengingDomForm.getCellInRow5Column3();
152+
ILabel cellInRow7Column5 = challengingDomForm.getCellInRow7Column5();
159153

160154
ILabel actualCellRaw5Column5GotWithAqualityElement =
161155
elementFactory.getLabel(with(By.xpath(labelLocatorCell))
@@ -176,20 +170,20 @@ public void testAboveBelowLeftRight() {
176170

177171
ILabel actualCellRaw5Column5GotWithXpath =
178172
elementFactory.getLabel(with(By.xpath(labelLocatorCell))
179-
.above(By.xpath(labelLocatorCellRow7Column5))
180-
.below(By.xpath(labelLocatorCellRow3Column5))
181-
.toRightOf(By.xpath(labelLocatorCellRow5Column3))
182-
.toLeftOf(By.xpath(labelLocatorCellRow5Column7))
183-
.above(By.xpath(labelLocatorCellRow7Column5))
173+
.above(By.xpath(challengingDomForm.getLocatorCellRow7Column5()))
174+
.below(By.xpath(challengingDomForm.getLocatorCellRow3Column5()))
175+
.toRightOf(By.xpath(challengingDomForm.getLocatorCellRow5Column3()))
176+
.toLeftOf(By.xpath(challengingDomForm.getLocatorCellRow5Column7()))
177+
.above(By.xpath(challengingDomForm.getLocatorCellRow7Column5()))
184178
, nameElementRow5Column5);
185179

186180
WebElement actualWebElementCellRaw5Column5GotBySeleniumRelative =
187181
getBrowser().getDriver().findElement(RelativeLocator.with(By.xpath(labelLocatorCell))
188-
.above(By.xpath(labelLocatorCellRow7Column5))
189-
.below(By.xpath(labelLocatorCellRow3Column5))
190-
.toRightOf(By.xpath(labelLocatorCellRow5Column3))
191-
.toLeftOf(By.xpath(labelLocatorCellRow5Column7))
192-
.above(By.xpath(labelLocatorCellRow7Column5))
182+
.above(By.xpath(challengingDomForm.getLocatorCellRow7Column5()))
183+
.below(By.xpath(challengingDomForm.getLocatorCellRow3Column5()))
184+
.toRightOf(By.xpath(challengingDomForm.getLocatorCellRow5Column3()))
185+
.toLeftOf(By.xpath(challengingDomForm.getLocatorCellRow5Column7()))
186+
.above(By.xpath(challengingDomForm.getLocatorCellRow7Column5()))
193187
);
194188

195189
checkDifferentTypesWithSoftAssert(

0 commit comments

Comments
 (0)