Skip to content

Commit

Permalink
[java] Add Missing W3C Exceptions (#12175)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
LogicOscar and diemol authored Jun 8, 2023
1 parent 3880298 commit da3a82b
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 0 deletions.
32 changes: 32 additions & 0 deletions java/src/org/openqa/selenium/DetachedShadowRootException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium;

/**
* Indicates that a reference to a shadow root is now "detached" --- the element no longer appears on the
* DOM of the page.
*/
public class DetachedShadowRootException extends WebDriverException {
public DetachedShadowRootException(String message) {
super(message);
}

public DetachedShadowRootException(String message, Throwable cause) {
super(message, cause);
}
}
35 changes: 35 additions & 0 deletions java/src/org/openqa/selenium/InsecureCertificateException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium;

/**
* Indicates that navigation caused by the user agent hit a certificate warning, which is usually the result of an expired or invalid TLS certificate.
*/
public class InsecureCertificateException extends WebDriverException {
public InsecureCertificateException(String message) {
super(message);
}

public InsecureCertificateException(Throwable cause) {
super(cause);
}

public InsecureCertificateException(String message, Throwable cause) {
super(message, cause);
}
}
3 changes: 3 additions & 0 deletions java/src/org/openqa/selenium/NoSuchShadowRootException.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

package org.openqa.selenium;

/**
* Indicates that an element does not have a shadow root.
*/
public class NoSuchShadowRootException extends NotFoundException {

public NoSuchShadowRootException(String message) {
Expand Down
6 changes: 6 additions & 0 deletions java/src/org/openqa/selenium/remote/ErrorCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
import java.lang.reflect.Constructor;
import java.util.Map;
import java.util.Set;
import org.openqa.selenium.DetachedShadowRootException;
import org.openqa.selenium.ElementClickInterceptedException;
import org.openqa.selenium.ElementNotInteractableException;
import org.openqa.selenium.InsecureCertificateException;
import org.openqa.selenium.InvalidArgumentException;
import org.openqa.selenium.InvalidCookieDomainException;
import org.openqa.selenium.InvalidElementStateException;
Expand All @@ -35,6 +37,7 @@
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.NoSuchFrameException;
import org.openqa.selenium.NoSuchSessionException;
import org.openqa.selenium.NoSuchShadowRootException;
import org.openqa.selenium.NoSuchWindowException;
import org.openqa.selenium.ScriptTimeoutException;
import org.openqa.selenium.SessionNotCreatedException;
Expand All @@ -56,6 +59,7 @@ public class ErrorCodec {
private static final Set<W3CError> ERRORS =
ImmutableSet.<W3CError>builder()
.add(new W3CError("script timeout", ScriptTimeoutException.class, 500))
.add(new W3CError("detached shadow root", DetachedShadowRootException.class, 404))
.add(
new W3CError(
"element click intercepted", ElementClickInterceptedException.class, 400))
Expand All @@ -65,12 +69,14 @@ public class ErrorCodec {
.add(new W3CError("invalid element state", InvalidElementStateException.class, 400))
.add(new W3CError("invalid selector", InvalidSelectorException.class, 400))
.add(new W3CError("invalid session id", NoSuchSessionException.class, 404))
.add(new W3CError("insecure certificate", InsecureCertificateException.class, 400))
.add(new W3CError("javascript error", JavascriptException.class, 500))
.add(new W3CError("move target out of bounds", MoveTargetOutOfBoundsException.class, 500))
.add(new W3CError("no such alert", NoAlertPresentException.class, 404))
.add(new W3CError("no such cookie", NoSuchCookieException.class, 404))
.add(new W3CError("no such element", NoSuchElementException.class, 404))
.add(new W3CError("no such frame", NoSuchFrameException.class, 404))
.add(new W3CError("no such shadow root", NoSuchShadowRootException.class, 404))
.add(new W3CError("no such window", NoSuchWindowException.class, 404))
.add(new W3CError("session not created", SessionNotCreatedException.class, 500))
.add(new W3CError("stale element reference", StaleElementReferenceException.class, 404))
Expand Down
32 changes: 32 additions & 0 deletions java/test/org/openqa/selenium/NoSuchShadowRootTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium;

import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.testing.JupiterTestBase;

public class NoSuchShadowRootTest extends JupiterTestBase{

@Test
public void getNoSuchShadowRoot(){
driver.get(pages.shadowRootPage);
WebElement nonExistentShadowRootElement = driver.findElement(By.id("noShadowRoot"));
assertThatExceptionOfType(NoSuchShadowRootException.class).isThrownBy(() -> nonExistentShadowRootElement.getShadowRoot());
}
}
2 changes: 2 additions & 0 deletions java/test/org/openqa/selenium/testing/Pages.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public class Pages {
public String richTextPage;
public String selectableItemsPage;
public String selectPage;
public String shadowRootPage;
public String simpleTestPage;
public String simpleXmlDocument;
public String sleepingPage;
Expand Down Expand Up @@ -132,6 +133,7 @@ public Pages(AppServer appServer) {
selectPage = appServer.whereIs("selectPage.html");
simpleTestPage = appServer.whereIs("simpleTest.html");
simpleXmlDocument = appServer.whereIs("simple.xml");
shadowRootPage = appServer.whereIs("shadowRootPage.html");
sleepingPage = appServer.whereIs("sleep");
slowIframes = appServer.whereIs("slow_loading_iframes.html");
slowLoadingAlertPage = appServer.whereIs("slowLoadingAlert.html");
Expand Down

0 comments on commit da3a82b

Please sign in to comment.