mardi 16 mai 2017

Android automation tests with Appium

I want to launch some automated tests in my Android app using Appium.

I'm adding these dependencies in my gradle file:

compile 'io.appium:java-client:4.0.0'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support:support-annotations:25.3.1'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'

and creating an Appium class where I define my AndroidDriver setting up the DesiredCapabilities.

capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());

driver = new AndroidDriver(urlConnection.getURL(), capabilities);

My first unit test is creating the driver first of all

@Before
public void setUp() throws MalformedURLException {
    try {
        Appium.connectAppium();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

@Test
public void myTest() {
    if (Appium.getDriver() != null) {
        // Test
    }
}

First question...

Must I always define the APK location even if the tests are in the same Android project? Cannot I use just somehow the package name/activityName?

File app  = new File("D:\\Users\\myUser\\Documents\\Android\\android-project\\app\\build\\outputs\\apk\\app-debug.apk");
URL url = new URL ("http://ift.tt/1eWSHgW");
URLConnection urlConnection = url.openConnection();

Second question...

When launching my unit test against Appium Desktop (Appium v1.6.4) and using Android Emulator I always get an error:

[ADB] Error: my.package/my.package.modules.startup.StartActivity or my.package.debug.modules.startup.StartActivity never started
at Object.wrappedLogger.errorAndThrow...

Aucun commentaire:

Enregistrer un commentaire