1

I am new to Python and trying to make an automation test for an application using Appium 1.3.1 and Python 3.6 on Android 7.1.1 simulator. At this point I am stuck at system permissions popup and don't know how to select "ALLOW" element with Python (not the same as selecting regular button inside the application). Application doesn't start until access to files is granted but I am not sure exactly where to set this in code and how to write it in Python. Does someone have some kind of sample code or some idea how to do this? This is what I have done so far:

import os
import unittest
from appium import webdriver
from time import sleep

class meTest(unittest.TestCase):

def setUp(self):
    desired_caps = {}
    desired_caps['platformName'] = 'Android'
    desired_caps['platformVersion'] = '7.1.1'
    desired_caps['deviceName'] = 'Android Emulator'
    # Returns abs path relative to this file and not cwd
    desired_caps['app'] = ‘example.apk'

    self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

 def test_OpenDocuments(self):
    sleep(10)
    documentSearchButton = self.driver.find_element_by_id(
        ‘example.example').click()


def tearDown(self):
    self.driver.quit()


if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(meTest)
unittest.TextTestRunner(verbosity=2).run(suite)

Thanks.

bluRNG
  • 41
  • 6

2 Answers2

3

To grant the permission (in my case for the "ALLOW" button in Android permission dialog) it is necessary to access the desired_caps in Appium webdriver. It automatically granted all permissions for this app.

desired_caps['autoGrantPermissions'] = 'true'
bluRNG
  • 41
  • 6
-1

As far as I know you can generally set permissions using os.chown(). In your case (Python 3.6) the following could work:

os.chmod("path/to/your/file", 0o666)

Of course you need to modify the access rights to meet your requirements, '0o666' is just an example for a return like:

-rw-rw-rw- 1 ag ag 0 Mar 25 05:55 your_file
joffi
  • 101
  • Do you mean to add permission to .apk file? I've tried to add that to this code but I still get the same popup, one just like [this](https://img.gadgethacks.com/img/73/01/63590011830876/0/android-basics-manage-app-permissions-marshmallow-higher.w1456.jpg). Is there a way to access it as an element and simply click on it? – bluRNG Jan 31 '18 at 12:45