uiautomator takescreenshot 无缘无故不起作用

uiautomator takescreenshot not work for no reason

我在自动化测试的时候试图在内部存储中截图,但是运行测试的时候,没有报错,但是我查看文件的时候,没有截图成功了,我现在很迷茫,请大家帮帮我~

这是我的部分代码:

我已经在 AndroidManifest.xml 中获得了我的许可

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS "/>

截图

UiDevice mDevice =UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
mDevice.pressHome(); 
mDevice.takeScreenshot(new File("/sdcard/Pictures/test.png"));
sleep(3000);

我确定方向没有错,因为我以前试过同样的代码,它工作正常,但几天后我又累了,它失败了,没有显示任何错误。

你能试试吗

mDevice.takeScreenshot(新文件("/sdcard/Download/test.png")); 睡眠(3000);