Search code examples
androidpythontestingandroid-virtual-devicemonkeyrunner

Python, MonkeyRunner. How to find a package name inside all list packages?


everybody. I´m using python and monkeyrunner for test apps on AVDs, I´m writing an script that could test if an app is installed or not.

I have a package name like:

package_name = "package:me.abc.app"

And I have a list of packages installed on an AVD with this command:

C:\test>adb shell pm list packages
package:com.example.android.notepad
package:com.android.smoketest
package:com.example.android.softkeyb
package:me.abc.app
package:com.android.smoketest.tests

I want to write a script where I could save that list in an array/list and do something like this:

If package_name is in list_of_packages
   print "App is installed"
else
   print "App is not installed"

I´m having problemn with how could I save that list in an array or list, in Python.


Solution

  • Finally I created this function to save the list packages and you can search in that.

    def search_package_in_avd(device):
        command = device.shell("pm list packages -3")
        splitedline=re.split(':|\r|\n',command)
        if not splitedline:
            return ""
        else:
            return splitedline