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


The following commit(s) were added to refs/heads/master by this push:
     new 4aed3b2f Support GString as JS execution argument
4aed3b2f is described below

commit 4aed3b2fe7afbefe0fe1d747f107cd37dd32b3b6
Author: Björn Kautler <[email protected]>
AuthorDate: Thu May 22 12:05:59 2025 +0200

    Support GString as JS execution argument
---
 .../main/groovy/geb/js/JavascriptInterface.groovy    |  4 ++--
 .../test/groovy/geb/JavascriptInterfaceSpec.groovy   | 20 +++++++++++++++++++-
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/module/geb-core/src/main/groovy/geb/js/JavascriptInterface.groovy 
b/module/geb-core/src/main/groovy/geb/js/JavascriptInterface.groovy
index 4844b8e2..afcee048 100644
--- a/module/geb-core/src/main/groovy/geb/js/JavascriptInterface.groovy
+++ b/module/geb-core/src/main/groovy/geb/js/JavascriptInterface.groovy
@@ -67,7 +67,7 @@ class JavascriptInterface {
             throw new GebException("driver '$driver' can not execute 
javascript")
         }
 
-        driver.executeScript(script, *args)
+        driver.executeScript(script, *args.collect { (it instanceof GString) ? 
it as String : it })
     }
 
-}
\ No newline at end of file
+}
diff --git a/module/geb-core/src/test/groovy/geb/JavascriptInterfaceSpec.groovy 
b/module/geb-core/src/test/groovy/geb/JavascriptInterfaceSpec.groovy
index dc09d8b3..fdc76b86 100644
--- a/module/geb-core/src/test/groovy/geb/JavascriptInterfaceSpec.groovy
+++ b/module/geb-core/src/test/groovy/geb/JavascriptInterfaceSpec.groovy
@@ -63,6 +63,12 @@ class JavascriptInterfaceSpec extends 
GebSpecWithCallbackServer {
         r == "coming back"
         js.v1 == 5
         js.v2 == 6
+        when: "we use a GString as argument"
+        r = js.exec("${7}", 8, "return changeVars(arguments[0], 
arguments[1]);")
+        then: "the call result is returned and it changed the vars"
+        r == "coming back"
+        js.v1 == '7'
+        js.v2 == 8
     }
 
     def "page objects style"() {
@@ -83,6 +89,12 @@ class JavascriptInterfaceSpec extends 
GebSpecWithCallbackServer {
         r == "coming back"
         v1 == 5
         v2 == 6
+        when: "we use a GString as argument"
+        r = changeVarsViaExec("${7}", 8)
+        then: "the call result is returned and it changed the vars"
+        r == "coming back"
+        v1 == '7'
+        v2 == 8
     }
 
     def "via a module"() {
@@ -103,6 +115,12 @@ class JavascriptInterfaceSpec extends 
GebSpecWithCallbackServer {
         r == "coming back"
         mod.v1 == 5
         mod.v2 == 6
+        when: "we use a GString as argument"
+        r = mod.changeVarsViaExec("${7}", 8)
+        then: "the call result is returned and it changed the vars"
+        r == "coming back"
+        mod.v1 == '7'
+        mod.v2 == 8
     }
 
     /**
@@ -153,4 +171,4 @@ class JavascriptInterfaceSpecModule extends Module {
     def changeVarsViaExec(a, b) {
         js.exec(a, b, "return changeVars(arguments[0], arguments[1]);")
     }
-}
\ No newline at end of file
+}

Reply via email to