test framework [driver]: Fix BackgroundRun.useDriver error handling

GitOrigin-RevId: 02d2c64c6296be03b6ff6f728412d2a8c23779f6
This commit is contained in:
Dmitry.Yudin
2026-01-15 14:28:11 +00:00
committed by intellij-monorepo-bot
parent 9761812196
commit ed82295049
@@ -59,11 +59,25 @@ open class BackgroundRun(override val startResult: Deferred<IDEStartResult>, dri
* The IDE is closed on any exception, or if it doesn't close automatically after the block execution completes.
*/
open fun <R> useDriver(closeIdeTimeout: Duration = 1.minutes, block: Driver.() -> R): IDEStartResult {
val ideStartResult: IDEStartResult
try {
driver.withContext { block(this) }
}
finally {
lateinit var ideStartResult: IDEStartResult
runCatching {
driver.withContext {
block(this)
if (isConnected) takeScreenshot("beforeIdeClosed")
}
}.onFailure { e ->
runCatching {
driver.exitApplication()
waitFor(
timeout = 15.seconds,
errorMessage = {
forceKill()
"Error on exit application via Driver"
},
) { !driver.isConnected }
}
throw e
}.onSuccess {
ideStartResult = driver.waitToClose(closeIdeTimeout)
}
return ideStartResult