繁体   English   中英

Android屏幕错误状态截图

[英]Android wrong screen state of screenshot

我在UI测试中有一些步骤:

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

在运行测试时,当assertButtonsAreDisplayedInScrollView方法启动时,我可以在屏幕上看到操作:将显示滚动到底部,直到最后一个按钮,确保在调用该saveScreenshot方法之后显示最低按钮。

但是,当我打开screenshot.png时,我看到它已经达到了初始屏幕状态,即带有上按钮(就像它没有滚动到底部一样)。

有人可以帮助解决这个问题吗? 我必须截图屏幕的最后状态。

屏幕截图方法的主体:

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

谢谢!

尝试增加拍摄屏幕快照的时间。

Handler handler = new Handler();
handler.postDelayed(new Runnable() {
      @Override
      public void run() {
        //Do something after 100ms
        saveScreenshot();
      }
}, 100);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM