firebase / firebase-testlab-instr-lib

Apache License 2.0
13 stars 17 forks source link

Test Lab notepad sample app not capturing screenshots in API 30 #19

Open mobileappfactory1 opened 1 year ago

mobileappfactory1 commented 1 year ago

Test Lab notepad sample app not capturing screenshots in API 30

Below method called in NotePadTest.java file Screenshot.capture(activityRule.getActivity()).process();

Got below crash in firebase test lab console java.io.IOException: The directory /sdcard/screenshots does not exist and could not be created or is not writable. at androidx.test.runner.screenshot.BasicScreenCaptureProcessor.process(BasicScreenCaptureProcessor.java:72) at androidx.test.runner.screenshot.ScreenCapture.process(ScreenCapture.java:144) at androidx.test.runner.screenshot.ScreenCapture.process(ScreenCapture.java:126) at com.example.android.notepad.NotePadTest.testAddNote(NotePadTest.java:62) at java.lang.reflect.Method.invoke(Native Method) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at androidx.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:531) at androidx.test.rule.GrantPermissionRule$RequestPermissionStatement.evaluate(GrantPermissionRule.java:134) at org.junit.rules.RunRules.evaluate(RunRules.java:20) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at androidx.test.runner.AndroidJUnit4.run(AndroidJUnit4.java:104) at org.junit.runners.Suite.runChild(Suite.java:128) at org.junit.runners.Suite.runChild(Suite.java:27) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at org.junit.runner.JUnitCore.run(JUnitCore.java:115) at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56) at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:395) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2205)

tijins commented 8 months ago

This code is work on API34 emulator.

androidTest directory

        val processor = object : FirebaseScreenCaptureProcessor() {
            init {
                mDefaultScreenshotPath = context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)
            }
        }
        Screenshot.capture(context)
            .setName(name)
            .process(
                setOf(
                    processor
                )
            )

app/build.gradle fix "com.my.app" to your applicationId

    defaultConfig {
        testInstrumentationRunnerArguments additionalTestOutputDir: '/storage/emulated/0/Android/data/com.my.app/files/Download'
   }