jeudi 21 juin 2018

Android wrong screen state of screenshot

I have some steps in UI-test:

rotateDevice(Orientation.LANDSCAPE);
closeSoftKeyboard();
assertActionBarTitle(getString(R.string.demo_activity_title));
assertButtonsAreDisplayedInScrollView(mExpectedDisplayedButtonIds);
saveScreenshot();

When I run tests, I can see actions on screen, when assertButtonsAreDisplayedInScrollView method starts: display is scrolled to the bottom until the last button, assuring that lowest button is displayed, after that saveScreenshot method is called.

But when I open screenshot.png, I see that it has shotted the initial screen state, i.e. with upper buttons (like it hasn't scrolled to the bottom).

Can someone help to solve this problem? I have to screenshot the last state of screen.

Screenshot method's body:

Bitmap bitmap = InstrumentationRegistry.getInstrumentation().getUiAutomation().takeScreenshot();

File screenshotFile = getScreenshotFile();

try (FileOutputStream outputStream = new FileOutputStream(screenshotFile)) {
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
    Log.i(mTag, "Saved screenshot: " + screenshotFile.getAbsolutePath());
} catch (IOException e) {
    Log.e(mTag, "Could not save screenshot", e);
}

Thanks!

Aucun commentaire:

Enregistrer un commentaire