android-emulator-runner icon indicating copy to clipboard operation
android-emulator-runner copied to clipboard

Blank/Empty screenshot

Open cmonfortep opened this issue 2 years ago • 9 comments

Hello,

A part of another project, we were playing around if it's possible to take an screenshot when running some tests. We are having problems with that since all the screenshots we pull are empty/blank.

To reproduce it, it's as simple ase using the following steps in a github action.

      - name: Test
        uses: reactiveCircus/android-emulator-runner@v2
        with:
          api-level: 29
          force-avd-creation: false
          arch: x86_64
          target: google_apis
          profile: Nexus 6
          script: adb shell screencap -p /data/local/tmp/Screenshot.png; adb pull /data/local/tmp/Screenshot.png Screenshot.png;

      - name: Upload screenshot
        if: always()
        uses: actions/upload-artifact@v3
        with:
          name: device-screenshot
          path: ./*Screenshot.png

Are we missing something? is it expected that screenshots are blank/empty when using emulators inside github actions?

cmonfortep avatar Oct 05 '22 22:10 cmonfortep

@cmonfortep By default, this action starts the emulator headlessly with -no-window. This might be the reason screenshots are not showing up. Try explicitly overriding that in your emulator options and let me know how your screenshots are appearing after.

EDIT Screenshots are possible with -no-window

mrk-han avatar Oct 05 '22 22:10 mrk-han

Thanks, I've tested it multiple times with different setups and I'm always getting the same emtpy/blank png.

This is the latest I tested, and no luck.

      - name: Android checks
        uses: reactiveCircus/android-emulator-runner@v2
        with:
          api-level: 29
          force-avd-creation: false
          arch: x86_64
          target: google_apis
          profile: Nexus 6
          emulator-options: -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim
          script: adb shell screencap -p /data/local/tmp/Screenshot.png; adb pull /data/local/tmp/Screenshot.png Screenshot.png;

cmonfortep avatar Oct 05 '22 23:10 cmonfortep

Are you able to attach the verbose log of the run?

mrk-han avatar Oct 05 '22 23:10 mrk-han

I'm playing around with a dummy repository I have. You can take a look to the run here

cmonfortep avatar Oct 05 '22 23:10 cmonfortep

Hmmm, one question is do you think if we did this same setup without using reactivecircus's action, that screenshots would be working fine?

Maybe we can alter your demo to do the same thing without this action handling the emulator startup.

mrk-han avatar Oct 06 '22 02:10 mrk-han

I expect they will work as well, any reason why they shouldn't work?

I've also seen people running screenshot tests on headless emulators, I don't think that's an issue. As a reference, this issue (https://github.com/ReactiveCircus/android-emulator-runner/issues/196) is about screenshots, and the emulator options they are using is -no-window.

cmonfortep avatar Oct 06 '22 12:10 cmonfortep

@cmonfortep Hey, one of my coworkers had this same issue and said they fixed it by setting this:

         sourceCompatibility = 1.8
         targetCompatibility = 1.8

https://stackoverflow.com/questions/57838904/emulators-cant-load-libgles-emulation-driver

mrk-han avatar Oct 07 '22 00:10 mrk-han

Thanks @mrk-han. We have that in our app, and on my dummy app for testing.

Let's see if someone could bring more light here about possible issues around screenshots.

cmonfortep avatar Oct 11 '22 09:10 cmonfortep

@cmonfortep I tried to use the new screenshot APIs and was able to get some output. Had to update to Espresso 3.5.0 Alphas

That's the last thing I can suggest for now.

Make sure to also bring in androidTestUtil "androidx.test.services:test-services:$servicesVersion" and set testInstrumentationRunnerArguments useTestStorageService: 'true' in your defaultConfig

Can check this for a sample too https://github.com/android/testing-samples/blob/main/ui/espresso/ScreenshotSample/app/build.gradle

Would change the artifacts to catch the output, and if you want to excplitiyl take a screenshot instead of relying on the default behavior during test failure then can use:


/// in base test
    @get:Rule
    var nameRule = TestName()
    
///    then inside your test
   takeScreenshot.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}_Screenshot")  // Takes screenshot of entire page        

updated .yml

 - name: Upload screenshot
        if: always()
        uses: actions/upload-artifact@v3
        with:
          name: device-screenshot
          path:  |
            **/app/build/reports/**
            **/app/build/outputs/**

mrk-han avatar Oct 11 '22 15:10 mrk-han

@cmonfortep See: https://github.com/ReactiveCircus/android-emulator-runner/issues/272#issuecomment-1282877350

I don't think this is related to the android-emulator-runner action

mrk-han avatar Oct 18 '22 19:10 mrk-han

Closing because this does not seem related to the android-emulator-runner action. See: https://github.com/ReactiveCircus/android-emulator-runner/issues/272#issuecomment-1282877350

mrk-han avatar Oct 19 '22 19:10 mrk-han

A solution would be appreciated,. check : https://github.com/actions/runner/issues/2287#issuecomment-1350488499

seems like some people succeed to use runner with android emulator

kopax-polyconseil avatar Dec 14 '22 12:12 kopax-polyconseil

@kopax-polyconseil Using gpu -host on the Github Hosted macOS Runners shouldn't work. We don't have GPU access

mrk-han avatar Dec 16 '22 19:12 mrk-han

I used to be able to take screenshots with this Action, but now they are mostly coming out blank.

This might be the root case, in case anyone wants to follow: https://github.com/actions/runner-images/issues/6814

zommerfelds avatar Feb 02 '23 07:02 zommerfelds

Hi,

Try updating to latest Canary version of emulator. I've verified that latest Canary version of emulator no longer has the issue of making blank screenshots. https://github.com/actions/runner-images/issues/6814#issuecomment-1419003014

Also check the Issuetracker issue where I found this fix for more details: https://issuetracker.google.com/issues/259111479#comment3

I'm not familiar with this runner but setting channel parameter to canary should pull the Canary version of emulator.

vpuonti avatar Feb 07 '23 08:02 vpuonti