Skip to content

Commit 3330f28

Browse files
committed
[java] added ShadowRoot.hashCode / .equals #13326
1 parent 5e384fc commit 3330f28

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

java/src/org/openqa/selenium/remote/ShadowRoot.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import java.util.List;
2626
import java.util.Map;
27+
import java.util.Objects;
2728
import org.openqa.selenium.By;
2829
import org.openqa.selenium.SearchContext;
2930
import org.openqa.selenium.WebDriver;
@@ -69,4 +70,21 @@ public String getId() {
6970
private Map<String, Object> toJson() {
7071
return singletonMap(W3C.getShadowRootElementKey(), id);
7172
}
73+
74+
@Override
75+
public boolean equals(Object o) {
76+
if (this == o) {
77+
return true;
78+
}
79+
if (o == null || getClass() != o.getClass()) {
80+
return false;
81+
}
82+
ShadowRoot that = (ShadowRoot) o;
83+
return Objects.equals(parent, that.parent) && Objects.equals(id, that.id);
84+
}
85+
86+
@Override
87+
public int hashCode() {
88+
return Objects.hash(parent, id);
89+
}
7290
}

java/test/org/openqa/selenium/remote/ShadowDomTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,6 @@ void shouldBeAbleToGetShadowRootFromExecuteScript() {
225225
ShadowRoot shadowContext = (ShadowRoot) element.getShadowRoot();
226226
ShadowRoot executeContext =
227227
(ShadowRoot) ((JavascriptExecutor) driver).executeScript("return Arguments[0].shadowRoot");
228-
assertThat(shadowContext.getId()).isEqualTo(executeContext.getId());
228+
assertThat(shadowContext).isEqualTo(executeContext);
229229
}
230230
}

0 commit comments

Comments
 (0)