Browse Source

Dispose web drivers after selenium tests

pull/822/head v0.5.0-build228
Shagen Ogandzhanian 3 years ago
parent
commit
1b42dbec3e
  1. 30
      web/integration-core/src/jvmTest/kotlin/org/jetbrains/compose/web/tests/integration/common/BaseIntegrationTests.kt
  2. 3
      web/integration-core/src/jvmTest/kotlin/org/jetbrains/compose/web/tests/integration/common/IntegrationTestsSetup.kt

30
web/integration-core/src/jvmTest/kotlin/org/jetbrains/compose/web/tests/integration/common/BaseIntegrationTests.kt

@ -26,7 +26,7 @@ fun WebDriver.waitTextToBe(textId: String = "txt", value: String) {
WebDriverWait(this, 1).until(ExpectedConditions.textToBe(By.id(textId), value)) WebDriverWait(this, 1).until(ExpectedConditions.textToBe(By.id(textId), value))
} }
object Drivers { internal object Drivers {
val Chrome by lazy { val Chrome by lazy {
object : ChromeDriver( object : ChromeDriver(
ChromeOptions().apply { ChromeOptions().apply {
@ -54,6 +54,22 @@ object Drivers {
} }
} }
@OptIn(ExperimentalStdlibApi::class)
val activatedDrivers: Array<Array<WebDriver>> = buildList<Array<WebDriver>> {
add(arrayOf(Chrome))
if (System.getProperty("compose.web.tests.integration.withFirefox") == "true") {
add(arrayOf(Firefox))
}
}.toTypedArray()
fun dispose() {
activatedDrivers.forEach {
val webDriver = it.first()
println("Closing web driver: ${webDriver}")
webDriver.quit()
}
}
} }
@Target(AnnotationTarget.FUNCTION) @Target(AnnotationTarget.FUNCTION)
@ -63,18 +79,10 @@ annotation class ResolveDrivers
@DisplayNameGeneration(DisplayNameSimplifier::class) @DisplayNameGeneration(DisplayNameSimplifier::class)
@ExtendWith(value = [StaticServerSetupExtension::class]) @ExtendWith(value = [IntegrationTestsSetup::class])
abstract class BaseIntegrationTests() { abstract class BaseIntegrationTests() {
companion object { companion object {
@OptIn(ExperimentalStdlibApi::class)
private val drivers: Array<Array<WebDriver>> = buildList<Array<WebDriver>> {
add(arrayOf(Drivers.Chrome))
if (System.getProperty("compose.web.tests.integration.withFirefox") == "true") {
add(arrayOf(Drivers.Firefox))
}
}.toTypedArray()
@JvmStatic @JvmStatic
fun resolveDrivers() = drivers fun resolveDrivers() = Drivers.activatedDrivers
} }
} }

3
web/integration-core/src/jvmTest/kotlin/org/jetbrains/compose/web/tests/integration/common/StaticServerSetupExtension.kt → web/integration-core/src/jvmTest/kotlin/org/jetbrains/compose/web/tests/integration/common/IntegrationTestsSetup.kt

@ -3,7 +3,7 @@ package org.jetbrains.compose.web.tests.integration.common
import org.junit.jupiter.api.extension.BeforeAllCallback import org.junit.jupiter.api.extension.BeforeAllCallback
import org.junit.jupiter.api.extension.ExtensionContext import org.junit.jupiter.api.extension.ExtensionContext
class StaticServerSetupExtension : class IntegrationTestsSetup:
BeforeAllCallback, BeforeAllCallback,
ExtensionContext.Store.CloseableResource { ExtensionContext.Store.CloseableResource {
@ -22,5 +22,6 @@ class StaticServerSetupExtension :
override fun close() { override fun close() {
ServerLauncher.stopServer(this) ServerLauncher.stopServer(this)
Drivers.dispose()
} }
} }
Loading…
Cancel
Save