Skip to content

Commit f62b9d1

Browse files
fix: appium#1660 - correction for ping method to get proper status URL in case of a basepath provided (appium#1661)
1 parent d3ede46 commit f62b9d1

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package io.appium.java_client.service.local;
1818

19+
import static com.google.common.base.Preconditions.checkArgument;
20+
import static com.google.common.base.Preconditions.checkNotNull;
1921
import static org.openqa.selenium.remote.CapabilityType.PLATFORM_NAME;
2022

2123
import com.google.common.collect.ImmutableList;
@@ -217,13 +219,23 @@ public AppiumServiceBuilder withArgument(ServerArgument argument, String value)
217219
case "-g":
218220
withLogFile(new File(value));
219221
break;
222+
case "--base-path":
223+
serverArguments.put(argName, sanitizeBasePath(value));
224+
break;
220225
default:
221226
serverArguments.put(argName, value);
222227
break;
223228
}
224229
return this;
225230
}
226231

232+
private static String sanitizeBasePath(String basePath) {
233+
basePath = checkNotNull(basePath).trim();
234+
checkArgument(!basePath.isEmpty(),
235+
"Given base path is not valid - blank or empty values are not allowed for base path");
236+
return basePath.endsWith("/") ? basePath : basePath + "/";
237+
}
238+
227239
/**
228240
* Adds capabilities.
229241
*

src/test/java/io/appium/java_client/service/local/ServerBuilderTest.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import static io.appium.java_client.TestUtils.getLocalIp4Address;
55
import static io.appium.java_client.service.local.AppiumDriverLocalService.buildDefaultService;
66
import static io.appium.java_client.service.local.AppiumServiceBuilder.APPIUM_PATH;
7+
import static io.appium.java_client.service.local.AppiumServiceBuilder.BROADCAST_IP_ADDRESS;
8+
import static io.appium.java_client.service.local.AppiumServiceBuilder.DEFAULT_APPIUM_PORT;
9+
import static io.appium.java_client.service.local.flags.GeneralServerFlag.BASEPATH;
710
import static io.appium.java_client.service.local.flags.GeneralServerFlag.CALLBACK_ADDRESS;
811
import static io.appium.java_client.service.local.flags.GeneralServerFlag.SESSION_OVERRIDE;
912
import static io.github.bonigarcia.wdm.WebDriverManager.chromedriver;
@@ -18,6 +21,7 @@
1821
import static org.junit.Assert.assertEquals;
1922
import static org.junit.Assert.assertFalse;
2023
import static org.junit.Assert.assertThat;
24+
import static org.junit.Assert.assertThrows;
2125
import static org.junit.Assert.assertTrue;
2226

2327
import com.google.common.collect.ImmutableMap;
@@ -312,4 +316,45 @@ public void checkAbilityToStartServiceWithLogFileUsingShortFlag() {
312316
service.start();
313317
assertTrue(testLogFile.exists());
314318
}
319+
320+
@Test
321+
public void checkAbilityToStartServiceUsingValidBasePathWithMultiplePathParams() {
322+
String baseUrl = String.format("http://%s:%d/", BROADCAST_IP_ADDRESS, DEFAULT_APPIUM_PORT);
323+
String basePath = "wd/hub";
324+
service = new AppiumServiceBuilder().withArgument(BASEPATH, basePath).build();
325+
service.start();
326+
assertTrue(service.isRunning());
327+
assertEquals(baseUrl + basePath + "/", service.getUrl().toString());
328+
}
329+
330+
@Test
331+
public void checkAbilityToStartServiceUsingValidBasePathWithSinglePathParams() {
332+
String baseUrl = String.format("http://%s:%d/", BROADCAST_IP_ADDRESS, DEFAULT_APPIUM_PORT);
333+
String basePath = "/wd/";
334+
service = new AppiumServiceBuilder().withArgument(BASEPATH, basePath).build();
335+
service.start();
336+
assertTrue(service.isRunning());
337+
assertEquals(baseUrl + basePath.substring(1), service.getUrl().toString());
338+
}
339+
340+
@Test
341+
public void checkAbilityToValidateBasePathForEmptyBasePath() {
342+
assertThrows(IllegalArgumentException.class, () -> {
343+
new AppiumServiceBuilder().withArgument(BASEPATH, "").build();
344+
});
345+
}
346+
347+
@Test
348+
public void checkAbilityToValidateBasePathForBlankBasePath() {
349+
assertThrows(IllegalArgumentException.class, () -> {
350+
new AppiumServiceBuilder().withArgument(BASEPATH, " ").build();
351+
});
352+
}
353+
354+
@Test
355+
public void checkAbilityToValidateBasePathForNullBasePath() {
356+
assertThrows(NullPointerException.class, () -> {
357+
new AppiumServiceBuilder().withArgument(BASEPATH, null).build();
358+
});
359+
}
315360
}

0 commit comments

Comments
 (0)