Android 当我试图使用截图捕获屏幕截图时,fastlane中的语言设置出现错误

Android 当我试图使用截图捕获屏幕截图时,fastlane中的语言设置出现错误,android,fastlane,fastlane-snapshot,Android,Fastlane,Fastlane Snapshot,我在takeScreenShot()中得到了错误,并且在执行命令fastlane screenshot 这是我的测试执行代码 /** * Instrumentation test, which will execute on an Android device. * */ @RunWith(AndroidJUnit4.class) public class ExampleInstrumentedTest { @ClassRule public static final L

我在
takeScreenShot()
中得到了错误,并且在执行命令
fastlane screenshot

这是我的测试执行代码

/**
 * Instrumentation test, which will execute on an Android device.
 *
 */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {

    @ClassRule
    public static final LocaleTestRule localeTestRule = new LocaleTestRule();

    @Rule
    public ActivityTestRule<MainActivity> activityRule = new ActivityTestRule<>(MainActivity.class);


    @Test
    public void testTakeScreenshot() {
        Screengrab.screenshot("Dashboard");
    }

    @Test
    public void useAppContext() {
    }
}
/**
*仪器测试,将在Android设备上执行。
*
*/
@RunWith(AndroidJUnit4.class)
公共类示例InstrumentedTest{
@阶级规则
public static final LocaleTestRule LocaleTestRule=new LocaleTestRule();
@统治
public ActivityTestRule activityRule=新的ActivityTestRule(MainActivity.class);
@试验
公共无效测试截图(){
截图。截图(“仪表板”);
}
@试验
public void useAppContext(){
}
}
终端错误:-

[11:09:17]:▸ com.tcc.gstknowledge.example仪表测试: [11:09:17]: ▸ 错误 测试截图(com.tcc.gstknowledge.ExampleInstrumentedTest): [11:09:17]: ▸ java.lang.IllegalStateException:无法获取 来自视图上下文的活动[11:09:17]:▸ 在 tools.fastlane.screengrab.DecorViewScreenshotStrategy$ScreenshotViewAction.perform(DecorViewScreenshotStrategy.java:69) [11:09:17]: ▸ 在 android.support.test.espresso.ViewInteraction$SingleExecutionViewAction.perform(ViewInteraction.java:356) [11:09:17]: ▸ 在 android.support.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:248) [11:09:17]: ▸ 在 android.support.test.espresso.ViewInteraction.access$100(ViewInteraction.java:63) [11:09:17]: ▸ 在 android.support.test.espresso.ViewInteraction$1.call(ViewInteraction.java:153) [11:09:17]: ▸ 在 android.support.test.espresso.ViewInteraction$1.call(ViewInteraction.java:150) [11:09:17]: ▸ 在 java.util.concurrent.FutureTask.run(FutureTask.java:237)[11:09:17]:▸ 在android.os.Handler.handleCallback(Handler.java:751)[11:09:17]:▸ 在android.os.Handler.dispatchMessage(Handler.java:95)[11:09:17]:▸ 在android.os.Looper.loop(Looper.java:154)[11:09:17]:▸ 在 main(ActivityThread.java:6776)[11:09:17]: ▸ 在java.lang.reflect.Method.invoke(本机方法)[11:09:17]:▸ 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1518) [11:09:17]: ▸ 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408) [11:09:19]: ▸ . [11:09:19]: ▸ 时间:5.788[11:09:19]:▸ 有1个 失败:[11:09:19]:▸ 1) 测试截图(com.tcc.gstknowledge.ExampleInstrumentedTest) [11:09:19]: ▸ java.lang.IllegalStateException:无法获取 视图上下文中的活动[11:09:19]:▸ 在 tools.fastlane.screengrab.DecorViewScreenshotStrategy$ScreenshotViewAction.perform(DecorViewScreenshotStrategy.java:69) [11:09:19]: ▸ 在 android.support.test.espresso.ViewInteraction$SingleExecutionViewAction.perform(ViewInteraction.java:356) [11:09:19]: ▸ 在 android.support.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:248) [11:09:19]: ▸ 在 android.support.test.espresso.ViewInteraction.access$100(ViewInteraction.java:63) [11:09:19]: ▸ 在 android.support.test.espresso.ViewInteraction$1.call(ViewInteraction.java:153) [11:09:19]: ▸ 在 android.support.test.espresso.ViewInteraction$1.call(ViewInteraction.java:150) [11:09:19]: ▸ 在 java.util.concurrent.FutureTask.run(FutureTask.java:237)[11:09:19]:▸ 在android.os.Handler.handleCallback(Handler.java:751)[11:09:19]:▸ 在android.os.Handler.dispatchMessage(Handler.java:95)[11:09:19]:▸ 在android.os.Looper.loop(Looper.java:154)[11:09:19]:▸ 在 android.app.ActivityThread.main(ActivityThread.java:6776)[11:09:19]: ▸ 在java.lang.reflect.Method.invoke(本机方法)[11:09:19]:▸ 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1518) [11:09:19]: ▸ 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408) [11:09:19]: ▸ 失败!!![11:09:19]: ▸ 测试运行:2,失败:1

[!]设备3300dea196566381上的locale en US测试失败


这可能有助于:

从screengrab 0.5.0开始,您可以指定不同的策略来控制screengrab捕获截图的方式。较新的策略委托给UI Automator,与原始策略相比,它修复了许多问题:

  • 为材质UI正确捕捉阴影/立面
  • 正确捕获多窗口情况(对话框等)
  • 在安卓N上工作
但是,UI Automator需要API级别>=18的设备,因此它还不是默认策略。要在默认情况下为所有屏幕截图启用它,请在测试运行之前进行以下调用:

 Screengrab.setDefaultScreenshotStrategy(new UiAutomatorScreenshotStrategy());

是否尝试设置默认策略?关键似乎是文档中报价末尾的代码行。