@Test public void checkAbilityToStartServiceUsingFlags() { service = new AppiumServiceBuilder() .withArgument(CALLBACK_ADDRESS, testIP) .withArgument(SESSION_OVERRIDE) .withArgument(PRE_LAUNCH) .build(); service.start(); assertTrue(service.isRunning()); }
/** * Starts a local server. * * @return ip of a local host * @throws UnknownHostException when it is impossible to get ip address of a local host */ public static String startAppiumServer() throws UnknownHostException { service = new AppiumServiceBuilder() .usingPort(PORT).build(); service.start(); InetAddress inetAddress = InetAddress.getLocalHost(); return inetAddress.getHostAddress(); }
@Test public void checkAbilityToStartServiceUsingNonLocalhostIP() { service = new AppiumServiceBuilder().withIPAddress(testIP).build(); service.start(); assertTrue(service.isRunning()); }
public AppiumServiceBuilder() { usingPort(DEFAULT_APPIUM_PORT); withEnvironment(System.getenv()); }
/** * 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 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 checkAbilityToStartServiceWithLogFile() throws Exception { testLogFile = new File("Log.txt"); testLogFile.createNewFile(); service = new AppiumServiceBuilder().withLogFile(testLogFile).build(); service.start(); assertTrue(testLogFile.exists()); assertThat(testLogFile.length(), greaterThan(0L)); }
serBuilder=new AppiumServiceBuilder().withAppiumJS(new File("/usr/local/lib/node_modules/appium/build/lib/main.js")).usingPort(7000); service = serBuilder.build(); service.start();
@Test public void checkAbilityToStartServiceUsingCapabilitiesAndFlags() { File app = ROOT_TEST_PATH.resolve("ApiDemos-debug.apk").toFile(); DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability(PLATFORM_NAME, "Android"); caps.setCapability(FULL_RESET, true); caps.setCapability(NEW_COMMAND_TIMEOUT, 60); caps.setCapability(APP_PACKAGE, "io.appium.android.apis"); caps.setCapability(APP_ACTIVITY, ".view.WebView1"); caps.setCapability(APP, app.getAbsolutePath()); caps.setCapability(CHROMEDRIVER_EXECUTABLE, chromeManager.getBinaryPath()); service = new AppiumServiceBuilder() .withArgument(CALLBACK_ADDRESS, testIP) .withArgument(SESSION_OVERRIDE) .withArgument(PRE_LAUNCH) .withCapabilities(caps).build(); service.start(); assertTrue(service.isRunning()); }
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); } }
@Test public void startingIOSAppWithCapabilitiesAndFlagsOnServerSideTest() { DesiredCapabilities serverCapabilities = new DesiredCapabilities(); serverCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, DEVICE_NAME); serverCapabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 500000); //some environment is too slow serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, PLATFORM_VERSION); serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.IOS); File appDir = new File("src/test/java/io/appium/java_client"); File app = new File(appDir, "UICatalog.app.zip"); DesiredCapabilities clientCapabilities = new DesiredCapabilities(); clientCapabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); AppiumServiceBuilder builder = new AppiumServiceBuilder() .withArgument(GeneralServerFlag.SESSION_OVERRIDE) .withArgument(GeneralServerFlag.STRICT_CAPS).withCapabilities(serverCapabilities); IOSDriver<?> driver = new IOSDriver<>(builder, clientCapabilities); try { Capabilities caps = driver.getCapabilities(); assertTrue(caps.getCapability(MobileCapabilityType.PLATFORM_NAME) .toString().equalsIgnoreCase(MobilePlatform.IOS)); assertNotEquals(null, caps.getCapability(MobileCapabilityType.DEVICE_NAME)); } finally { driver.quit(); } } }
@Test public void checkAbilityToStartServiceUsingCapabilities() { File app = ROOT_TEST_PATH.resolve("ApiDemos-debug.apk").toFile(); DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability(PLATFORM_NAME, "Android"); caps.setCapability(FULL_RESET, true); caps.setCapability(NEW_COMMAND_TIMEOUT, 60); caps.setCapability(APP_PACKAGE, "io.appium.android.apis"); caps.setCapability(APP_ACTIVITY, ".view.WebView1"); caps.setCapability(APP, app.getAbsolutePath()); caps.setCapability(CHROMEDRIVER_EXECUTABLE, chromeManager.getBinaryPath()); service = new AppiumServiceBuilder().withCapabilities(caps).build(); service.start(); assertTrue(service.isRunning()); }
@Test public void checkAbilityToUseNodeDefinedExplicitly() { File mainJS = PATH_T0_TEST_MAIN_JS.toFile(); AppiumServiceBuilder builder = new AppiumServiceBuilder() .withAppiumJS(mainJS); assertThat(builder.createArgs().get(0), is(mainJS.getAbsolutePath())); }
@Test public void startingAndroidAppWithCapabilitiesAndServiceTest() { File appDir = new File("src/test/java/io/appium/java_client"); File app = new File(appDir, "ApiDemos-debug.apk"); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator"); capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); AppiumServiceBuilder builder = new AppiumServiceBuilder() .withArgument(GeneralServerFlag.SESSION_OVERRIDE) .withArgument(GeneralServerFlag.STRICT_CAPS); AndroidDriver<?> driver = new AndroidDriver<>(builder, capabilities); try { Capabilities caps = driver.getCapabilities(); assertEquals(MobilePlatform.ANDROID, caps.getCapability(MobileCapabilityType.PLATFORM_NAME)); assertNotEquals(null, caps.getCapability(MobileCapabilityType.DEVICE_NAME)); } finally { driver.quit(); } }
public static AppiumDriverLocalService buildDefaultService() { return buildService(new AppiumServiceBuilder()); }
protected boolean check(Supplier<DesiredCapabilities> serverCapabilitiesSupplier, Supplier<Capabilities> clientCapabilitiesSupplier, BiPredicate<By, Class<? extends WebElement>> filter, By by, Class<? extends WebElement> clazz) { AppiumServiceBuilder builder = new AppiumServiceBuilder() .withCapabilities(serverCapabilitiesSupplier.get()); driver = new AppiumDriver<>(builder, clientCapabilitiesSupplier.get()); return filter.test(by, clazz); }
@Test public void checkAbilityToFindNodeDefinedInProperties() { File definedNode = PATH_T0_TEST_MAIN_JS.toFile(); setProperty(APPIUM_PATH, definedNode.getAbsolutePath()); assertThat(new AppiumServiceBuilder().createArgs().get(0), is(definedNode.getAbsolutePath())); }
public AppiumDriver(AppiumServiceBuilder builder, HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) { this(builder.build(), httpClientFactory, desiredCapabilities); }
/** * @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 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..."); }