设置Facebook屏幕截图测试Android时出现问题

时间:2019-01-10 09:26:29

标签: android kotlin

我正在尝试在我们的Android应用上设置facebook的screenshot-tests-for-android(v0.8.0),但出现以下错误:

java.lang.RuntimeException: Failed to create the directory /sdcard/screenshots/com.schibsted.peil.android.dev.test/screenshots-default for screenshots. Is your sdcard directory read-only?
at com.facebook.testing.screenshot.internal.ScreenshotDirectories.getSdcardDir(ScreenshotDirectories.java:121)
at com.facebook.testing.screenshot.internal.ScreenshotDirectories.get(ScreenshotDirectories.java:53)
at com.facebook.testing.screenshot.internal.AlbumImpl.<init>(AlbumImpl.java:44)
at com.facebook.testing.screenshot.internal.AlbumImpl.create(AlbumImpl.java:49)
at com.facebook.testing.screenshot.internal.ScreenshotImpl.create(ScreenshotImpl.java:66)
at com.facebook.testing.screenshot.internal.ScreenshotImpl.getInstance(ScreenshotImpl.java:84)
at com.facebook.testing.screenshot.Screenshot.snap(Screenshot.java:38)
at com.sample.myapp.ThirteenCardScreenshotTest.testScreenshot(ThirteenCardScreenshotTest.kt:24)

在我的应用AndroidManifest.xml上,我明确设置了库所需的WRITE_EXTERNAL_STORAGE权限,关于运行检测测试的权限似乎发生了变化,但似乎在检测测试中不可用?还是其他?

有人有使用该库的经验吗?有什么建议吗?

我的测试如下:

package com.sample.myapp

import android.widget.LinearLayout
import androidx.test.InstrumentationRegistry
import com.facebook.testing.screenshot.Screenshot
import com.facebook.testing.screenshot.ViewHelpers
import com.sample.myapp.feed.FooterStoryViewHolder
import org.junit.Test

class ThirteenCardScreenshotTest {
    @Test
    fun testScreenshot() {
        val context = InstrumentationRegistry.getInstrumentation().targetContext

        val view = LinearLayout(context)
        val viewHolder = FooterStoryViewHolder(view)
        view.addView(viewHolder.itemView)

        ViewHelpers.setupView(view)
            .setExactWidthDp(360)
            .setExactHeightDp(740)
            .layout()

        Screenshot.snap(view)
            .record()
    }
}

https://github.com/facebook/screenshot-tests-for-android/issues/162中提出的解决方法对我不起作用

1 个答案:

答案 0 :(得分:0)

如果您具有该应用程序的调试环境,请将其添加到其清单中:

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

否则,您将不得不将其放入默认应用清单中