From 80c8f71d8e693aceb8b827af0c1118c2d22328e7 Mon Sep 17 00:00:00 2001 From: Burak Kaygusuz Date: Mon, 11 Nov 2024 18:28:05 +0300 Subject: [PATCH] Call remove method --- .../burakkaygusuz/config/WebDriverBuilder.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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(); + } } }