Skip to content
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

Injecting launch arguments to web page #2223

Merged
merged 1 commit into from
Jan 2, 2025
Merged
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
10 changes: 10 additions & 0 deletions maestro-client/src/main/java/maestro/drivers/WebDriver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class WebDriver(val isStudio: Boolean) : Driver {
private var seleniumDriver: org.openqa.selenium.WebDriver? = null
private var maestroWebScript: String? = null
private var lastSeenWindowHandles = setOf<String>()
private var injectedArguments: Map<String, Any> = emptyMap()

private var webScreenRecorder: WebScreenRecorder? = null

Expand Down Expand Up @@ -102,6 +103,11 @@ class WebDriver(val isStudio: Boolean) : Driver {

try {
executor.executeScript("$maestroWebScript")

injectedArguments.forEach { (key, value) ->
executor.executeScript("$key = '$value'")
}

Thread.sleep(100)
return executor.executeScript(js)
} catch (e: Exception) {
Expand Down Expand Up @@ -137,6 +143,8 @@ class WebDriver(val isStudio: Boolean) : Driver {
}

override fun close() {
injectedArguments = emptyMap()

try {
seleniumDriver?.quit()
webScreenRecorder?.close()
Expand Down Expand Up @@ -169,6 +177,8 @@ class WebDriver(val isStudio: Boolean) : Driver {
launchArguments: Map<String, Any>,
sessionId: UUID?,
) {
injectedArguments = injectedArguments + launchArguments

open()
val driver = ensureOpen()

Expand Down
Loading