From e8da28498c51c65ec3fa200d382882219a9f3aa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Crobin=2Egupta=E2=80=9D?= <“robin.gupta@singtel.com”> Date: Thu, 17 Mar 2022 16:04:02 +0800 Subject: [PATCH 1/2] Fix for basePath appending logic to fix Issue#1660 AppiumDriverLocalService is not able to start - checkStatus is failing --- .../service/local/AppiumDriverLocalService.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/appium/java_client/service/local/AppiumDriverLocalService.java b/src/main/java/io/appium/java_client/service/local/AppiumDriverLocalService.java index cc1c77ad5..b1e24bbf3 100644 --- a/src/main/java/io/appium/java_client/service/local/AppiumDriverLocalService.java +++ b/src/main/java/io/appium/java_client/service/local/AppiumDriverLocalService.java @@ -94,10 +94,23 @@ public static AppiumDriverLocalService buildService(AppiumServiceBuilder builder } public AppiumDriverLocalService withBasePath(String basePath) { - this.basePath = basePath; + this.basePath = sanitizeBasePath(basePath); return this; } + @SneakyThrows private static String sanitizeBasePath(String basePath) { + if (null == basePath) { + LOG.warn("Base Path cannot be NULL -- ignoring the basepath configuration"); + return null; + } + basePath = basePath.trim(); + if (basePath.isBlank() || basePath.isEmpty()) { + LOG.warn("Base Path cannot be Empty or Blank -- ignoring the basepath configuration"); + return null; + } + return (basePath.endsWith("/") ? basePath : basePath + "/"); + } + public String getBasePath() { return this.basePath; } From 72cf29f942691861b33479c975837fd216f6ff9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Crobin=2Egupta=E2=80=9D?= <“robin.gupta@singtel.com”> Date: Thu, 17 Mar 2022 18:06:35 +0800 Subject: [PATCH 2/2] Added test to check the service instantiation with basepath --- .../java_client/service/local/ServerBuilderTest.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/test/java/io/appium/java_client/service/local/ServerBuilderTest.java b/src/test/java/io/appium/java_client/service/local/ServerBuilderTest.java index 7db741cdd..fd075e976 100644 --- a/src/test/java/io/appium/java_client/service/local/ServerBuilderTest.java +++ b/src/test/java/io/appium/java_client/service/local/ServerBuilderTest.java @@ -6,6 +6,7 @@ import static io.appium.java_client.service.local.AppiumServiceBuilder.APPIUM_PATH; import static io.appium.java_client.service.local.flags.GeneralServerFlag.CALLBACK_ADDRESS; import static io.appium.java_client.service.local.flags.GeneralServerFlag.SESSION_OVERRIDE; +import static io.appium.java_client.service.local.flags.GeneralServerFlag.BASEPATH; import static io.github.bonigarcia.wdm.WebDriverManager.chromedriver; import static java.lang.System.getProperty; import static java.lang.System.setProperty; @@ -312,4 +313,11 @@ public void checkAbilityToStartServiceWithLogFileUsingShortFlag() { service.start(); assertTrue(testLogFile.exists()); } + + @Test + public void checkAbilityToStartServiceUsingBasePath() { + service = new AppiumServiceBuilder().withArgument(BASEPATH, "/wd/hub").build(); + service.start(); + assertTrue(service.isRunning()); + } }