@Test public void checkAbilityToStartAndShutDownFewServices() throws Exception { List<AppiumDriverLocalService> services = asList( new AppiumServiceBuilder().usingAnyFreePort().build(), new AppiumServiceBuilder().usingAnyFreePort().build(), new AppiumServiceBuilder().usingAnyFreePort().build(), new AppiumServiceBuilder().usingAnyFreePort().build()); services.parallelStream().forEach(AppiumDriverLocalService::start); assertTrue(services.stream().allMatch(AppiumDriverLocalService::isRunning)); SECONDS.sleep(1); services.parallelStream().forEach(AppiumDriverLocalService::stop); assertTrue(services.stream().noneMatch(AppiumDriverLocalService::isRunning)); }
@Test public void checkAbilityToStartServiceOnAFreePort() { service = new AppiumServiceBuilder().usingAnyFreePort().build(); service.start(); assertTrue(service.isRunning()); }
/** * @author wasiq.bhamla * @since Oct 27, 2017 12:42:30 PM */ private void setPort () { if (this.setting.getPort () > 0) { this.builder = this.builder.usingPort (this.setting.getPort ()); } else { this.builder = this.builder.usingAnyFreePort (); } } }
private URL localServerUrlFor(String deviceName) { LOGGER.info("Finding local appium server for " + deviceName); DriverService appiumDriverService = null; try { if (appiumServers.get(deviceName) != null) { appiumDriverService = appiumServers.get(deviceName); if(!appiumDriverService.isRunning()) { LOGGER.info(" -> Restarting local appium server " + appiumDriverService.getUrl()); appiumDriverService.start(); } return appiumDriverService.getUrl(); } LOGGER.info("No local appium server found for " + deviceName + " - starting a new one"); appiumDriverService = AppiumDriverLocalService.buildService(new AppiumServiceBuilder().withIPAddress("127.0.0.1"). withArgument(GeneralServerFlag.SESSION_OVERRIDE).usingAnyFreePort()); LOGGER.info("Starting service..."); appiumDriverService.start(); LOGGER.info("Service started: " + appiumDriverService.getUrl()); appiumServers.put(deviceName, appiumDriverService); index(appiumDriverService); LOGGER.info("Local appium server for " + deviceName + " started on " + appiumDriverService.getUrl()); logStatus(); return appiumDriverService.getUrl(); } catch (Throwable e) { LOGGER.info("Failed to start appium service on " + appiumDriverService.getUrl()); e.printStackTrace(); LOGGER.error("Failed to start appium service on " + appiumDriverService.getUrl()); throw new WebDriverException("Failed to start appium service on " + appiumDriverService.getUrl(), e); } }