diff --git a/src/main/java/io/github/burakkaygusuz/config/WebDriverBuilder.java b/src/main/java/io/github/burakkaygusuz/config/WebDriverBuilder.java index 45dac8a..b779104 100644 --- a/src/main/java/io/github/burakkaygusuz/config/WebDriverBuilder.java +++ b/src/main/java/io/github/burakkaygusuz/config/WebDriverBuilder.java @@ -63,9 +63,13 @@ public WebDriverBuilder enableHeadless() { } public WebDriver build() { - DRIVER_THREAD_LOCAL.set(url != null ? new RemoteWebDriver(url, options, isTracingEnabled) - : new RemoteWebDriver(options, isTracingEnabled)); - WebDriver original = DRIVER_THREAD_LOCAL.get(); - return new EventFiringDecorator<>(new CustomWebDriverListener()).decorate(original); + try { + DRIVER_THREAD_LOCAL.set(url != null ? new RemoteWebDriver(url, options, isTracingEnabled) + : new RemoteWebDriver(options, isTracingEnabled)); + WebDriver original = DRIVER_THREAD_LOCAL.get(); + return new EventFiringDecorator<>(new CustomWebDriverListener()).decorate(original); + } finally { + DRIVER_THREAD_LOCAL.remove(); + } } }