|
4 | 4 | import static io.appium.java_client.TestUtils.getLocalIp4Address;
|
5 | 5 | import static io.appium.java_client.service.local.AppiumDriverLocalService.buildDefaultService;
|
6 | 6 | 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; |
7 | 9 | import static io.appium.java_client.service.local.flags.GeneralServerFlag.CALLBACK_ADDRESS;
|
8 | 10 | import static io.appium.java_client.service.local.flags.GeneralServerFlag.SESSION_OVERRIDE;
|
9 | 11 | import static io.appium.java_client.service.local.flags.GeneralServerFlag.BASEPATH;
|
|
20 | 22 | import static org.junit.Assert.assertFalse;
|
21 | 23 | import static org.junit.Assert.assertThat;
|
22 | 24 | import static org.junit.Assert.assertTrue;
|
| 25 | +import static org.junit.Assert.fail; |
23 | 26 |
|
24 | 27 | import com.google.common.collect.ImmutableMap;
|
25 | 28 | import io.appium.java_client.android.options.UiAutomator2Options;
|
@@ -55,6 +58,9 @@ public class ServerBuilderTest {
|
55 | 58 | private static final Path PATH_T0_TEST_MAIN_JS = ROOT_TEST_PATH
|
56 | 59 | .resolve("service").resolve("local").resolve("main.js");
|
57 | 60 |
|
| 61 | + private static final String INVALID_BASE_PATH_ERROR_MESSAGE = |
| 62 | + "Given base path is not valid - blank or empty values are not allowed for base path"; |
| 63 | + |
58 | 64 | private static String testIP;
|
59 | 65 | private AppiumDriverLocalService service;
|
60 | 66 | private File testLogFile;
|
@@ -315,9 +321,54 @@ public void checkAbilityToStartServiceWithLogFileUsingShortFlag() {
|
315 | 321 | }
|
316 | 322 |
|
317 | 323 | @Test
|
318 |
| - public void checkAbilityToStartServiceUsingBasePath() { |
319 |
| - service = new AppiumServiceBuilder().withArgument(BASEPATH, "/wd/hub").build(); |
| 324 | + public void checkAbilityToStartServiceUsingValidBasePathWithMultiplePathParams() { |
| 325 | + String baseUrl = String.format("http://%s:%d/", BROADCAST_IP_ADDRESS, DEFAULT_APPIUM_PORT); |
| 326 | + String basePath = "wd/hub"; |
| 327 | + service = new AppiumServiceBuilder().withArgument(BASEPATH, basePath).build(); |
320 | 328 | service.start();
|
321 | 329 | assertTrue(service.isRunning());
|
| 330 | + assertEquals(baseUrl + basePath + "/",service.getUrl().toString()); |
| 331 | + } |
| 332 | + |
| 333 | + @Test |
| 334 | + public void checkAbilityToStartServiceUsingValidBasePathWithSinglePathParams() { |
| 335 | + String baseUrl = String.format("http://%s:%d/", BROADCAST_IP_ADDRESS, DEFAULT_APPIUM_PORT); |
| 336 | + String basePath = "/wd/"; |
| 337 | + service = new AppiumServiceBuilder().withArgument(BASEPATH, basePath).build(); |
| 338 | + service.start(); |
| 339 | + assertTrue(service.isRunning()); |
| 340 | + assertEquals(baseUrl + basePath.substring(1) ,service.getUrl().toString()); |
| 341 | + } |
| 342 | + |
| 343 | + @Test |
| 344 | + public void checkAbilityToValidateBasePathForEmptyBasePath() { |
| 345 | + try { |
| 346 | + service = new AppiumServiceBuilder().withArgument(BASEPATH, "").build(); |
| 347 | + fail("Base path was not validated for Blank or Empty string"); |
| 348 | + } catch (Exception e) { |
| 349 | + assertEquals(InvalidBasePathException.class, e.getClass()); |
| 350 | + assertEquals(INVALID_BASE_PATH_ERROR_MESSAGE, e.getMessage()); |
| 351 | + } |
| 352 | + } |
| 353 | + |
| 354 | + @Test |
| 355 | + public void checkAbilityToValidateBasePathForBlankBasePath() { |
| 356 | + try { |
| 357 | + service = new AppiumServiceBuilder().withArgument(BASEPATH, " ").build(); |
| 358 | + fail("Base path was not validated for Blank or Empty string"); |
| 359 | + } catch (Exception e) { |
| 360 | + assertEquals(InvalidBasePathException.class, e.getClass()); |
| 361 | + assertEquals(INVALID_BASE_PATH_ERROR_MESSAGE, e.getMessage()); |
| 362 | + } |
| 363 | + } |
| 364 | + |
| 365 | + @Test |
| 366 | + public void checkAbilityToValidateBasePathForNullBasePath() { |
| 367 | + try { |
| 368 | + service = new AppiumServiceBuilder().withArgument(BASEPATH, null).build(); |
| 369 | + fail("Base path was not validated for a null value"); |
| 370 | + } catch (Exception e) { |
| 371 | + assertEquals(NullPointerException.class, e.getClass()); |
| 372 | + } |
322 | 373 | }
|
323 | 374 | }
|
0 commit comments