class TestDeviceInfo(object): _devices = ADB.get_connected_devices() assert len(_devices) > 0, "Check connected Device" device = _devices[0] def test_android_version(self): """ Unit test for Android version Return Example - Android Version 6.0.1 """ android_version = DeviceInfo.get_prop(self.device, Properties.ANDROID_VERSION) print(android_version) assert isinstance(android_version, dict) version = android_version.get("Android Version") assert len(version) > 0 def test_getprop(self): """ Unit test for all getprop should return in dict """ getprop = DeviceInfo.all_getprop(self.device) assert isinstance(getprop, dict) assert len(getprop) > 0
def test_get_connected_devices(self): devices = ADB.get_connected_devices() print("NOTE: Execute test with connected devices") print("E: Found Devices {}".format(devices)) assert True assert len(devices) > 0
def test_get_layout(self): # TODO: Make a generator Files.clear_dir(Path.TEST_FILES.value) dev_id = ADB.get_connected_devices()[0] print("I: Device - {}".format(dev_id)) path_to_file = Layout.save_layout(dev_id, Path.TEST_FILES.value) print("I: Path to file - {}".format(path_to_file)) assert os.path.isfile(path_to_file)
class TestPackageInfo(object): dev_id = ADB.get_connected_devices()[0] def test_is_package_exist(self): notExist = PackageInfo.is_package_exist(self.dev_id, "com.android.not_a_package") assert notExist is False exist = PackageInfo.is_package_exist(self.dev_id, "com.android.vending") assert exist is True
class TestCookbook(object): dev_id = ADB.get_connected_devices()[0] def test_packages_info(self): """ Unit test to check return for Cookbook.get_packages_info() """ packages = Info.get_packages_info(self.dev_id, AndroidKPackage.YOUTUBE, AndroidKPackage.PLAY_STORE) for package in packages: assert len(package.appName) > 0 assert len(package.version) > 0 assert len(package.package) > 0
@staticmethod def is_locked(dev_id) -> bool: """ Return is device locked :dev_id: Device ID """ command = "adb -s {dev} shell dumpsys window | grep 'mShowingLockscreen'".format(dev=dev_id) out = ADB.get_terminal_output(command)[0].split() for line in out: raw = line.strip().split("=") if "mDreamingLockscreen" in raw[0]: if raw[1] == "true": return True if "mShowingLockscreen" in raw[0]: if raw[1] == "true": return True return False if __name__ == "__main__": # # system_process = "com.android.systemui" dev_id = ADB.get_connected_devices()[0] x = DeviceInfo.get_current_activity(dev_id) print(x) # size = DeviceInfo.get_display_size(dev_id) # print(size) # print(DeviceInfo.get_package_activity(dev_id, "com.android.vending")) # DeviceInfo.get_prop(dev_id, Properties.BRAND, Properties.MODEL)
class TestDeviceManipulations(object): test_files_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), "test_files") _devices = ADB.get_connected_devices() assert len(_devices) > 0, "Check connected Device" device = _devices[0] def test_open_close_notification_center(self): """ Unit test to Perform open and close Notification Center TODO: Fix the test """ if DeviceInfo.is_locked: DeviceManipulations.unlock_device(self.device, UnlockType.SWIPE) DeviceManipulations.open_notification_center(self.device) current_activity = DeviceInfo.get_current_activity(self.device) assert current_activity.get("activity") == "StatusBar" DeviceManipulations.execute_keyevent(self.device, AndroidKeyevent.BACK) current_activity = DeviceInfo.get_current_activity(self.device) assert current_activity.get( "activity" ) == "com.sec.android.app.launcher.activities.LauncherActivity" def test_lock_device(self): """ Unit test for device lock """ DeviceManipulations.lock_device(self.device) time.sleep(1) lock_status = DeviceInfo.is_locked(self.device) print("Device lock status - {}".format(lock_status)) assert lock_status def test_save_screenshot(self): """ Unit test for save_screenshot """ if DeviceInfo.is_locked: DeviceManipulations.unlock_device(self.device, UnlockType.SWIPE) test_device_path = "/sdcard/sc2.png" test_file_name = "sc2.png" Files.clear_dir(self.test_files_dir) DeviceManipulations.save_screenshot(self.device, "/sdcard/sc2.png", self.test_files_dir) assert os.path.isfile(os.path.join(self.test_files_dir, test_file_name)) def test_unlock_device(self): """ Unit test for unlock the device """ if not DeviceInfo.is_locked: DeviceManipulations.lock_device(self.device) DeviceManipulations.unlock_device(self.device, UnlockType.SWIPE) assert not DeviceInfo.is_locked(self.device)