Skip to content

Support GString as JS execution argument #273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"() {
Expand All @@ -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"() {
Expand All @@ -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
}

/**
Expand Down Expand Up @@ -153,4 +171,4 @@ class JavascriptInterfaceSpecModule extends Module {
def changeVarsViaExec(a, b) {
js.exec(a, b, "return changeVars(arguments[0], arguments[1]);")
}
}
}