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())); }
@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 checkAbilityToUseNodeDefinedExplicitly() { File mainJS = PATH_T0_TEST_MAIN_JS.toFile(); AppiumServiceBuilder builder = new AppiumServiceBuilder() .withAppiumJS(mainJS); assertThat(builder.createArgs().get(0), is(mainJS.getAbsolutePath())); }
/** * 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 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)); }
@Test public void checkAbilityToStartServiceWithLogFileUsingShortFlag() { testLogFile = new File("Log3.txt"); service = new AppiumServiceBuilder() .withArgument(() -> "-g", testLogFile.getAbsolutePath()) .build(); service.start(); assertTrue(testLogFile.exists()); } }
@Test public void checkAbilityToStartServiceWithLogFileUsingFlag() { testLogFile = new File("Log2.txt"); service = new AppiumServiceBuilder() .withArgument(() -> "--log", testLogFile.getAbsolutePath()) .build(); service.start(); assertTrue(testLogFile.exists()); }
@Test public void checkAbilityToStartServiceWithIpUsingShortFlag() { String expectedUrl = String.format("http://%s:4723/wd/hub", testIP); service = new AppiumServiceBuilder() .withArgument(() -> "-a", testIP) .build(); String actualUrl = service.getUrl().toString(); assertEquals(expectedUrl, actualUrl); service.start(); }
@Test public void checkAbilityToStartServiceWithPortUsingFlag() { String port = "8996"; String expectedUrl = String.format("http://0.0.0.0:%s/wd/hub", port); service = new AppiumServiceBuilder() .withArgument(() -> "--port", port) .build(); String actualUrl = service.getUrl().toString(); assertEquals(expectedUrl, actualUrl); service.start(); }
@Test public void checkAbilityToStartServiceWithPortUsingShortFlag() { String port = "8996"; String expectedUrl = String.format("http://0.0.0.0:%s/wd/hub", port); service = new AppiumServiceBuilder() .withArgument(() -> "-p", port) .build(); String actualUrl = service.getUrl().toString(); assertEquals(expectedUrl, actualUrl); service.start(); }
@Test public void checkAbilityToStartServiceWithIpUsingFlag() { String expectedUrl = String.format("http://%s:4723/wd/hub", testIP); service = new AppiumServiceBuilder() .withArgument(() -> "--address", testIP) .build(); String actualUrl = service.getUrl().toString(); assertEquals(expectedUrl, actualUrl); service.start(); }
@Test public void checkAbilityToStartServiceOnAFreePort() { service = new AppiumServiceBuilder().usingAnyFreePort().build(); service.start(); assertTrue(service.isRunning()); }
@Test public void checkAbilityToStartServiceUsingNonLocalhostIP() { service = new AppiumServiceBuilder().withIPAddress(testIP).build(); service.start(); assertTrue(service.isRunning()); }
@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(); } }
@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 startingIOSAppWithCapabilitiesAndServiceTest() { File appDir = new File("src/test/java/io/appium/java_client"); File app = new File(appDir, "UICatalog.app.zip"); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, DEVICE_NAME); capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.APPIUM); capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, PLATFORM_VERSION); //sometimes environment has performance problems capabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 500000); AppiumServiceBuilder builder = new AppiumServiceBuilder() .withArgument(GeneralServerFlag.SESSION_OVERRIDE) .withArgument(GeneralServerFlag.STRICT_CAPS); IOSDriver<?> driver = new IOSDriver<>(builder, capabilities); try { Capabilities caps = driver.getCapabilities(); assertTrue(caps.getCapability(MobileCapabilityType.PLATFORM_NAME) .toString().equalsIgnoreCase(MobilePlatform.IOS)); assertNotNull(null, caps.getCapability(MobileCapabilityType.DEVICE_NAME)); } finally { driver.quit(); } }
@Test public void checkAbilityToStartServiceUsingFlags() { service = new AppiumServiceBuilder() .withArgument(CALLBACK_ADDRESS, testIP) .withArgument(SESSION_OVERRIDE) .withArgument(PRE_LAUNCH) .build(); service.start(); assertTrue(service.isRunning()); }
@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()); }