Search in sources :

Example 6 with MobileDevice

use of com.seleniumtests.browserfactory.mobile.MobileDevice in project seleniumRobot by bhecquet.

the class TestMobileDeviceSelector method testSelectFirstMatchingAndroidDevice.

/**
 * Test that when several devices exists with the same capabilities, the first one is selected
 * Test platform name with different cases
 */
@Test(groups = { "ut" })
public void testSelectFirstMatchingAndroidDevice() {
    // available devices
    List<MobileDevice> deviceListAndroid = new ArrayList<>();
    deviceListAndroid.add(new MobileDevice("Nexus 5", "1234", "Android", "5.0", new ArrayList<>()));
    deviceListAndroid.add(new MobileDevice("Nexus 7", "1235", "Android", "6.0", new ArrayList<>()));
    when(adbWrapper.getDeviceList()).thenReturn(deviceListAndroid);
    List<MobileDevice> deviceListIos = new ArrayList<>();
    deviceListIos.add(new MobileDevice("IPhone 6", "0000", "iOS", "10.2", new ArrayList<>()));
    when(instrumentsWrapper.parseIosDevices()).thenReturn(deviceListIos);
    // requested caps
    DesiredCapabilities requestedCaps = new DesiredCapabilities();
    requestedCaps.setCapability(MobileCapabilityType.PLATFORM_NAME, "android");
    deviceSelector.setAndroidReady(true);
    deviceSelector.setIosReady(true);
    Assert.assertEquals(deviceSelector.getRelevantMobileDevice(requestedCaps), deviceListAndroid.get(0));
}
Also used : MobileDevice(com.seleniumtests.browserfactory.mobile.MobileDevice) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 7 with MobileDevice

use of com.seleniumtests.browserfactory.mobile.MobileDevice in project seleniumRobot by bhecquet.

the class TestMobileDeviceSelector method testSelectNonExistingAndroidDevice.

/**
 * Test that an error is raised when no matching device is found
 */
@Test(groups = { "ut" }, expectedExceptions = ConfigurationException.class)
public void testSelectNonExistingAndroidDevice() {
    // available devices
    List<MobileDevice> deviceList = new ArrayList<>();
    when(adbWrapper.getDeviceList()).thenReturn(deviceList);
    // requested caps
    DesiredCapabilities requestedCaps = new DesiredCapabilities();
    requestedCaps.setCapability(MobileCapabilityType.PLATFORM_NAME, "android");
    deviceSelector.setAndroidReady(true);
    deviceSelector.setIosReady(false);
    deviceSelector.getRelevantMobileDevice(requestedCaps);
}
Also used : MobileDevice(com.seleniumtests.browserfactory.mobile.MobileDevice) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 8 with MobileDevice

use of com.seleniumtests.browserfactory.mobile.MobileDevice in project seleniumRobot by bhecquet.

the class TestWebUiDriver method testLocaliOSDriverWithRemoteAppiumServer.

@Test(groups = { "it" })
public void testLocaliOSDriverWithRemoteAppiumServer() throws Exception {
    whenNew(InstrumentsWrapper.class).withNoArguments().thenReturn(instrumentsWrapper);
    List<MobileDevice> deviceList = new ArrayList<>();
    when(instrumentsWrapper.parseIosDevices()).thenReturn(deviceList);
    whenNew(IOSDriver.class).withAnyArguments().thenReturn(iosDriver);
    when(iosDriver.manage()).thenReturn(driverOptions);
    when(iosDriver.getCapabilities()).thenReturn(DesiredCapabilities.chrome());
    when(driverOptions.timeouts()).thenReturn(timeouts);
    SeleniumTestsContextManager.getThreadContext().setRunMode("local");
    SeleniumTestsContextManager.getThreadContext().setAppiumServerUrl("http://localhost:4321/wd/hub/");
    SeleniumTestsContextManager.getThreadContext().setDeviceId("123456");
    SeleniumTestsContextManager.getThreadContext().setPlatform("ios");
    SeleniumTestsContextManager.getThreadContext().setMobilePlatformVersion("13.0");
    SeleniumTestsContextManager.getThreadContext().setTestType(TestType.APPIUM_APP_IOS);
    createServerMock("GET", "/wd/hub/sessions", 200, "{}");
    PowerMockito.mockStatic(AppiumLauncherFactory.class);
    ExistingAppiumLauncher appiumLauncher;
    appiumLauncher = spy(new ExistingAppiumLauncher("http://localhost:4321/wd/hub/"));
    when(AppiumLauncherFactory.getInstance()).thenReturn(appiumLauncher);
    WebUIDriver.getWebDriver(true);
    PowerMockito.verifyNew(IOSDriver.class).withArguments(any(URL.class), any(Capabilities.class));
    WebUIDriver.cleanUp();
    verify(appiumLauncher).stopAppium();
}
Also used : ExistingAppiumLauncher(com.seleniumtests.browserfactory.mobile.ExistingAppiumLauncher) IOSDriver(io.appium.java_client.ios.IOSDriver) MobileDevice(com.seleniumtests.browserfactory.mobile.MobileDevice) Capabilities(org.openqa.selenium.Capabilities) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) ArrayList(java.util.ArrayList) URL(java.net.URL) Test(org.testng.annotations.Test) GenericDriverTest(com.seleniumtests.GenericDriverTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) ReporterTest(com.seleniumtests.it.reporter.ReporterTest)

Example 9 with MobileDevice

use of com.seleniumtests.browserfactory.mobile.MobileDevice in project seleniumRobot by bhecquet.

the class TestWebUiDriver method testLocalAndroidDriver.

@Test(groups = { "it" })
public void testLocalAndroidDriver() throws Exception {
    whenNew(AdbWrapper.class).withNoArguments().thenReturn(adbWrapper);
    List<MobileDevice> deviceList = new ArrayList<>();
    deviceList.add(new MobileDevice("IPhone 6", "0000", "ios", "10.2", new ArrayList<>()));
    deviceList.add(new MobileDevice("Nexus 5", "1234", "android", "5.0", new ArrayList<>()));
    deviceList.add(new MobileDevice("Nexus 7", "1235", "android", "6.0", new ArrayList<>()));
    when(adbWrapper.getDeviceList()).thenReturn(deviceList);
    whenNew(AndroidDriver.class).withAnyArguments().thenReturn(androidDriver);
    when(androidDriver.manage()).thenReturn(driverOptions);
    when(androidDriver.getCapabilities()).thenReturn(DesiredCapabilities.chrome());
    when(driverOptions.timeouts()).thenReturn(timeouts);
    SeleniumTestsContextManager.getThreadContext().setRunMode("local");
    SeleniumTestsContextManager.getThreadContext().setPlatform("android");
    SeleniumTestsContextManager.getThreadContext().setMobilePlatformVersion("5.0");
    SeleniumTestsContextManager.getThreadContext().setTestType(TestType.APPIUM_APP_ANDROID);
    PowerMockito.mockStatic(AppiumLauncherFactory.class);
    LocalAppiumLauncher appiumLauncher;
    try {
        appiumLauncher = spy(new LocalAppiumLauncher());
        when(AppiumLauncherFactory.getInstance()).thenReturn(appiumLauncher);
        WebUIDriver.getWebDriver(true);
    } catch (ConfigurationException e) {
        throw new SkipException("Test skipped, appium not correctly configured", e);
    }
    PowerMockito.verifyNew(AndroidDriver.class).withArguments(any(URL.class), any(Capabilities.class));
    verify(appiumLauncher).stopAppium();
}
Also used : MobileDevice(com.seleniumtests.browserfactory.mobile.MobileDevice) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) Capabilities(org.openqa.selenium.Capabilities) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) ArrayList(java.util.ArrayList) LocalAppiumLauncher(com.seleniumtests.browserfactory.mobile.LocalAppiumLauncher) SkipException(org.testng.SkipException) AndroidDriver(io.appium.java_client.android.AndroidDriver) URL(java.net.URL) Test(org.testng.annotations.Test) GenericDriverTest(com.seleniumtests.GenericDriverTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) ReporterTest(com.seleniumtests.it.reporter.ReporterTest)

Example 10 with MobileDevice

use of com.seleniumtests.browserfactory.mobile.MobileDevice in project seleniumRobot by bhecquet.

the class TestWebUiDriver method testLocalAndroidDriverWithRemoteAppiumServer.

/**
 * Test we can connect to a remote appium server (no local devices)
 * @throws Exception
 */
@Test(groups = { "it" })
public void testLocalAndroidDriverWithRemoteAppiumServer() throws Exception {
    whenNew(AdbWrapper.class).withNoArguments().thenReturn(adbWrapper);
    List<MobileDevice> deviceList = new ArrayList<>();
    when(adbWrapper.getDeviceList()).thenReturn(deviceList);
    whenNew(AndroidDriver.class).withAnyArguments().thenReturn(androidDriver);
    when(androidDriver.manage()).thenReturn(driverOptions);
    when(androidDriver.getCapabilities()).thenReturn(DesiredCapabilities.chrome());
    when(driverOptions.timeouts()).thenReturn(timeouts);
    SeleniumTestsContextManager.getThreadContext().setRunMode("local");
    SeleniumTestsContextManager.getThreadContext().setAppiumServerUrl("http://localhost:4321/wd/hub/");
    SeleniumTestsContextManager.getThreadContext().setDeviceId("emulator-5556");
    SeleniumTestsContextManager.getThreadContext().setPlatform("android");
    SeleniumTestsContextManager.getThreadContext().setMobilePlatformVersion("5.0");
    SeleniumTestsContextManager.getThreadContext().setTestType(TestType.APPIUM_APP_ANDROID);
    createServerMock("GET", "/wd/hub/sessions", 200, "{}");
    PowerMockito.mockStatic(AppiumLauncherFactory.class);
    ExistingAppiumLauncher appiumLauncher;
    appiumLauncher = spy(new ExistingAppiumLauncher("http://localhost:4321/wd/hub/"));
    when(AppiumLauncherFactory.getInstance()).thenReturn(appiumLauncher);
    WebUIDriver.getWebDriver(true);
    PowerMockito.verifyNew(AndroidDriver.class).withArguments(any(URL.class), any(Capabilities.class));
    WebUIDriver.cleanUp();
    verify(appiumLauncher).stopAppium();
}
Also used : ExistingAppiumLauncher(com.seleniumtests.browserfactory.mobile.ExistingAppiumLauncher) MobileDevice(com.seleniumtests.browserfactory.mobile.MobileDevice) Capabilities(org.openqa.selenium.Capabilities) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) ArrayList(java.util.ArrayList) AndroidDriver(io.appium.java_client.android.AndroidDriver) URL(java.net.URL) Test(org.testng.annotations.Test) GenericDriverTest(com.seleniumtests.GenericDriverTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) ReporterTest(com.seleniumtests.it.reporter.ReporterTest)

Aggregations

MobileDevice (com.seleniumtests.browserfactory.mobile.MobileDevice)16 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)16 Test (org.testng.annotations.Test)16 ArrayList (java.util.ArrayList)14 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)13 MockitoTest (com.seleniumtests.MockitoTest)12 GenericDriverTest (com.seleniumtests.GenericDriverTest)4 ReporterTest (com.seleniumtests.it.reporter.ReporterTest)4 ExistingAppiumLauncher (com.seleniumtests.browserfactory.mobile.ExistingAppiumLauncher)3 URL (java.net.URL)3 Capabilities (org.openqa.selenium.Capabilities)3 MutableCapabilities (org.openqa.selenium.MutableCapabilities)3 BrowserInfo (com.seleniumtests.browserfactory.BrowserInfo)2 AndroidDriver (io.appium.java_client.android.AndroidDriver)2 AdbWrapper (com.seleniumtests.browserfactory.mobile.AdbWrapper)1 InstrumentsWrapper (com.seleniumtests.browserfactory.mobile.InstrumentsWrapper)1 LocalAppiumLauncher (com.seleniumtests.browserfactory.mobile.LocalAppiumLauncher)1 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)1 IOSDriver (io.appium.java_client.ios.IOSDriver)1 SkipException (org.testng.SkipException)1