Skip to content

Commit 7dac504

Browse files
authored
Merge pull request #111 from aquality-automation/Feature/Add_Relative_Locators
Feature/add relative locators
2 parents d2d296e + 3fb1c6c commit 7dac504

File tree

9 files changed

+549
-1
lines changed

9 files changed

+549
-1
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package aquality.selenium.locators;
2+
3+
import org.openqa.selenium.By;
4+
5+
public interface IRelativeBy {
6+
RelativeBy above(By by);
7+
RelativeBy below(By by);
8+
RelativeBy toLeftOf(By by);
9+
RelativeBy toRightOf(By by);
10+
RelativeBy near(By by);
11+
RelativeBy near(By by, int atMostDistanceInPixels);
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package aquality.selenium.locators;
2+
3+
import aquality.selenium.elements.interfaces.IElement;
4+
5+
public interface IRelativeByAqualityElement {
6+
RelativeBy above(IElement element);
7+
RelativeBy below(IElement element);
8+
RelativeBy toLeftOf(IElement element);
9+
RelativeBy toRightOf(IElement element);
10+
RelativeBy near(IElement element);
11+
RelativeBy near(IElement element, int atMostDistanceInPixels);
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package aquality.selenium.locators;
2+
3+
import org.openqa.selenium.WebElement;
4+
5+
public interface IRelativeByWebElement {
6+
RelativeBy above(WebElement element);
7+
RelativeBy below(WebElement element);
8+
RelativeBy toLeftOf(WebElement element);
9+
RelativeBy toRightOf(WebElement element);
10+
RelativeBy near(WebElement element);
11+
RelativeBy near(WebElement element, int atMostDistanceInPixels);
12+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
package aquality.selenium.locators;
2+
3+
import aquality.selenium.elements.interfaces.IElement;
4+
import org.openqa.selenium.By;
5+
import org.openqa.selenium.SearchContext;
6+
import org.openqa.selenium.WebElement;
7+
import org.openqa.selenium.support.locators.RelativeLocator;
8+
import java.util.List;
9+
10+
public class RelativeBy extends By implements IRelativeByAqualityElement, IRelativeByWebElement, IRelativeBy {
11+
private By by;
12+
13+
public RelativeBy(By by) {
14+
this.by = by;
15+
}
16+
17+
public RelativeBy above(IElement element) {
18+
by = RelativeLocator.with(by).above(element.getLocator());
19+
return new RelativeBy(by);
20+
}
21+
22+
public RelativeBy above(WebElement element) {
23+
by = RelativeLocator.with(by).above(element);
24+
return new RelativeBy(by);
25+
}
26+
27+
public RelativeBy above(By by) {
28+
this.by = RelativeLocator.with(this.by).above(by);
29+
return new RelativeBy(this.by);
30+
}
31+
32+
public RelativeBy below(IElement element) {
33+
by = RelativeLocator.with(by).below(element.getLocator());
34+
return new RelativeBy(by);
35+
}
36+
37+
public RelativeBy below(WebElement element) {
38+
by = RelativeLocator.with(by).below(element);
39+
return new RelativeBy(by);
40+
}
41+
42+
public RelativeBy below(By by) {
43+
this.by = RelativeLocator.with(this.by).below(by);
44+
return new RelativeBy(this.by);
45+
}
46+
47+
public RelativeBy toLeftOf(IElement element) {
48+
by = RelativeLocator.with(by).toLeftOf(element.getLocator());
49+
return new RelativeBy(by);
50+
}
51+
52+
public RelativeBy toLeftOf(WebElement element) {
53+
by = RelativeLocator.with(by).toLeftOf(element);
54+
return new RelativeBy(by);
55+
}
56+
57+
public RelativeBy toLeftOf(By by) {
58+
this.by = RelativeLocator.with(this.by).toLeftOf(by);
59+
return new RelativeBy(this.by);
60+
}
61+
62+
public RelativeBy toRightOf(IElement element) {
63+
by = RelativeLocator.with(by).toRightOf(element.getLocator());
64+
return new RelativeBy(by);
65+
}
66+
67+
public RelativeBy toRightOf(WebElement element) {
68+
by = RelativeLocator.with(by).toRightOf(element);
69+
return new RelativeBy(by);
70+
}
71+
72+
public RelativeBy toRightOf(By by) {
73+
this.by = RelativeLocator.with(this.by).toRightOf(by);
74+
return new RelativeBy(this.by);
75+
}
76+
77+
public RelativeBy near(IElement element) {
78+
by = RelativeLocator.with(by).near(element.getLocator());
79+
return new RelativeBy(by);
80+
}
81+
82+
public RelativeBy near(WebElement element) {
83+
by = RelativeLocator.with(by).near(element);
84+
return new RelativeBy(by);
85+
}
86+
87+
public RelativeBy near(By by) {
88+
this.by = RelativeLocator.with(this.by).near(by);
89+
return new RelativeBy(this.by);
90+
}
91+
92+
public RelativeBy near(IElement element, int atMostDistanceInPixels) {
93+
by = RelativeLocator.with(by).near(element.getLocator(), atMostDistanceInPixels);
94+
return new RelativeBy(by);
95+
}
96+
97+
public RelativeBy near(WebElement element, int atMostDistanceInPixels) {
98+
by = RelativeLocator.with(by).near(element, atMostDistanceInPixels);
99+
return new RelativeBy(by);
100+
}
101+
102+
public RelativeBy near(By by, int atMostDistanceInPixels) {
103+
this.by = RelativeLocator.with(this.by).near(by, atMostDistanceInPixels);
104+
return new RelativeBy(this.by);
105+
}
106+
107+
@Override
108+
public List<WebElement> findElements(SearchContext context) {
109+
return context.findElements(by);
110+
}
111+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package aquality.selenium.locators;
2+
3+
import org.openqa.selenium.By;
4+
5+
public class RelativeBySupplier {
6+
7+
private RelativeBySupplier() {
8+
}
9+
10+
public static RelativeBy with(By by) {
11+
return new RelativeBy(by);
12+
}
13+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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+
public static final String LOCATOR_CHALLENGING_DOM_FORM = "//h3[contains(text(),'Challenging DOM')]";
10+
public static final String ELEMENT_NAME_ROW3_COLUMN5 = "Cell in row 3 column 5";
11+
public static final String ELEMENT_NAME_ROW5_COLUMN5 = "Cell in row 5 column 5";
12+
public static final String ELEMENT_NAME_ROW7_COLUMN5 = "Cell in row 7 column 5";
13+
public static final String ELEMENT_NAME_ROW5_COLUMN7 = "Cell in row 5 column 7";
14+
public static final String ELEMENT_NAME_ROW5_COLUMN3 = "Cell in row 5 column 3";
15+
public static final String ELEMENT_NAME_ROW1_COLUMN1 = "Cell in row 1 column 1";
16+
public static final String ELEMENT_NAME_ROW2_COLUMN1 = "Cell in row 2 column 1";
17+
public static final String ELEMENT_NAME_HEADER_CHALLENGING_DOM = "Header of Challenging Dom";
18+
19+
private final String locatorCellRow5Column5 = "//tr[5]/td[5]";
20+
private final String locatorCellRow3Column5 = "//tr[3]/td[5]";
21+
private final String locatorCellRow7Column5 = "//tr[7]/td[5]";
22+
private final String locatorCellRow5Column3 = "//tr[5]/td[3]";
23+
private final String locatorCellRow5Column7 = "//tr[5]/td[7]";
24+
private final String locatorCellRow1Column1 = "//tr[1]/td[1]";
25+
private final String locatorCellRow2Column1 = "//tr[2]/td[1]";
26+
27+
private ILabel headerName = getElementFactory().getLabel(By.xpath(LOCATOR_CHALLENGING_DOM_FORM), ELEMENT_NAME_HEADER_CHALLENGING_DOM);
28+
private ILabel cellInRow3Column5 = getElementFactory().getLabel(By.xpath(locatorCellRow3Column5), ELEMENT_NAME_ROW3_COLUMN5);
29+
private ILabel cellInRow5Column5 = getElementFactory().getLabel(By.xpath(locatorCellRow5Column5), ELEMENT_NAME_ROW5_COLUMN5);
30+
private ILabel cellInRow7Column5 = getElementFactory().getLabel(By.xpath(locatorCellRow7Column5), ELEMENT_NAME_ROW7_COLUMN5);
31+
private ILabel cellInRow5Column7 = getElementFactory().getLabel(By.xpath(locatorCellRow5Column7), ELEMENT_NAME_ROW5_COLUMN7);
32+
private ILabel cellInRow5Column3 = getElementFactory().getLabel(By.xpath(locatorCellRow5Column3), ELEMENT_NAME_ROW5_COLUMN3);
33+
private ILabel cellInRow1Column1 = getElementFactory().getLabel(By.xpath(locatorCellRow1Column1), ELEMENT_NAME_ROW1_COLUMN1);
34+
private ILabel cellInRow2Column1 = getElementFactory().getLabel(By.xpath(locatorCellRow2Column1), ELEMENT_NAME_ROW2_COLUMN1);
35+
36+
public ChallengingDomForm() {
37+
super(By.xpath(LOCATOR_CHALLENGING_DOM_FORM), "Challenging DOM");
38+
}
39+
40+
public ILabel getCellInRow3Column5() {
41+
return cellInRow3Column5;
42+
}
43+
44+
public ILabel getCellInRow5Column5() {
45+
return cellInRow5Column5;
46+
}
47+
48+
public ILabel getCellInRow7Column5() {
49+
return cellInRow7Column5;
50+
}
51+
52+
public ILabel getCellInRow5Column7() {
53+
return cellInRow5Column7;
54+
}
55+
56+
public ILabel getCellInRow5Column3() {
57+
return cellInRow5Column3;
58+
}
59+
60+
public ILabel getCellInRow1Column1() {
61+
return cellInRow1Column1;
62+
}
63+
64+
public ILabel getCellInRow2Column1() {
65+
return cellInRow2Column1;
66+
}
67+
68+
public ILabel getHeaderName() {
69+
return headerName;
70+
}
71+
72+
public String getLocatorCellRow1Column1() {
73+
return locatorCellRow1Column1;
74+
}
75+
76+
public String getLocatorCellRow5Column5() {
77+
return locatorCellRow5Column5;
78+
}
79+
80+
public String getLocatorCellRow3Column5() {
81+
return locatorCellRow3Column5;
82+
}
83+
84+
public String getLocatorCellRow7Column5() {
85+
return locatorCellRow7Column5;
86+
}
87+
88+
public String getLocatorCellRow5Column3() {
89+
return locatorCellRow5Column3;
90+
}
91+
92+
public String getLocatorCellRow5Column7() {
93+
return locatorCellRow5Column7;
94+
}
95+
}

0 commit comments

Comments
 (0)