当我尝试使用 Screengrab 捕获屏幕截图时,fastlane 中的语言设置出现错误
I am getting error for the Language Setting in fastlane when i trying to capture screenshots using Screengrab
我在 takeScreenShot()
中收到错误,它还给我在执行命令时的语言配置错误 fastlane Screengrab
这是我的测试执行代码
/**
* 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() {
}
}
终端错误:-
[11:09:17]: ▸ com.tcc.gstknowledge.ExampleInstrumentedTest:
[11:09:17]: ▸ Error in
testTakeScreenshot(com.tcc.gstknowledge.ExampleInstrumentedTest):
[11:09:17]: ▸ java.lang.IllegalStateException: Couldn't get the
activity from the view context [11:09:17]: ▸ at
tools.fastlane.screengrab.DecorViewScreenshotStrategy$ScreenshotViewAction.perform(DecorViewScreenshotStrategy.java:69)
[11:09:17]: ▸ at
android.support.test.espresso.ViewInteraction$SingleExecutionViewAction.perform(ViewInteraction.java:356)
[11:09:17]: ▸ at
android.support.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:248)
[11:09:17]: ▸ at
android.support.test.espresso.ViewInteraction.access0(ViewInteraction.java:63)
[11:09:17]: ▸ at
android.support.test.espresso.ViewInteraction.call(ViewInteraction.java:153)
[11:09:17]: ▸ at
android.support.test.espresso.ViewInteraction.call(ViewInteraction.java:150)
[11:09:17]: ▸ at
java.util.concurrent.FutureTask.run(FutureTask.java:237) [11:09:17]: ▸
at android.os.Handler.handleCallback(Handler.java:751) [11:09:17]: ▸
at android.os.Handler.dispatchMessage(Handler.java:95) [11:09:17]: ▸
at android.os.Looper.loop(Looper.java:154) [11:09:17]: ▸ at
android.app.ActivityThread.main(ActivityThread.java:6776) [11:09:17]:
▸ at java.lang.reflect.Method.invoke(Native Method) [11:09:17]: ▸ at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1518)
[11:09:17]: ▸ at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
[11:09:19]: ▸ . [11:09:19]: ▸ Time: 5.788 [11:09:19]: ▸ There was 1
failure: [11:09:19]: ▸ 1)
testTakeScreenshot(com.tcc.gstknowledge.ExampleInstrumentedTest)
[11:09:19]: ▸ java.lang.IllegalStateException: Couldn't get the
activity from the view context [11:09:19]: ▸ at
tools.fastlane.screengrab.DecorViewScreenshotStrategy$ScreenshotViewAction.perform(DecorViewScreenshotStrategy.java:69)
[11:09:19]: ▸ at
android.support.test.espresso.ViewInteraction$SingleExecutionViewAction.perform(ViewInteraction.java:356)
[11:09:19]: ▸ at
android.support.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:248)
[11:09:19]: ▸ at
android.support.test.espresso.ViewInteraction.access0(ViewInteraction.java:63)
[11:09:19]: ▸ at
android.support.test.espresso.ViewInteraction.call(ViewInteraction.java:153)
[11:09:19]: ▸ at
android.support.test.espresso.ViewInteraction.call(ViewInteraction.java:150)
[11:09:19]: ▸ at
java.util.concurrent.FutureTask.run(FutureTask.java:237) [11:09:19]: ▸
at android.os.Handler.handleCallback(Handler.java:751) [11:09:19]: ▸
at android.os.Handler.dispatchMessage(Handler.java:95) [11:09:19]: ▸
at android.os.Looper.loop(Looper.java:154) [11:09:19]: ▸ at
android.app.ActivityThread.main(ActivityThread.java:6776) [11:09:19]:
▸ at java.lang.reflect.Method.invoke(Native Method) [11:09:19]: ▸ at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1518)
[11:09:19]: ▸ at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
[11:09:19]: ▸ FAILURES!!! [11:09:19]: ▸ Tests run: 2, Failures: 1
[!] Tests failed for locale en-US on device 3300dea196566381
这可能会有所帮助:
As of screengrab 0.5.0, you can specify different strategies to control the way screengrab captures screenshots. The newer strategy delegates to UI Automator which fixes a number of problems compared to the original strategy:
- Shadows/elevation are correctly captured for Material UI
- Multi-window situations are correctly captured (dialogs, etc.)
- Works on Android N
However, UI Automator requires a device with API level >= 18, so it is not yet the default strategy. To enable it for all screenshots by default, make the following call before your tests run:
Screengrab.setDefaultScreenshotStrategy(new UiAutomatorScreenshotStrategy());
我在 takeScreenShot()
中收到错误,它还给我在执行命令时的语言配置错误 fastlane Screengrab
这是我的测试执行代码
/**
* 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() {
}
}
终端错误:-
[11:09:17]: ▸ com.tcc.gstknowledge.ExampleInstrumentedTest: [11:09:17]: ▸ Error in testTakeScreenshot(com.tcc.gstknowledge.ExampleInstrumentedTest): [11:09:17]: ▸ java.lang.IllegalStateException: Couldn't get the activity from the view context [11:09:17]: ▸ at tools.fastlane.screengrab.DecorViewScreenshotStrategy$ScreenshotViewAction.perform(DecorViewScreenshotStrategy.java:69) [11:09:17]: ▸ at android.support.test.espresso.ViewInteraction$SingleExecutionViewAction.perform(ViewInteraction.java:356) [11:09:17]: ▸ at android.support.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:248) [11:09:17]: ▸ at android.support.test.espresso.ViewInteraction.access0(ViewInteraction.java:63) [11:09:17]: ▸ at android.support.test.espresso.ViewInteraction.call(ViewInteraction.java:153) [11:09:17]: ▸ at android.support.test.espresso.ViewInteraction.call(ViewInteraction.java:150) [11:09:17]: ▸ at java.util.concurrent.FutureTask.run(FutureTask.java:237) [11:09:17]: ▸ at android.os.Handler.handleCallback(Handler.java:751) [11:09:17]: ▸ at android.os.Handler.dispatchMessage(Handler.java:95) [11:09:17]: ▸ at android.os.Looper.loop(Looper.java:154) [11:09:17]: ▸ at android.app.ActivityThread.main(ActivityThread.java:6776) [11:09:17]: ▸ at java.lang.reflect.Method.invoke(Native Method) [11:09:17]: ▸ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1518) [11:09:17]: ▸ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408) [11:09:19]: ▸ . [11:09:19]: ▸ Time: 5.788 [11:09:19]: ▸ There was 1 failure: [11:09:19]: ▸ 1) testTakeScreenshot(com.tcc.gstknowledge.ExampleInstrumentedTest) [11:09:19]: ▸ java.lang.IllegalStateException: Couldn't get the activity from the view context [11:09:19]: ▸ at tools.fastlane.screengrab.DecorViewScreenshotStrategy$ScreenshotViewAction.perform(DecorViewScreenshotStrategy.java:69) [11:09:19]: ▸ at android.support.test.espresso.ViewInteraction$SingleExecutionViewAction.perform(ViewInteraction.java:356) [11:09:19]: ▸ at android.support.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:248) [11:09:19]: ▸ at android.support.test.espresso.ViewInteraction.access0(ViewInteraction.java:63) [11:09:19]: ▸ at android.support.test.espresso.ViewInteraction.call(ViewInteraction.java:153) [11:09:19]: ▸ at android.support.test.espresso.ViewInteraction.call(ViewInteraction.java:150) [11:09:19]: ▸ at java.util.concurrent.FutureTask.run(FutureTask.java:237) [11:09:19]: ▸ at android.os.Handler.handleCallback(Handler.java:751) [11:09:19]: ▸ at android.os.Handler.dispatchMessage(Handler.java:95) [11:09:19]: ▸ at android.os.Looper.loop(Looper.java:154) [11:09:19]: ▸ at android.app.ActivityThread.main(ActivityThread.java:6776) [11:09:19]: ▸ at java.lang.reflect.Method.invoke(Native Method) [11:09:19]: ▸ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1518) [11:09:19]: ▸ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408) [11:09:19]: ▸ FAILURES!!! [11:09:19]: ▸ Tests run: 2, Failures: 1
[!] Tests failed for locale en-US on device 3300dea196566381
这可能会有所帮助:
As of screengrab 0.5.0, you can specify different strategies to control the way screengrab captures screenshots. The newer strategy delegates to UI Automator which fixes a number of problems compared to the original strategy:
- Shadows/elevation are correctly captured for Material UI
- Multi-window situations are correctly captured (dialogs, etc.)
- Works on Android N
However, UI Automator requires a device with API level >= 18, so it is not yet the default strategy. To enable it for all screenshots by default, make the following call before your tests run:
Screengrab.setDefaultScreenshotStrategy(new UiAutomatorScreenshotStrategy());