Below is the code
@RunWith(AndroidJUnit4.class)
public class ScreenshotJavaTest {
// a handy JUnit rule that stores the method name
@Rule
public TestName nameRule = new TestName();
@Rule
public ActivityScenarioRule<MainActivity> activityScenarioRule =
new ActivityScenarioRule<>(MainActivity.class);
/**
* Captures and saves an image of the entire {@link MainActivity} contents.
*/
@Test
public void saveActivityBitmap() throws IOException {
writeToTestStorage(captureToBitmap(onView(isRoot())), getClass().getSimpleName() + "_" + nameRule.getMethodName());
}
/**
* Captures and saves an image of the 'Hello world' view.
*/
@Test
public void saveViewBitmap() throws IOException {
writeToTestStorage(captureToBitmap(onView(withText("Hello World!"))), getClass().getSimpleName() + "_" + nameRule.getMethodName());
}
/**
* Captures and saves an image of the entire device screen to storage.
*/
@Test
public void saveDeviceScreenBitmap() throws IOException {
writeToTestStorage(takeScreenshot(), getClass().getSimpleName() + "_" + nameRule.getMethodName());
}
}
All test cases are running but I am not able to find any screenshots anywhere in the device file manager. So How I will find those screenshots or there are some other ways we can achieve to get these screenshots in automation testing
Cannot speak for real devices, but when using the Android Studio Simulator you can find the screenshots using the Device File Explorer at the following path:
/storage/emulated/0/googletest/test_outputfiles
Make sure to add the following line to your gradle file:
testInstrumentationRunnerArguments useTestStorageService: 'true'
I've been searching for hours and this doesn't seem to be documented anywhere.