Skip to content

Commit ed0f23f

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

File tree

2 files changed

+35
-29
lines changed

2 files changed

+35
-29
lines changed

src/main/resources/org/openqa/selenium/htmlunit/findElements.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2433,22 +2433,14 @@ return (function() {
24332433
};
24342434
var Y = {
24352435
F: function(a, b) {
2436-
console.log('caller is 2' + arguments.callee.caller);
2437-
console.log(arguments);
24382436
return function(c) {
2439-
console.log('caller is 1' + arguments.callee.caller);
2440-
console.log(arguments);
24412437
var d = Y.u(a);
24422438
d = V(d);
24432439
c = V(c);
24442440
return b.call(null, d, c)
24452441
}
24462442
},
24472443
R: function(a) {
2448-
console.log('caller is 3' + arguments.callee.caller);
2449-
console.log(arguments);
2450-
console.log(a);
2451-
// a ist args aus dem übergebenen
24522444
return Y.F(a, function(b, c) {
24532445
return c.b + c.height < b.b
24542446
})
@@ -2482,8 +2474,6 @@ console.log(a);
24822474
}
24832475
},
24842476
u: function(a) {
2485-
console.log(a);
2486-
console.log('caller is ' + arguments.callee.caller);
24872477
if (ha(a) && 1 == a.nodeType) return a;
24882478
if (ea(a)) return Y.u(a.call(null));
24892479
if (ha(a)) {
@@ -2496,7 +2486,6 @@ console.log('caller is ' + arguments.callee.caller);
24962486
break a
24972487
}
24982488
}
2499-
console.log("#### " + b);
25002489
throw new P(61, "Unsupported locator strategy: " + b);
25012490
}
25022491
if (!b) throw new P(7, "No element has been found by " + JSON.stringify(a));
@@ -2526,9 +2515,6 @@ console.log("#### " + b);
25262515
var g = f.kind,
25272516
h = Y.P[g];
25282517
if (!h) throw new P(61, "Cannot find filter suitable for " + g);
2529-
console.log(f);
2530-
console.log(f.args);
2531-
console.log(e);
25322518
return h.apply(null, f.args)(e)
25332519
}, null) && c.push(e)
25342520
}, null);

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

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import org.openqa.selenium.WebElement;
3434
import org.openqa.selenium.htmlunit.WebDriverTestCase;
3535
import org.openqa.selenium.htmlunit.junit.BrowserRunner;
36+
import org.openqa.selenium.htmlunit.junit.BrowserRunner.Alerts;
37+
import org.openqa.selenium.htmlunit.junit.BrowserRunner.HtmlUnitNYI;
3638

3739
/**
3840
* Tests for RelativeLocator.
@@ -43,6 +45,11 @@
4345
public class RelativeLocatorTest extends WebDriverTestCase {
4446

4547
@Test
48+
@Alerts({"2", "mid", "above"})
49+
@HtmlUnitNYI(CHROME = {"1", "above", "above"},
50+
EDGE = {"1", "above", "above"},
51+
FF = {"1", "above", "above"},
52+
FF_ESR = {"1", "above", "above"})
4653
public void shouldBeAbleToFindElementsAboveAnotherWithTagName() throws Exception {
4754
final String html = getFileContent("relative_locators.html");
4855
final WebDriver driver = loadPage2(html);
@@ -52,12 +59,17 @@ public void shouldBeAbleToFindElementsAboveAnotherWithTagName() throws Exception
5259
final List<WebElement> seen = driver.findElements(with(tagName("p")).above(lowest));
5360
final List<String> ids = seen.stream().map(e -> e.getAttribute("id")).collect(Collectors.toList());
5461

55-
assertEquals(2, ids.size());
56-
assertTrue(ids.contains("mid"));
57-
assertTrue(ids.contains("above"));
62+
assertEquals(Integer.parseInt(getExpectedAlerts()[0]), ids.size());
63+
assertTrue(ids.contains(getExpectedAlerts()[1]));
64+
assertTrue(ids.contains(getExpectedAlerts()[2]));
5865
}
5966

6067
@Test
68+
@Alerts({"2", "fourth", "first"})
69+
@HtmlUnitNYI(CHROME = {"1", "first", "first"},
70+
EDGE = {"1", "first", "first"},
71+
FF = {"1", "first", "first"},
72+
FF_ESR = {"1", "first", "first"})
6173
public void shouldBeAbleToFindElementsAboveAnotherWithXpath() throws Exception {
6274
final String html = getFileContent("relative_locators.html");
6375
final WebDriver driver = loadPage2(html);
@@ -67,12 +79,17 @@ public void shouldBeAbleToFindElementsAboveAnotherWithXpath() throws Exception {
6779
final List<WebElement> seen = driver.findElements(with(xpath("//td[1]")).above(lowest));
6880
final List<String> ids = seen.stream().map(e -> e.getAttribute("id")).collect(Collectors.toList());
6981

70-
assertEquals(2, ids.size());
71-
assertTrue(ids.contains("fourth"));
72-
assertTrue(ids.contains("first"));
82+
assertEquals(Integer.parseInt(getExpectedAlerts()[0]), ids.size());
83+
assertTrue(ids.contains(getExpectedAlerts()[1]));
84+
assertTrue(ids.contains(getExpectedAlerts()[2]));
7385
}
7486

7587
@Test
88+
@Alerts({"2", "mid", "above"})
89+
@HtmlUnitNYI(CHROME = {"1", "above", "above"},
90+
EDGE = {"1", "above", "above"},
91+
FF = {"1", "above", "above"},
92+
FF_ESR = {"1", "above", "above"})
7693
public void shouldBeAbleToFindElementsAboveAnotherWithCssSelector() throws Exception {
7794
final String html = getFileContent("relative_locators.html");
7895
final WebDriver driver = loadPage2(html);
@@ -82,12 +99,13 @@ public void shouldBeAbleToFindElementsAboveAnotherWithCssSelector() throws Excep
8299
final List<WebElement> seen = driver.findElements(with(cssSelector("p")).above(lowest));
83100
final List<String> ids = seen.stream().map(e -> e.getAttribute("id")).collect(Collectors.toList());
84101

85-
assertEquals(2, ids.size());
86-
assertTrue(ids.contains("mid"));
87-
assertTrue(ids.contains("above"));
102+
assertEquals(Integer.parseInt(getExpectedAlerts()[0]), ids.size());
103+
assertTrue(ids.contains(getExpectedAlerts()[1]));
104+
assertTrue(ids.contains(getExpectedAlerts()[2]));
88105
}
89106

90107
@Test
108+
@Alerts({"1", "third"})
91109
public void shouldBeAbleToCombineFilters() throws Exception {
92110
final String html = getFileContent("relative_locators.html");
93111
final WebDriver driver = loadPage2(html);
@@ -96,11 +114,12 @@ public void shouldBeAbleToCombineFilters() throws Exception {
96114
with(tagName("td")).above(By.id("center")).toRightOf(By.id("second")));
97115
final List<String> ids = seen.stream().map(e -> e.getAttribute("id")).collect(Collectors.toList());
98116

99-
assertEquals(1, ids.size());
100-
assertTrue(ids.contains("third"));
117+
assertEquals(Integer.parseInt(getExpectedAlerts()[0]), ids.size());
118+
assertTrue(ids.contains(getExpectedAlerts()[1]));
101119
}
102120

103121
@Test
122+
@Alerts({"1", "fourth"})
104123
public void shouldBeAbleToCombineFiltersWithXpath() throws Exception {
105124
final String html = getFileContent("relative_locators.html");
106125
final WebDriver driver = loadPage2(html);
@@ -109,11 +128,12 @@ public void shouldBeAbleToCombineFiltersWithXpath() throws Exception {
109128
with(xpath("//td[1]")).below(By.id("second")).above(By.id("seventh")));
110129
final List<String> ids = seen.stream().map(e -> e.getAttribute("id")).collect(Collectors.toList());
111130

112-
assertEquals(1, ids.size());
113-
assertTrue(ids.contains("fourth"));
131+
assertEquals(Integer.parseInt(getExpectedAlerts()[0]), ids.size());
132+
assertTrue(ids.contains(getExpectedAlerts()[1]));
114133
}
115134

116135
@Test
136+
@Alerts({"1", "third"})
117137
public void shouldBeAbleToCombineFiltersWithCssSelector() throws Exception {
118138
final String html = getFileContent("relative_locators.html");
119139
final WebDriver driver = loadPage2(html);
@@ -122,8 +142,8 @@ public void shouldBeAbleToCombineFiltersWithCssSelector() throws Exception {
122142
with(cssSelector("td")).above(By.id("center")).toRightOf(By.id("second")));
123143
final List<String> ids = seen.stream().map(e -> e.getAttribute("id")).collect(Collectors.toList());
124144

125-
assertEquals(1, ids.size());
126-
assertTrue(ids.contains("third"));
145+
assertEquals(Integer.parseInt(getExpectedAlerts()[0]), ids.size());
146+
assertTrue(ids.contains(getExpectedAlerts()[1]));
127147
}
128148

129149
@Test

0 commit comments

Comments
 (0)