Skip to content

Commit da3a82b

Browse files
dev-velodiemol
andauthored
[java] Add Missing W3C Exceptions (#12175)
* Add DetachedShadowRootException class and W3CError * Add no such shadow root to w3c error * add shadow root test and appServer page * Add insecure cert exception and w3c error --------- Co-authored-by: Diego Molina <diemol@users.noreply.github.com>
1 parent 3880298 commit da3a82b

File tree

6 files changed

+110
-0
lines changed

6 files changed

+110
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium;
19+
20+
/**
21+
* Indicates that a reference to a shadow root is now "detached" --- the element no longer appears on the
22+
* DOM of the page.
23+
*/
24+
public class DetachedShadowRootException extends WebDriverException {
25+
public DetachedShadowRootException(String message) {
26+
super(message);
27+
}
28+
29+
public DetachedShadowRootException(String message, Throwable cause) {
30+
super(message, cause);
31+
}
32+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium;
19+
20+
/**
21+
* Indicates that navigation caused by the user agent hit a certificate warning, which is usually the result of an expired or invalid TLS certificate.
22+
*/
23+
public class InsecureCertificateException extends WebDriverException {
24+
public InsecureCertificateException(String message) {
25+
super(message);
26+
}
27+
28+
public InsecureCertificateException(Throwable cause) {
29+
super(cause);
30+
}
31+
32+
public InsecureCertificateException(String message, Throwable cause) {
33+
super(message, cause);
34+
}
35+
}

java/src/org/openqa/selenium/NoSuchShadowRootException.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
package org.openqa.selenium;
1919

20+
/**
21+
* Indicates that an element does not have a shadow root.
22+
*/
2023
public class NoSuchShadowRootException extends NotFoundException {
2124

2225
public NoSuchShadowRootException(String message) {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
import java.lang.reflect.Constructor;
2424
import java.util.Map;
2525
import java.util.Set;
26+
import org.openqa.selenium.DetachedShadowRootException;
2627
import org.openqa.selenium.ElementClickInterceptedException;
2728
import org.openqa.selenium.ElementNotInteractableException;
29+
import org.openqa.selenium.InsecureCertificateException;
2830
import org.openqa.selenium.InvalidArgumentException;
2931
import org.openqa.selenium.InvalidCookieDomainException;
3032
import org.openqa.selenium.InvalidElementStateException;
@@ -35,6 +37,7 @@
3537
import org.openqa.selenium.NoSuchElementException;
3638
import org.openqa.selenium.NoSuchFrameException;
3739
import org.openqa.selenium.NoSuchSessionException;
40+
import org.openqa.selenium.NoSuchShadowRootException;
3841
import org.openqa.selenium.NoSuchWindowException;
3942
import org.openqa.selenium.ScriptTimeoutException;
4043
import org.openqa.selenium.SessionNotCreatedException;
@@ -56,6 +59,7 @@ public class ErrorCodec {
5659
private static final Set<W3CError> ERRORS =
5760
ImmutableSet.<W3CError>builder()
5861
.add(new W3CError("script timeout", ScriptTimeoutException.class, 500))
62+
.add(new W3CError("detached shadow root", DetachedShadowRootException.class, 404))
5963
.add(
6064
new W3CError(
6165
"element click intercepted", ElementClickInterceptedException.class, 400))
@@ -65,12 +69,14 @@ public class ErrorCodec {
6569
.add(new W3CError("invalid element state", InvalidElementStateException.class, 400))
6670
.add(new W3CError("invalid selector", InvalidSelectorException.class, 400))
6771
.add(new W3CError("invalid session id", NoSuchSessionException.class, 404))
72+
.add(new W3CError("insecure certificate", InsecureCertificateException.class, 400))
6873
.add(new W3CError("javascript error", JavascriptException.class, 500))
6974
.add(new W3CError("move target out of bounds", MoveTargetOutOfBoundsException.class, 500))
7075
.add(new W3CError("no such alert", NoAlertPresentException.class, 404))
7176
.add(new W3CError("no such cookie", NoSuchCookieException.class, 404))
7277
.add(new W3CError("no such element", NoSuchElementException.class, 404))
7378
.add(new W3CError("no such frame", NoSuchFrameException.class, 404))
79+
.add(new W3CError("no such shadow root", NoSuchShadowRootException.class, 404))
7480
.add(new W3CError("no such window", NoSuchWindowException.class, 404))
7581
.add(new W3CError("session not created", SessionNotCreatedException.class, 500))
7682
.add(new W3CError("stale element reference", StaleElementReferenceException.class, 404))
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium;
19+
20+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
21+
import org.junit.jupiter.api.Test;
22+
import org.openqa.selenium.testing.JupiterTestBase;
23+
24+
public class NoSuchShadowRootTest extends JupiterTestBase{
25+
26+
@Test
27+
public void getNoSuchShadowRoot(){
28+
driver.get(pages.shadowRootPage);
29+
WebElement nonExistentShadowRootElement = driver.findElement(By.id("noShadowRoot"));
30+
assertThatExceptionOfType(NoSuchShadowRootException.class).isThrownBy(() -> nonExistentShadowRootElement.getShadowRoot());
31+
}
32+
}

java/test/org/openqa/selenium/testing/Pages.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public class Pages {
6666
public String richTextPage;
6767
public String selectableItemsPage;
6868
public String selectPage;
69+
public String shadowRootPage;
6970
public String simpleTestPage;
7071
public String simpleXmlDocument;
7172
public String sleepingPage;
@@ -132,6 +133,7 @@ public Pages(AppServer appServer) {
132133
selectPage = appServer.whereIs("selectPage.html");
133134
simpleTestPage = appServer.whereIs("simpleTest.html");
134135
simpleXmlDocument = appServer.whereIs("simple.xml");
136+
shadowRootPage = appServer.whereIs("shadowRootPage.html");
135137
sleepingPage = appServer.whereIs("sleep");
136138
slowIframes = appServer.whereIs("slow_loading_iframes.html");
137139
slowLoadingAlertPage = appServer.whereIs("slowLoadingAlert.html");

0 commit comments

Comments
 (0)