Skip to content

Commit d938cc9

Browse files
committed
working on relative locator support
1 parent ed0f23f commit d938cc9

2 files changed

Lines changed: 27 additions & 10 deletions

File tree

src/main/java/org/openqa/selenium/htmlunit/HtmlUnitElementFinder.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -605,10 +605,6 @@ private static List<WebElement> convertRawDomElementsToWebElements(
605605

606606
public static class FindByRelativeLocator extends HtmlUnitElementLocator {
607607

608-
public FindByRelativeLocator() {
609-
610-
}
611-
612608
@Override
613609
public List<WebElement> findElements(final HtmlUnitDriver driver, final By locator) {
614610
return (List<WebElement>) driver.executeScript(FIND_ELEMENTS_JS, asParameter(locator));

src/test/java/org/openqa/selenium/htmlunit/by/RelativeLocatorTest.java

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ public void shouldBeAbleToFindElementsAboveAnotherWithCssSelector() throws Excep
106106

107107
@Test
108108
@Alerts({"1", "third"})
109+
@HtmlUnitNYI(CHROME = "0",
110+
EDGE = "0",
111+
FF = "0",
112+
FF_ESR = "0")
109113
public void shouldBeAbleToCombineFilters() throws Exception {
110114
final String html = getFileContent("relative_locators.html");
111115
final WebDriver driver = loadPage2(html);
@@ -114,12 +118,19 @@ public void shouldBeAbleToCombineFilters() throws Exception {
114118
with(tagName("td")).above(By.id("center")).toRightOf(By.id("second")));
115119
final List<String> ids = seen.stream().map(e -> e.getAttribute("id")).collect(Collectors.toList());
116120

117-
assertEquals(Integer.parseInt(getExpectedAlerts()[0]), ids.size());
118-
assertTrue(ids.contains(getExpectedAlerts()[1]));
121+
final int expectedSize = Integer.parseInt(getExpectedAlerts()[0]);
122+
assertEquals(expectedSize, ids.size());
123+
if (expectedSize > 0) {
124+
assertTrue(ids.contains(getExpectedAlerts()[1]));
125+
}
119126
}
120127

121128
@Test
122129
@Alerts({"1", "fourth"})
130+
@HtmlUnitNYI(CHROME = "0",
131+
EDGE = "0",
132+
FF = "0",
133+
FF_ESR = "0")
123134
public void shouldBeAbleToCombineFiltersWithXpath() throws Exception {
124135
final String html = getFileContent("relative_locators.html");
125136
final WebDriver driver = loadPage2(html);
@@ -128,12 +139,19 @@ public void shouldBeAbleToCombineFiltersWithXpath() throws Exception {
128139
with(xpath("//td[1]")).below(By.id("second")).above(By.id("seventh")));
129140
final List<String> ids = seen.stream().map(e -> e.getAttribute("id")).collect(Collectors.toList());
130141

131-
assertEquals(Integer.parseInt(getExpectedAlerts()[0]), ids.size());
132-
assertTrue(ids.contains(getExpectedAlerts()[1]));
142+
final int expectedSize = Integer.parseInt(getExpectedAlerts()[0]);
143+
assertEquals(expectedSize, ids.size());
144+
if (expectedSize > 0) {
145+
assertTrue(ids.contains(getExpectedAlerts()[1]));
146+
}
133147
}
134148

135149
@Test
136150
@Alerts({"1", "third"})
151+
@HtmlUnitNYI(CHROME = "0",
152+
EDGE = "0",
153+
FF = "0",
154+
FF_ESR = "0")
137155
public void shouldBeAbleToCombineFiltersWithCssSelector() throws Exception {
138156
final String html = getFileContent("relative_locators.html");
139157
final WebDriver driver = loadPage2(html);
@@ -142,8 +160,11 @@ public void shouldBeAbleToCombineFiltersWithCssSelector() throws Exception {
142160
with(cssSelector("td")).above(By.id("center")).toRightOf(By.id("second")));
143161
final List<String> ids = seen.stream().map(e -> e.getAttribute("id")).collect(Collectors.toList());
144162

145-
assertEquals(Integer.parseInt(getExpectedAlerts()[0]), ids.size());
146-
assertTrue(ids.contains(getExpectedAlerts()[1]));
163+
final int expectedSize = Integer.parseInt(getExpectedAlerts()[0]);
164+
assertEquals(expectedSize, ids.size());
165+
if (expectedSize > 0) {
166+
assertTrue(ids.contains(getExpectedAlerts()[1]));
167+
}
147168
}
148169

149170
@Test

0 commit comments

Comments
 (0)