From c4b0de9e5961930e42aa387e52dbc4d0f92630bd Mon Sep 17 00:00:00 2001 From: Dmitry Zaytsev Date: Fri, 3 Jan 2025 00:28:16 +0100 Subject: [PATCH] Injecting launch arguments to web page (#2223) --- .../src/main/java/maestro/drivers/WebDriver.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/maestro-client/src/main/java/maestro/drivers/WebDriver.kt b/maestro-client/src/main/java/maestro/drivers/WebDriver.kt index 9be0251b25..4c15040270 100644 --- a/maestro-client/src/main/java/maestro/drivers/WebDriver.kt +++ b/maestro-client/src/main/java/maestro/drivers/WebDriver.kt @@ -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() + private var injectedArguments: Map = emptyMap() private var webScreenRecorder: WebScreenRecorder? = null @@ -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) { @@ -137,6 +143,8 @@ class WebDriver(val isStudio: Boolean) : Driver { } override fun close() { + injectedArguments = emptyMap() + try { seleniumDriver?.quit() webScreenRecorder?.close() @@ -169,6 +177,8 @@ class WebDriver(val isStudio: Boolean) : Driver { launchArguments: Map, sessionId: UUID?, ) { + injectedArguments = injectedArguments + launchArguments + open() val driver = ensureOpen()