From cd91b8c95d3455eaf7c8d6f436199e5f8a80165a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Sautter?= Date: Fri, 5 Jan 2024 00:37:55 +0100 Subject: [PATCH] [java] stop the started server when an exception is raised --- .../selenium/testing/drivers/RemoteSupplier.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/java/test/org/openqa/selenium/testing/drivers/RemoteSupplier.java b/java/test/org/openqa/selenium/testing/drivers/RemoteSupplier.java index b41083cb33b06..3904791b7f4cc 100644 --- a/java/test/org/openqa/selenium/testing/drivers/RemoteSupplier.java +++ b/java/test/org/openqa/selenium/testing/drivers/RemoteSupplier.java @@ -57,9 +57,17 @@ public WebDriver get() { serverUrl = server.getWebDriverUrl(); } - RemoteWebDriver driver = new RemoteWebDriver(serverUrl, desiredCapabilities); - driver.setFileDetector(new LocalFileDetector()); - return new Augmenter().augment(driver); + try { + RemoteWebDriver driver = new RemoteWebDriver(serverUrl, desiredCapabilities); + driver.setFileDetector(new LocalFileDetector()); + return new Augmenter().augment(driver); + } catch (Exception ex) { + if (started) { + started = false; + server.stop(); + } + throw ex; + } } private synchronized void startServer() {