Skip to content

Commit

Permalink
Fix ElementQuery for built-in elements or elements without a shadow r…
Browse files Browse the repository at this point in the history
…oot (#990)

Fixes #989
  • Loading branch information
Artur- committed Feb 12, 2018
1 parent 4e74e20 commit b2022df
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,15 @@ private List<T> executeSearch(Integer index) {
TestBenchElement elementContext;
JavascriptExecutor executor;
if (getContext() instanceof TestBenchElement) {
script.append(
"var result = arguments[0].shadowRoot.querySelectorAll(arguments[1]+arguments[2]);");
script.append(
"var light = arguments[0].querySelectorAll(arguments[1]+arguments[2]);");
script.append("if (light.length > 0) {");
script.append(
"result = Array.prototype.slice.call(result).concat(Array.prototype.slice.call(light));");
script.append("}");
script.append("return result");
script.append("var result = [];" //
+ "if (arguments[0].shadowRoot) {" //
+ " var shadow = arguments[0].shadowRoot.querySelectorAll(arguments[1]+arguments[2]);" //
+ " result = result.concat(Array.prototype.slice.call(shadow));" //
+ "}" //
+ "var light = arguments[0].querySelectorAll(arguments[1]+arguments[2]);" //
+ "result = result.concat(Array.prototype.slice.call(light));" //
+ "return result" //
);
elementContext = (TestBenchElement) getContext();
executor = elementContext.getCommandExecutor().getDriver();
} else if (getContext() instanceof WebDriver) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,14 @@ public void findTestBenchElement() throws Exception {
.waitForFirst().$(TestBenchElement.class).id("shadow-button-2");
Assert.assertNotNull(button);
}

@Test
public void findTestBenchElementChild() throws Exception {
openTestURL();

TestBenchElement button = $(PolymerTemplateViewElement.class)
.waitForFirst().$(TestBenchElement.class).first()
.$(TestBenchElement.class).first();
Assert.assertEquals("Shadow Button 1", button.getText());
}
}

0 comments on commit b2022df

Please sign in to comment.