Search in sources :

Example 11 with MobileDevice

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

the class TestWebUiDriver method testLocalAndroidDriverWithRemoteAppiumServerAndNoDeviceId.

/**
 * Test we get an error when using remote appium and no deviceId is provided
 * @throws Exception
 */
@Test(groups = { "it" }, expectedExceptions = ConfigurationException.class)
public void testLocalAndroidDriverWithRemoteAppiumServerAndNoDeviceId() throws Exception {
    try {
        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().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);
    } finally {
        WebUIDriver.cleanUp();
    }
}
Also used : ExistingAppiumLauncher(com.seleniumtests.browserfactory.mobile.ExistingAppiumLauncher) MobileDevice(com.seleniumtests.browserfactory.mobile.MobileDevice) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test) GenericDriverTest(com.seleniumtests.GenericDriverTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) ReporterTest(com.seleniumtests.it.reporter.ReporterTest)

Example 12 with MobileDevice

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

the class TestMobileDeviceSelector method testCapabilitiesUpdate.

/**
 * Test the update of capabilities with device properties
 * input capabilities only know the name, and from that data, we expect to get the platform and version
 * plus an updated version of device name with the id instead as it's the property expected by ADB to
 * communicate with any device
 */
@Test(groups = { "ut" })
public void testCapabilitiesUpdate() {
    // available devices
    List<MobileDevice> deviceList = new ArrayList<>();
    deviceList.add(new MobileDevice("nexus 5", "1234", "android", "5.0", new ArrayList<>()));
    when(adbWrapper.getDeviceList()).thenReturn(deviceList);
    DesiredCapabilities requestedCaps = new DesiredCapabilities();
    requestedCaps.setCapability(MobileCapabilityType.DEVICE_NAME, "Nexus 5");
    deviceSelector.setAndroidReady(true);
    deviceSelector.setIosReady(false);
    MutableCapabilities updatedCaps = deviceSelector.updateCapabilitiesWithSelectedDevice(requestedCaps, DriverMode.LOCAL);
    Assert.assertEquals(updatedCaps.getCapability(MobileCapabilityType.PLATFORM_NAME), "android");
    Assert.assertEquals(updatedCaps.getCapability(MobileCapabilityType.DEVICE_NAME), "1234");
    Assert.assertEquals(updatedCaps.getCapability(MobileCapabilityType.PLATFORM_VERSION), "5.0");
    Assert.assertNull(updatedCaps.getCapability(AndroidMobileCapabilityType.CHROMEDRIVER_EXECUTABLE));
}
Also used : MobileDevice(com.seleniumtests.browserfactory.mobile.MobileDevice) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) MutableCapabilities(org.openqa.selenium.MutableCapabilities) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 13 with MobileDevice

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

the class TestMobileDeviceSelector method testSelectMostMatchingAndroidDevice.

/**
 * Test that only the device that matches all capabilities is selected
 */
@Test(groups = { "ut" })
public void testSelectMostMatchingAndroidDevice() {
    // available devices
    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);
    // requested caps
    DesiredCapabilities requestedCaps = new DesiredCapabilities();
    requestedCaps.setCapability(MobileCapabilityType.PLATFORM_NAME, "android");
    requestedCaps.setCapability(MobileCapabilityType.PLATFORM_VERSION, "6.0");
    deviceSelector.setAndroidReady(true);
    deviceSelector.setIosReady(false);
    Assert.assertEquals(deviceSelector.getRelevantMobileDevice(requestedCaps), deviceList.get(2));
}
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 14 with MobileDevice

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

the class TestMobileDeviceSelector method testSelectFirstMatchingiOSDevice.

/**
 * 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 testSelectFirstMatchingiOSDevice() {
    // 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<>()));
    deviceListIos.add(new MobileDevice("IPhone 7", "0000", "iOS", "10.3", new ArrayList<>()));
    when(instrumentsWrapper.parseIosDevices()).thenReturn(deviceListIos);
    // requested caps
    DesiredCapabilities requestedCaps = new DesiredCapabilities();
    requestedCaps.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");
    deviceSelector.setAndroidReady(true);
    deviceSelector.setIosReady(true);
    Assert.assertEquals(deviceSelector.getRelevantMobileDevice(requestedCaps), deviceListIos.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 15 with MobileDevice

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

the class TestMobileDeviceSelector method testCapabilitiesUpdateWithDriver.

/**
 * Test the update of driver capabilities when using browsers in local mode
 */
@Test(groups = { "ut" })
public void testCapabilitiesUpdateWithDriver() {
    // available devices
    List<MobileDevice> deviceList = new ArrayList<>();
    BrowserInfo chromeInfo = new BrowserInfo(BrowserType.CHROME, "47.0", null);
    chromeInfo.setDriverFileName("chromedriver.exe");
    deviceList.add(new MobileDevice("nexus 5", "1234", "android", "5.0", Arrays.asList(chromeInfo)));
    when(adbWrapper.getDeviceList()).thenReturn(deviceList);
    DesiredCapabilities requestedCaps = new DesiredCapabilities();
    requestedCaps.setCapability(MobileCapabilityType.DEVICE_NAME, "Nexus 5");
    requestedCaps.setCapability(MobileCapabilityType.BROWSER_NAME, "chrome");
    deviceSelector.setAndroidReady(true);
    deviceSelector.setIosReady(false);
    MutableCapabilities updatedCaps = deviceSelector.updateCapabilitiesWithSelectedDevice(requestedCaps, DriverMode.LOCAL);
    Assert.assertEquals(updatedCaps.getCapability(AndroidMobileCapabilityType.CHROMEDRIVER_EXECUTABLE), "chromedriver.exe");
}
Also used : MobileDevice(com.seleniumtests.browserfactory.mobile.MobileDevice) BrowserInfo(com.seleniumtests.browserfactory.BrowserInfo) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) MutableCapabilities(org.openqa.selenium.MutableCapabilities) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

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