def test_make_dir(self, device: Device): storage = DeviceStorage(device) new_remote_dir = "/".join( [storage.external_storage_location, "a", "b", "c", "d"]) # assure dir does not already exist: with suppress(Exception): storage.remove(new_remote_dir, recursive=True) try: output = device.execute_remote_cmd("shell", "ls", "-d", new_remote_dir, capture_stdout=True) # expect "no such directory" error leading to exception, but just in case: assert new_remote_dir not in output except Device.CommandExecutionFailureException as e: assert "no such" in str(e).lower() storage.make_dir(new_remote_dir) output = device.execute_remote_cmd("shell", "ls", "-d", new_remote_dir, capture_stdout=True) assert new_remote_dir in output
def test_pull(self, device: Device, mp_tmp_dir): storage = DeviceStorage(device) local_path = os.path.join(mp_tmp_dir, "somefile") remote_path = "/".join([storage.external_storage_location, "touchedfile"]) device.execute_remote_cmd("shell", "touch", remote_path) storage.pull(remote_path=remote_path, local_path=local_path) assert os.path.exists(local_path)
def test_push_remove(self, device: Device): storage = DeviceStorage(device) remote_location = "/".join( [storage.external_storage_location, "some_file"]) with suppress(Exception): storage.remove(remote_location) output = device.execute_remote_cmd("shell", "ls", device.external_storage_location, capture_stdout=True) if os.path.basename(remote_location) in output: raise Exception("Error: did not expect file %s on remote device" % remote_location) storage.push(local_path=(os.path.abspath(__file__)), remote_path=remote_location) output = device.execute_remote_cmd("shell", "ls", device.external_storage_location, capture_stdout=True) assert os.path.basename(remote_location) in output storage.remove(remote_location) output = device.execute_remote_cmd("shell", "ls", device.external_storage_location, capture_stdout=True) assert not os.path.basename(remote_location) in output
def test_grant_permissions(self, device: Device, support_test_app: str): app = Application.from_apk(support_test_app, device) assert app.package_name.endswith(".test") try: permission = "android.permission.WRITE_EXTERNAL_STORAGE" app.grant_permissions([permission]) output = device.execute_remote_cmd("shell", "dumpsys", "package", app.package_name, capture_stdout=True, timeout=10) perms = [] look_for_perms = False for line in output.splitlines(): if "granted=true" in line: perms.append(line.strip().split(':', 1)[0]) if "grantedPermissions" in line: # older reporting style . Ugh. Yeah for inconsistencies look_for_perms = True if look_for_perms: if "permission" in line: perms.append(line.strip()) assert permission in perms finally: app.uninstall()
def test_install_uninstall(self, device: Device, support_app: str): app = Application.from_apk(support_app, device) try: assert app.package_name == "com.linkedin.mdctest" output = device.execute_remote_cmd("shell", "dumpsys", "package", app.package_name, capture_stdout=True, timeout=10) for line in output.splitlines(): if "versionName" in line: assert app.version == line.strip().split('=', 1)[1] finally: app.uninstall() assert app.package_name not in device.list_installed_packages()
def test_install_uninstall(self, device: Device, support_app: str): uninstall_apk(support_app, device) app = Application.from_apk(support_app, device) try: assert app.package_name == "com.linkedin.mtotestapp" completed = device.execute_remote_cmd("shell", "dumpsys", "package", app.package_name, timeout=10, stdout=subprocess.PIPE) for line in completed.stdout.splitlines(): if "versionName" in line: assert app.version == line.strip().split('=', 1)[1] finally: app.uninstall() assert app.package_name not in device.list_installed_packages()
def test_grant_permissions(self, device: Device, install_app, support_test_app): test_app = install_app(TestApplication, support_test_app) assert test_app.package_name.endswith(".test") permission = "android.permission.WRITE_EXTERNAL_STORAGE" test_app.grant_permissions([permission]) completed = device.execute_remote_cmd("shell", "dumpsys", "package", test_app.package_name, timeout=10, stdout=subprocess.PIPE) perms = [] look_for_perms = False for line in completed.stdout.splitlines(): if "granted=true" in line: perms.append(line.strip().split(':', 1)[0]) if "grantedPermissions" in line: # older reporting style . Ugh. Yeah for inconsistencies look_for_perms = True if look_for_perms: if "permission" in line: perms.append(line.strip()) assert permission in perms