Search code examples
c#androidxamarin.androidxamarin.uitest

Xamarin UITest | adb cmd to open mobile phone Internal storage via mobile screen (not through adb pull command and pull the data )


Our application is built on xamarin form and I am performing xamarin UITest to automate the android native app.

Scenario: During the validation I have to navigate to Phone's Internal Storage location where I have to open a folder in it(created before this step) -> open sysId.txt file -> validate the content of the file.

My Approach: I tried many ways to find a proper command which opens the internal storage via mobile screen but i couldn't find any solution other than using mobile screen coordinates(PFB)

Below commands are used to navigate from home screen to my txt file location (these steps would work only on MotoG8_Plus):

To open Files folder adb shell monkey -p com.google.android.apps.nbu.files -v 10

Swipe Down in Files Folder : adb shell input swipe 500 1000 300 300

Tap on Internal Storage : adb shell input tap 650 1800

Tap on iSpiro Folder : adb shell input tap 1000 1150

Tap on sysId.txt : adb shell input tap 400 400

Tap on HTML viewer : adb shell input tap 300 2000

Note: Above cmd's are working only in Motog8_Plus mobile device as the internal storage path and tap & click coordinates are specific to this device but I'm looking for a generic solution to Open Internal storage folder(via mobile screen) and click on folders by name(e.g click xyz folder using adb command by its name xyz)

Thank you for the help in advance!


Solution

  • As My test should run in other devices i thought to install(material_files.apk) a new file explorer (remove google files) then

    1. Open Internal storage:

      adb shell am start --user 0 -a android.intent.action.VIEW -d file://storage/sdcard/" -t resource/folder
      
    2. Open ABC Folder:

      adb shell am start --user 0 -a android.intent.action.VIEW -d file://storage/sdcard/ABC" -t resource/folder
      
    3. Open Text File(XYZ.txt):

      adb shell am start --user 0 -a android.intent.action.VIEW -d file://storage/sdcard/ABC/XYZ.txt -t text/plain