This is an automated email from the ASF dual-hosted git repository.

jonnybot pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy-geb.git

commit efae6b195446294afc3dba7d8cf0e9992cfa12ac
Author: Mattias Reichel <[email protected]>
AuthorDate: Fri Sep 19 13:24:58 2025 +0200

    fix(webstorage): replace removed Selenium HTML5 APIs (4.35.0)
    
    Selenium `4.35.0` removed `org.openqa.selenium.html5.*` classes.
    Switch to JS-based access for `localStorage`/`sessionStorage`
    (via Geb `js.exec`) to restore compatibility.
    
    Fixes gh-280
---
 doc/manual/src/docs/asciidoc/020-browser.adoc      |  5 ---
 module/geb-core/src/main/groovy/geb/Browser.groovy | 12 ++-----
 .../error/WebStorageNotSupportedException.groovy   | 25 -------------
 .../main/groovy/geb/webstorage/LocalStorage.groovy | 31 ++++++++--------
 .../groovy/geb/webstorage/SessionStorage.groovy    | 31 ++++++++--------
 .../webstorage/UnsupportedWebStorageSpec.groovy    | 42 ----------------------
 6 files changed, 34 insertions(+), 112 deletions(-)

diff --git a/doc/manual/src/docs/asciidoc/020-browser.adoc 
b/doc/manual/src/docs/asciidoc/020-browser.adoc
index b86cfff2..adfd36e7 100644
--- a/doc/manual/src/docs/asciidoc/020-browser.adoc
+++ b/doc/manual/src/docs/asciidoc/020-browser.adoc
@@ -480,11 +480,6 @@ 
include::{rb-snippets-dir}/browser/WebStorageSpec.groovy[tag=write_and_read]
 
 Both `localStorage` and `sessionStorage` properties are of 
`geb.webstorage.WebStorage` type - please refer to 
link:api/geb/webstorage/WebStorage.html[its javadoc] for information about 
other operations that are supported apart from reading and writing values.
 
-[WARNING]
-====
-Not all driver implementations support accessing web storage. When trying to 
access web storage when using a driver that doesn't support it 
`geb.error.WebStorageNotSupportedException` will be thrown.
-====
-
 [[quitting-the-browser]]
 == Quitting the browser
 
diff --git a/module/geb-core/src/main/groovy/geb/Browser.groovy 
b/module/geb-core/src/main/groovy/geb/Browser.groovy
index f8279892..4c94a4ce 100644
--- a/module/geb-core/src/main/groovy/geb/Browser.groovy
+++ b/module/geb-core/src/main/groovy/geb/Browser.groovy
@@ -23,7 +23,6 @@ import geb.driver.RemoteDriverOperations
 import geb.error.IncorrectDriverTypeException
 import geb.error.NoNewWindowException
 import geb.error.UnexpectedPageException
-import geb.error.WebStorageNotSupportedException
 import geb.js.JavascriptInterface
 import geb.navigator.factory.NavigatorFactory
 import geb.report.ReportState
@@ -35,7 +34,6 @@ import geb.webstorage.WebStorage
 import org.openqa.selenium.NoSuchWindowException
 import org.openqa.selenium.WebDriver
 import org.openqa.selenium.WebDriverException
-import org.openqa.selenium.html5.WebStorage as SeleniumWebStorage
 
 import java.time.Duration
 
@@ -944,7 +942,7 @@ class Browser {
      * @see geb.webstorage.WebStorage
      */
     WebStorage getLocalStorage() {
-        new LocalStorage(seleniumWebStorage)
+        new LocalStorage(js)
     }
 
     /**
@@ -953,7 +951,7 @@ class Browser {
      * @see geb.webstorage.WebStorage
      */
     WebStorage getSessionStorage() {
-        new SessionStorage(seleniumWebStorage)
+        new SessionStorage(js)
     }
 
     void verifyAtImplicitly(Class<? extends Page> targetPage) {
@@ -1085,12 +1083,6 @@ class Browser {
         newWindows.first()
     }
 
-    private SeleniumWebStorage getSeleniumWebStorage() {
-        driverAs(SeleniumWebStorage).orElseThrow {
-            new WebStorageNotSupportedException()
-        }
-    }
-
     private String toQueryString(Map params) {
         def escaper = UrlEscapers.urlFormParameterEscaper()
         if (params) {
diff --git 
a/module/geb-core/src/main/groovy/geb/error/WebStorageNotSupportedException.groovy
 
b/module/geb-core/src/main/groovy/geb/error/WebStorageNotSupportedException.groovy
deleted file mode 100644
index 5dd1032f..00000000
--- 
a/module/geb-core/src/main/groovy/geb/error/WebStorageNotSupportedException.groovy
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF 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 geb.error
-
-class WebStorageNotSupportedException extends GebException {
-    WebStorageNotSupportedException() {
-        super('Web storage is not supported by the driver')
-    }
-}
diff --git a/module/geb-core/src/main/groovy/geb/webstorage/LocalStorage.groovy 
b/module/geb-core/src/main/groovy/geb/webstorage/LocalStorage.groovy
index 0c23b579..3df86793 100644
--- a/module/geb-core/src/main/groovy/geb/webstorage/LocalStorage.groovy
+++ b/module/geb-core/src/main/groovy/geb/webstorage/LocalStorage.groovy
@@ -18,49 +18,50 @@
  */
 package geb.webstorage
 
-import org.openqa.selenium.html5.WebStorage as SeleniumWebStorage
-import org.openqa.selenium.html5.LocalStorage as SeleniumLocalStorage
+import geb.js.JavascriptInterface
 
 class LocalStorage implements WebStorage {
 
-    private final SeleniumWebStorage webStorage
+    private final JavascriptInterface js
 
-    LocalStorage(SeleniumWebStorage webStorage) {
-        this.webStorage = webStorage
+    LocalStorage(JavascriptInterface js) {
+        this.js = js
     }
 
     @Override
     String getAt(String key) {
-        localStorage.getItem(key)
+        js.exec(key, 'return window.localStorage.getItem(arguments[0]);')
     }
 
     @Override
     void putAt(String key, String value) {
-        localStorage.setItem(key, value)
+        js.exec(key, value, 'window.localStorage.setItem(arguments[0], 
arguments[1]);')
     }
 
     @Override
     void remove(String key) {
-        localStorage.removeItem(key)
+        js.exec(key, 'window.localStorage.removeItem(arguments[0]);')
     }
 
     @Override
     Set<String> keySet() {
-        localStorage.keySet()
+        js.exec('''
+            var out = [];
+            for (var i = 0; i < window.localStorage.length; i++) {
+                out.push(window.localStorage.key(i));
+            }
+            return out;
+        ''') as Set<String>
     }
 
     @Override
     int size() {
-        localStorage.size()
+        (js.exec('return window.localStorage.length;') as Number).intValue()
     }
 
     @Override
     void clear() {
-        localStorage.clear()
-    }
-
-    private SeleniumLocalStorage getLocalStorage() {
-        webStorage.localStorage
+        js.exec('window.localStorage.clear();')
     }
 
 }
diff --git 
a/module/geb-core/src/main/groovy/geb/webstorage/SessionStorage.groovy 
b/module/geb-core/src/main/groovy/geb/webstorage/SessionStorage.groovy
index ffc8a311..92722d11 100644
--- a/module/geb-core/src/main/groovy/geb/webstorage/SessionStorage.groovy
+++ b/module/geb-core/src/main/groovy/geb/webstorage/SessionStorage.groovy
@@ -18,49 +18,50 @@
  */
 package geb.webstorage
 
-import org.openqa.selenium.html5.SessionStorage as SeleniumSessionStorage
-import org.openqa.selenium.html5.WebStorage as SeleniumWebStorage
+import geb.js.JavascriptInterface
 
 class SessionStorage implements WebStorage {
 
-    private final SeleniumWebStorage webDriver
+    private final JavascriptInterface js
 
-    SessionStorage(SeleniumWebStorage webDriver) {
-        this.webDriver = webDriver
+    SessionStorage(JavascriptInterface js) {
+        this.js = js
     }
 
     @Override
     String getAt(String key) {
-        sessionStorage.getItem(key)
+        js.exec(key, 'return window.sessionStorage.getItem(arguments[0]);')
     }
 
     @Override
     void putAt(String key, String value) {
-        sessionStorage.setItem(key, value)
+        js.exec(key, value, 'window.sessionStorage.setItem(arguments[0], 
arguments[1]);')
     }
 
     @Override
     void remove(String key) {
-        sessionStorage.removeItem(key)
+        js.exec(key, 'window.sessionStorage.removeItem(arguments[0]);')
     }
 
     @Override
     Set<String> keySet() {
-        sessionStorage.keySet()
+        js.exec('''
+            var out = [];
+            for (var i = 0; i < window.sessionStorage.length; i++) {
+                out.push(window.sessionStorage.key(i));
+            }
+            return out;
+        ''') as Set<String>
     }
 
     @Override
     int size() {
-        sessionStorage.size()
+        (js.exec('return window.sessionStorage.length;') as Number).intValue()
     }
 
     @Override
     void clear() {
-        sessionStorage.clear()
-    }
-
-    private SeleniumSessionStorage getSessionStorage() {
-        webDriver.sessionStorage
+        js.exec('window.sessionStorage.clear();')
     }
 
 }
diff --git 
a/module/geb-core/src/test/groovy/geb/webstorage/UnsupportedWebStorageSpec.groovy
 
b/module/geb-core/src/test/groovy/geb/webstorage/UnsupportedWebStorageSpec.groovy
deleted file mode 100644
index 16d1b0c5..00000000
--- 
a/module/geb-core/src/test/groovy/geb/webstorage/UnsupportedWebStorageSpec.groovy
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF 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 geb.webstorage
-
-import geb.error.WebStorageNotSupportedException
-import geb.test.GebSpec
-
-class UnsupportedWebStorageSpec extends GebSpec {
-
-    def "an informative exception is thrown when web storage is not supported 
by the driver and trying to access local storage"() {
-        when:
-        localStorage
-
-        then:
-        thrown(WebStorageNotSupportedException)
-    }
-
-    def "an informative exception is thrown when web storage is not supported 
by the driver and trying to access session storage"() {
-        when:
-        sessionStorage
-
-        then:
-        thrown(WebStorageNotSupportedException)
-    }
-
-}

Reply via email to