@Override protected String perform() { service.start(); return "OK"; } };
@Test public void checkAbilityToChangeOutputStream() throws Exception { testLogFile = new File("test"); testLogFile.createNewFile(); stream = new FileOutputStream(testLogFile); service = buildDefaultService(); service.addOutPutStream(stream); service.start(); assertThat(testLogFile.length(), greaterThan(0L)); }
/** * 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 checkAbilityToChangeOutputStreamAfterTheServiceIsStarted() throws Exception { testLogFile = new File("test"); testLogFile.createNewFile(); stream = new FileOutputStream(testLogFile); service = buildDefaultService(); service.start(); service.addOutPutStream(stream); service.isRunning(); assertThat(testLogFile.length(), greaterThan(0L)); }
/** * initialization. */ @BeforeClass public static void beforeClass() { service = AppiumDriverLocalService.buildDefaultService(); service.start(); if (service == null || !service.isRunning()) { throw new ExceptionInInitializerError("An appium server node is not started!"); } }
@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 checkAbilityToStartServiceWithLogFileUsingFlag() { testLogFile = new File("Log2.txt"); service = new AppiumServiceBuilder() .withArgument(() -> "--log", testLogFile.getAbsolutePath()) .build(); service.start(); assertTrue(testLogFile.exists()); }
@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 checkAbilityToAddLogMessageConsumer() { List<String> log = new ArrayList<>(); service = buildDefaultService(); service.clearOutPutStreams(); service.addLogMessageConsumer(log::add); service.start(); assertTrue(log.size() > 0); }
@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 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 checkAbilityToStartDefaultService() { service = buildDefaultService(); service.start(); assertTrue(service.isRunning()); }
@Test public void checkAbilityToShutDownService() { service = buildDefaultService(); service.start(); service.stop(); assertFalse(service.isRunning()); }
@Test public void checkAbilityToStartServiceUsingNonLocalhostIP() { service = new AppiumServiceBuilder().withIPAddress(testIP).build(); service.start(); assertTrue(service.isRunning()); }
@Test public void checkAbilityToStartServiceOnAFreePort() { service = new AppiumServiceBuilder().usingAnyFreePort().build(); service.start(); assertTrue(service.isRunning()); }
/** * The setting up. */ @Before public void setUp() { service = AppiumDriverLocalService.buildDefaultService(); service.start(); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator"); capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, MobileBrowserType.BROWSER); driver = new AndroidDriver<RemoteWebElement>(service.getUrl(), capabilities); //This time out is set because test can be run on slow Android SDK emulator PageFactory.initElements(new AppiumFieldDecorator(driver, ofSeconds(5)), this); }
@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 checkAbilityToStartServiceUsingFlags() { service = new AppiumServiceBuilder() .withArgument(CALLBACK_ADDRESS, testIP) .withArgument(SESSION_OVERRIDE) .withArgument(PRE_LAUNCH) .build(); service.start(); assertTrue(service.isRunning()); }