27 lines
701 B
Kotlin
27 lines
701 B
Kotlin
|
|
// core/BrowserManager.kt
|
||
|
|
package core
|
||
|
|
|
||
|
|
import org.openqa.selenium.WebDriverException
|
||
|
|
import org.openqa.selenium.chrome.ChromeDriver
|
||
|
|
import org.openqa.selenium.chrome.ChromeOptions
|
||
|
|
|
||
|
|
object BrowserManager {
|
||
|
|
private var driver: ChromeDriver? = null
|
||
|
|
|
||
|
|
fun getChromeDriver(options: ChromeOptions): ChromeDriver {
|
||
|
|
try {
|
||
|
|
driver?.title // Check if the driver is still active
|
||
|
|
} catch (e: WebDriverException) {
|
||
|
|
driver = null // Driver is dead, so nullify it
|
||
|
|
}
|
||
|
|
if (driver == null) {
|
||
|
|
driver = ChromeDriver(options)
|
||
|
|
}
|
||
|
|
return driver!!
|
||
|
|
}
|
||
|
|
|
||
|
|
fun quitChromeDriver() {
|
||
|
|
driver?.quit()
|
||
|
|
driver = null
|
||
|
|
}
|
||
|
|
}
|