Problem with running android tests on emulator


#1

I am trying to run android test with Espresso and getting this error "android.support.test.espresso.PerformException: Error performing ‘single click’ on view ‘with id: …’.
at android.support.test.espresso.PerformException$Builder.build(PerformException.java:83)"
Everything works locally on Android emulator, real device and genymotion. Trying to find solution I also implemented code to wakeup, unlock device and remove tutorial message:

private void prepareDevice() {
    try {
        device.wakeUp();
    } catch (RemoteException e) {
        e.printStackTrace();
    }

    try {
        new UiObject(new UiSelector().className("android.widget.Button").text("OK")
        ).click();
    } catch (UiObjectNotFoundException e) {
        e.printStackTrace();
    }

    int dHeight = device.getDisplayHeight();
    int dWidth = device.getDisplayWidth();

    device.click(dWidth / 2, dHeight / 2);
}

This didn’t help so I implemented code to get device screenshot but the same problem - it works only locally and doesn’t work on emulator:

 - wget http://imgur.com/tools/imgurbash.sh
 - chmod a+x imgurbash.sh
 - adb shell screencap -p | sed 's/\r$//' > alua.png
 - ./imgurbash.sh alua.png

It seems I spent about several days to run android tests on circle without success. Please help! :wink:

P. S. My circle.yml:

machine:
    environment:
        GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError"'
        PATH: "~/$CIRCLE_PROJECT_REPONAME/gradle-2.9/bin:$PATH"
        TERM: "dumb"
        ADB_INSTALL_TIMEOUT: "10"
    java:
        version: oraclejdk7

general:
  branches:
    only:
      - master

dependencies:
  pre:
    - wget "https://services.gradle.org/distributions/gradle-2.9-bin.zip"; unzip gradle-2.9-bin.zip
    - echo y | android update sdk --no-ui --all --filter tool,extra-android-m2repository,extra-android-support,extra-google-google_play_services,extra-google-m2repository,android-23
    - echo y | android update sdk --no-ui --all --filter build-tools-23.0.2

test:
    pre:
         - emulator -avd circleci-android22 -no-audio -no-window:
             background: true
             parallel: true
         - circle-android wait-for-boot
         - sleep 70
         - adb shell input keyevent 82

         - wget http://imgur.com/tools/imgurbash.sh
         - chmod a+x imgurbash.sh
         - adb shell screencap -p | sed 's/\r$//' > alua.png
         - ./imgurbash.sh alua.png

         - sleep 5
         - fb-adb shell input touchscreen swipe 370 735 371 735
         - sleep 5

    override:
         - ./gradlew connectedAndroidTest -PdisablePreDex --stacktrace

         - ./gradlew assembleRelease -PdisablePreDex --stacktrace
         - ./gradlew testDevReleaseUnitTest --continue --stacktrace
         - ./gradlew testStageReleaseUnitTest --continue --stacktrace

    post:
         - cp -r app/build/reports $CIRCLE_ARTIFACTS
         - cp -r app/build/outputs $CIRCLE_ARTIFACTS
         - cp -r app/build/outputs/androidTest-results/* $CIRCLE_TEST_REPORTS
         - mkdir $CIRCLE_TEST_REPORTS/junit
         - find */build/test-results -name "*.xml" -exec cp {} $CIRCLE_TEST_REPORTS/junit/ \;

#2

Have you tried to re-run your test suite with VNC enabled? If not, here are the docs to VNC into a builder.

From the little Android development I’ve done, I know the emulators can be flakey, and are sensitive to events like an alert window popping up, which can cause a test suite to freeze up. Hopefully, re-running your tests from VNC might show you something funny that the Android emulator is doing.

Let us know if that helps!


#3

I connected with VNC, created screenshot, but I couldn’t copy it - “Permission denied”. Also I tried like several hours to push screenshot on image server without success. Now I have no ideas how to do it.


#4

Where was the screenshot created, and how did you attempt to copy it?


#5

I used scp command, screenshot was created in project folder and I got permission denied alert.


#6

Does your app require Google Play services? The circleci-android22 avd does not have it installed.


#7

It doesn’t require.


#8