Home:ALL Converter>uiautomator takescreenshot not work for no reason

uiautomator takescreenshot not work for no reason

Ask Time:2019-03-05T11:49:39         Author:abcde581125

Json Formatter

I tried to take a screenshot in the internal storage during automation testing,but when run the test,it didn't show any error,but when I check the file,the screenshot didn't take successfully,I am so confused right now,please help me~

Here is part of my code:

I have my permission in my AndroidManifest.xml already

<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 "/>

screenshot

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

I am sure the direction is not wrong cause I tried the same code before,it worked normally,but after few days I tired it again and it failed without showing any error.

Author:abcde581125,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/54995131/uiautomator-takescreenshot-not-work-for-no-reason
yy