/** * Adds a server argument. * * @param argument is an instance which contains the argument name. * @param value A non null string value. (Warn!!!) Boolean arguments have a special moment: * the presence of an arguments means "true". At this case an empty string * should be defined. * @return the self-reference. */ public AppiumServiceBuilder withArgument(ServerArgument argument, String value) { String argName = argument.getArgument().trim().toLowerCase(); if ("--port".equals(argName) || "-p".equals(argName)) { usingPort(Integer.valueOf(value)); } else if ("--address".equals(argName) || "-a".equals(argName)) { withIPAddress(value); } else if ("--log".equals(argName) || "-g".equals(argName)) { withLogFile(new File(value)); } else { serverArguments.put(argName, value); } return this; }
@Test public void checkAbilityToStartServiceUsingNonLocalhostIP() { service = new AppiumServiceBuilder().withIPAddress(testIP).build(); service.start(); assertTrue(service.isRunning()); }
/** * Adds a server argument. * * @param argument is an instance which contains the argument name. * @param value A non null string value. (Warn!!!) Boolean arguments have a special moment: * the presence of an arguments means "true". At this case an empty string * should be defined. * @return the self-reference. */ public AppiumServiceBuilder withArgument(ServerArgument argument, String value) { String argName = argument.getArgument().trim().toLowerCase(); if ("--port".equals(argName) || "-p".equals(argName)) { usingPort(Integer.valueOf(value)); } else if ("--address".equals(argName) || "-a".equals(argName)) { withIPAddress(value); } else if ("--log".equals(argName) || "-g".equals(argName)) { withLogFile(new File(value)); } else { serverArguments.put(argName, value); } return this; }
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); } }
private void buildService () { log.trace ("Building Appium Service started..."); checkServerConfigParams ("IP Host Address", this.setting.getHost ()); this.builder = this.builder.withIPAddress (this.setting.getHost ()) .withStartUpTimeOut (this.setting.getStartUpTimeOutSeconds (), TimeUnit.SECONDS); setPort (); setLogFile (); setAppiumJS (); setNodeExe (); setCapabilities (); setArguments (); setEnvironmentVariables (); log.trace ("Building Appium Service done..."); }