Check file exist in real device storage

Good morning!

I have a question about how to check file exists in my android device. I imported OperatingSystem library and use keyword:

File Should Exist file:////storage/emulated/0/Download/20230411.m4a

Test case failed with this error:

File ‘C:\Users\Dule\PycharmProjects\my-project-name\file:\storage\emulated\0\Download\20230411.m4a’ does not exist.

How can I check 20230411.m4a file exist or not in my android device? Please help me :smiling_face_with_tear:

Thank you and have a good day :+1:

If you are running an emulator as your post suggests and not your Title of the post “real device storage” but the paths below show “/emulated/” you could try using this:

adb shell ls -R | findstr 20230411.m4a

This can also be run against RL devices if you have Root access, To access /data partition you need root permission which is adb root but for me at least I get return Permission denied, and I’d rather not root the device

So you could use this with the process library to oppose to OperatingSystem library as the Run keyword holds a comment “supports better process configuration and is generally recommended as a replacement for this keyword”

in terms of the failed error, it looks to be looking for the file within your project path and not the device path itself, im unsure if it’s possible to switch to a RL device or emulator (very limited on time at the moment):

As an alternative you could use white library if all else fails to navigate to the device connected and check the file exists, which I’ve used in the past to move files across to an RL device due to root permissions, but that offers a keyword “Wait Until Item Exists” to check for a file, which can be used as the below but can be extended on:

WhiteLibrary.Wait Until Item Exists text=${file.name} 5

1 Like

Many thanks, Daryl. I will try your solution when I have a chance😊

Good night!

No problem gets a little painful with RL devices depending on what action you’re trying to achieve and though I’ve managed to work around most I’ve been faced with, it can be a tad tedious.
All the best :slight_smile:

1 Like