I am getting error for the Language Setting in fastlane when i trying to capture screenshots using Screengrab

831 Views Asked by At

I am getting the error in the takeScreenShot() and it also give me the error of language configuration while executing the command fastlane Screengrab

Here is my test Execution Code

/**
 * 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() {
    }
}

Error in terminal :-

[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.access$100(ViewInteraction.java:63) [11:09:17]: ▸ at android.support.test.espresso.ViewInteraction$1.call(ViewInteraction.java:153) [11:09:17]: ▸ at android.support.test.espresso.ViewInteraction$1.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.access$100(ViewInteraction.java:63) [11:09:19]: ▸ at android.support.test.espresso.ViewInteraction$1.call(ViewInteraction.java:153) [11:09:19]: ▸ at android.support.test.espresso.ViewInteraction$1.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

1

There are 1 best solutions below

1
On BEST ANSWER

This will probably help:

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());

https://docs.fastlane.tools/getting-started/android/screenshots/#improved-screenshot-capture-with-ui-automator