2017-09-09 27 views
0

我使用Karumi的射門插件(https://github.com/karumi/shot)從我的測試採取截圖和比較,然後使用Facebook的庫:http://facebook.github.io/screenshot-tests-for-android/Facebook`s截圖測試符合API失敗大於23

的庫API運行時,有一個問題大於23,因爲它需要WRITE_EXTERNAL_STORAGE權限,並且由於api 23,在測試期間授予權限並不是一項簡單的任務。

但是在espresso 3.0中添加了GrantPermissionRule,並且可以使用此功能輕鬆設置以前的測試執行權限。

嘛,我加了規則:

@Rule @JvmField 
val grantPermissionRule: GrantPermissionRule = GrantPermissionRule.grant(android.Manifest.permission.WRITE_EXTERNAL_STORAGE) 

,並採取了截圖用下面的代碼:

Screenshot.snapActivity(activityTestRule.activity).record() 

我有一個運行一個自定義的TestRunner:

override fun onCreate(args: Bundle) { 
    super.onCreate(args) 
    ScreenshotRunner.onCreate(this, args) 
} 

override fun finish(resultCode: Int, results: Bundle) { 
    ScreenshotRunner.onDestroy() 
    super.finish(resultCode, results) 
} 

但當我執行測試時,我收到以下錯誤:

java.lang.RuntimeException: Failed to create the directory for screenshots. Is your sdcard directory read-only? 
    at com.facebook.testing.screenshot.internal.ScreenshotDirectories.getSdcardDir(ScreenshotDirectories.java:66) 

回答

1

該插件未能嘗試將截圖保存在API> = 23中,因爲該權限必須在測試APK中授予,而不是在測試中的APK。使用名爲授予權限測試規則的規則不提供此功能。這是不支持官方Facebook庫,我們目前不支持:(

我也在GitHub存儲庫中回答了您的問題https://github.com/Karumi/Shot/issues/19#issuecomment-328334528