class Settings(UIATestBase): """ @summary: Test cases for settings """ def setUp(self): super(Settings, self).setUp() self._test_name = __name__ self.api = ApiImpl() self.api.unlock_screen() print "[Setup]: %s" % self._test_name def tearDown(self): super(Settings, self).tearDown() print "[Teardown]: %s" % self._test_name def testDeviceAdministrator_Change(self): self.api.d.press.home() self.api.click_with_timeout("text", "Allow") self.api.click_with_timeout("text", "GOT IT") self.api.launch_app_by_intents("android.settings.SECURITY_SETTINGS", False) if not self.api.check_ui_exists("text", "Security", 5): self.api.settings_sub_launch("Security") if not self.api.check_ui_exists("text", "Device administrators"): self.api.d(scrollable=True).scroll.vert.to( text="Device administrators") self.api.click_with_timeout("text", "Device administrators") assert self.api.check_ui_exists("text", "Sample MDM", 5), "[ERROR]: fail to check Sample MDM" assert self.api.check_ui_exists("text", "Android Device Manager", 5), \ "[ERROR]: fail to check android device manager" assert not self.api.d(text="Sample MDM").right(resourceId="com.android.settings:id/checkbox").clickable, \ "[ERROR]: sample mdm still able to click" assert not self.api.check_ui_exists( "text", "Work"), "[ERROR]: able to check Work profile"
class Settings(UIATestBase): """ @summary: Test cases for settings """ def setUp(self): super(Settings, self).setUp() self._test_name = __name__ self.api = ApiImpl() self.api.unlock_screen() self.api.clean_tasks() print "[Setup]: %s" % self._test_name def tearDown(self): super(Settings, self).tearDown() print "[Teardown]: %s" % self._test_name def testWorkProfile_Change(self): self.api.launch_app_by_intents("android.settings.SECURITY_SETTINGS", False) if not self.api.check_ui_exists("text", "Security", 5): self.api.settings_sub_launch("Security") if not self.api.check_ui_exists("text", "Device administrators"): self.api.d(scrollable=True).scroll.vert.to( text="Device administrators") self.api.click_with_timeout("text", "Device administrators") assert self.api.check_ui_exists( "text", "Work"), "[ERROR]: fail to detect Work profile" assert self.api.d(text="Work").down(text="Sample MDM").right(resourceId="com.android.settings:id/checkbox").checked, \ "[ERROR]: Sample MDM for work profile doesn't checked in security" self.api.d(text="Work").down(text="Sample MDM").right( resourceId="com.android.settings:id/checkbox").click() assert self.api.check_ui_exists("textContains", "To stop Sample MDM from accessing your work"), \ "[ERROR]: warning message for remove work profile doesn't pop" self.api.click_with_timeout("text", "OK")
class ScreenLockChange(UIATestBase): """ @summary: Test cases for apps control with GMS app in work profile """ def setUp(self): super(ScreenLockChange, self).setUp() self._test_name = __name__ self.api = ApiImpl() self.api.unlock_screen() self.api.clean_tasks() print "[Setup]: %s" % self._test_name def tearDown(self): super(ScreenLockChange, self).tearDown() print "[Teardown]: %s" % self._test_name def testUpdateSwipeLock(self): self.api.set_lock_swipe() self.api.d.press.home() self.api.d.sleep() time.sleep(2) for _ in range(5): self.api.d.wakeup() if self.api.check_ui_exists("resourceId", self.api.ui.lock_clock_view): self.api.d( resourceId=self.api.ui.lock_screen_scroll_view).swipe.up() if self.api.check_ui_exists("description", "Apps"): break assert self.api.check_ui_exists( "description", "Apps"), "[ERROR]: fail to detect apps launcher " assert not self.api.check_ui_exists("resourceId", self.api.ui.lock_pin_pad), \ "[ERROR]: lock pin pad was detected" def testUpdatePINLock(self): self.api.set_lock_pin() self.api.d.press.home() self.api.d.sleep() time.sleep(2) for _ in range(5): self.api.d.wakeup() if self.api.check_ui_exists("resourceId", self.api.ui.lock_clock_view): self.api.d( resourceId=self.api.ui.lock_screen_scroll_view).swipe.up() if self.api.check_ui_exists("resourceId", self.api.ui.lock_pin_pad): break assert not self.api.check_ui_exists( "description", "Apps"), "[ERROR]: apps launcher is found" assert self.api.check_ui_exists("resourceId", self.api.ui.lock_pin_pad), \ "[ERROR]: fail to change screen lock to pin code"
class SetupManagedProfile(UIATestBase): """ @summary: Test cases for setup managed profile """ def setUp(self): super(SetupManagedProfile, self).setUp() self.api = ApiImpl() self.function = Function() self.api.unlock_screen() self.api.clean_tasks() self._test_name = __name__ print "[Setup]: %s" % self._test_name def tearDown(self): super(SetupManagedProfile, self).tearDown() print "[Teardown]: %s" % self._test_name def testSetup_Managed_Profile(self): """ set up manged profile :return: None """ self.api.settings_sub_launch("Accounts") if self.api.check_ui_exists("text", "Work", 5): self.api.click_with_timeout("text", "Remove work profile") self.api.click_with_timeout("text", "Delete", 10) time.sleep(5) self.api.remove_other_users_by_id() self.api.setup_managed_profile() for _ in range(5): self.api.d.press.home() self.api.api_demo_po_launch() if self.api.check_ui_exists("textContains", "Profile Owner"): break time.sleep(3) assert self.api.check_ui_exists( "textContains", "Profile Owner"), "[ERROR]: fail to launch Work Sample MDM" def testDisable_Managed_Profile(self): """ disable manage profile :return: None """ self.api.remove_managed_profile() all_users = None for _ in range(5): all_users = repr( os.popen("adb -s {0} shell pm list users".format( self.api.serial)).read().strip()) if all_users.find("Work profile") == -1 and all_users.find( "HiProfileOwner") == -1: break time.sleep(3) assert all_users is not None, "[ERROR]: fail to get user info" assert all_users.find( "Work profile") == -1, "[ERROR]: still able to find Work profile" assert all_users.find( "HiProfileOwner" ) == -1, "[ERROR]: still able to find HiProfileOwner" def testAccount_Migrate(self): """ migrate account :return: None """ assert os.path.isfile( "/etc/oat/sys.conf" ), "[ERROR]: Missing config file /etc/oat/sys.config in host" cfg_file = "/etc/oat/sys.conf" account = self.config.read(cfg_file, "google_account").get("user_name") password = self.config.read(cfg_file, "google_account").get("password") # if self.api.locate_apps("Work Sample MDM"): if self.api.is_work_profile_enabled(): self.api.remove_managed_profile() if self.api.is_android_L_build(): self.function.add_google_account_mr1(account, password) else: self.api.add_google_account(account, password, False) self.api.clean_tasks() self.api.launch_app_by_intents("android.settings.SETTINGS", False) if not self.api.check_ui_exists("text", "Accounts"): self.api.d(scrollable=True).scroll.vert.to(text="Accounts") self.api.click_with_timeout("text", "Accounts") assert self.api.check_ui_exists( "text", "Google"), "[ERROR]: fail to add google account" assert not self.api.check_ui_exists( "text", "Work"), "[ERROR]: Work profile already created" self.api.api_demo_launch() if self.api.is_android_L_build( ): # TODO: change the entry if sample mdm got update for L self.api.click_with_timeout("resourceId", self.api.ui.create_and_delete_profile) else: self.api.click_with_timeout("resourceId", self.api.ui.setup_managed_profile) if self.api.check_ui_exists("resourceId", "com.intel.afw.mdm:id/content_edit", 10): self.api.d(resourceId="com.intel.afw.mdm:id/content_edit" ).set_text(account) self.api.click_with_timeout("text", "Yes") if self.api.is_android_L_build(): assert self.api.check_ui_exists( "textContains", account), "[ERROR]: fail to detect google account" self.api.click_with_timeout("textContains", account) self.api.click_with_timeout("text", "Create Managed Profile") self.api.click_with_timeout("text", "Set up") self.api.click_with_timeout("text", "OK") self.api.check_ui_exists("text", "Setup all done", 30) for _ in range(5): self.api.d.press.home() self.api.api_demo_po_launch() if self.api.check_ui_exists("textContains", "Profile Owner"): break time.sleep(3) assert self.api.check_ui_exists( "textContains", "Profile Owner"), "[ERROR]: fail to launch Work Sample MDM" self.api.clean_tasks() time.sleep(15) for _ in range(5): self.api.clean_tasks() self.api.launch_app_by_intents("android.settings.SETTINGS", False) if not self.api.check_ui_exists("text", "Accounts"): self.api.d(scrollable=True).scroll.vert.to(text="Accounts") self.api.click_with_timeout("text", "Accounts") if self.api.check_ui_exists("text", "Work") and self.api.check_ui_exists( "text", "Google"): break time.sleep(5) assert self.api.check_ui_exists( "text", "Work"), "[ERROR]: fail to detect work profile" assert self.api.check_ui_exists( "text", "Google"), "[ERROR]: fail to detect google account" assert self.api.d(text="Remove work profile").up( text="Google").exists, "[ERROR]: fail to migrate account"
class OpenTheTrustAgentSample(UIATestBase): """ @summary: Test cases for open the trust agent sample """ def setUp(self): super(OpenTheTrustAgentSample, self).setUp() self.api = ApiImpl() self.api.unlock_screen() self.api.clean_tasks() self._test_name = __name__ print "[Setup]: %s" % self._test_name def tearDown(self): super(OpenTheTrustAgentSample, self).tearDown() print "[Teardown]: %s" % self._test_name def testInstall_Trust_Agent_Sample(self): """ install trust agent sample :return: None """ self.api.uninstall_apps_by_adb( "package:com.android.trustagent.testsample") self.api.set_lock_pin() if not self.api.locate_apps("Work Sample MDM"): self.api.setup_managed_profile() self.api.launch_app("Sample MDM") assert self.api.check_ui_exists("text", self.api.ui.install_a_trust_agent), \ "[ERROR]: Install A Trust Agent Sample doesn't exist" self.api.click_with_timeout("text", self.api.ui.install_a_trust_agent) self.api.click_with_timeout("text", "Install") self.api.click_with_timeout("text", "ACCEPT", 10) self.api.check_ui_exists("text", "Done", 30) self.api.click_with_timeout("text", "Done") for _ in range(5): if self.api.locate_apps("Sample Trust Agent"): break time.sleep(5) assert self.api.locate_apps( "Sample Trust Agent" ), "[ERROR]: fail to install Sample Trust Agent" self.api.launch_app_by_intents("android.settings.SECURITY_SETTINGS", False) if not self.api.check_ui_exists("text", "Trust agents"): self.api.d(scrollable=True).scroll.vert.to(text="Trust agents") self.api.click_with_timeout("text", "Trust agents") assert self.api.check_ui_exists("text", "Sample Trust Agent"), \ "[ERROR]: Sample Trust Agent doesn't exist in settings" if not self.api.d(text="Sample Trust Agent").right( resourceId="android:id/switchWidget").checked: self.api.d(text="Sample Trust Agent").right( resourceId="android:id/switchWidget").click.wait() def testGrant_Trust_to_This_device(self): """ grant trust agent to this device :return: None """ self.api.d.sleep() self.api.d.wait.update(timeout=3000) self.api.d.wakeup() for _ in range(5): if self.api.check_ui_exists("resourceId", self.api.ui.lock_clock_view): self.api.d( resourceId=self.api.ui.lock_screen_scroll_view).swipe.up() if not self.api.check_ui_exists("resourceId", self.api.ui.lock_clock_view): break assert self.api.check_ui_exists("resourceId", self.api.ui.lock_pin_pad), \ "[ERROR]: fail to lock screen by pin code" self.api.d.sleep() self.api.unlock_screen() self.api.launch_app("Sample Trust Agent") self.api.click_with_timeout("resourceId", self.api.ui.grant_trust) self.api.d.sleep() self.api.d.wait.update(timeout=3000) self.api.d.wakeup() for _ in range(5): if self.api.check_ui_exists("resourceId", self.api.ui.lock_clock_view): self.api.d( resourceId=self.api.ui.lock_screen_scroll_view).swipe.up() if not self.api.check_ui_exists("resourceId", self.api.ui.lock_clock_view): break assert not self.api.check_ui_exists( "resourceId", self.api.ui.lock_pin_pad), "[ERROR]: unable to grant trust" self.api.clean_tasks() # sleep more than 10min self.api.d.sleep() time.sleep(800) self.api.d.wait.update(timeout=3000) os.popen("adb -s {0} shell input keyevent 82".format( self.api.serial)).read().strip() self.api.d.wait.update(timeout=3000) assert self.api.check_ui_exists("resourceId", "com.android.systemui:id/pinEntry"), \ "fail to detect pinEntry after 10mins" self.api.d.sleep() self.api.unlock_screen() def testRevoke_Trust_from_This_Device(self): """ revoke trust agent from this device :return: None """ self.api.launch_app("Sample Trust Agent") self.api.click_with_timeout("resourceId", self.api.ui.grant_trust) self.api.d.sleep() self.api.d.wait.update(timeout=3000) self.api.d.wakeup() for _ in range(5): if self.api.check_ui_exists("resourceId", self.api.ui.lock_clock_view): self.api.d( resourceId=self.api.ui.lock_screen_scroll_view).swipe.up() if not self.api.check_ui_exists("resourceId", self.api.ui.lock_clock_view): break assert not self.api.check_ui_exists( "resourceId", self.api.ui.lock_pin_pad), "[ERROR]: unable to grant trust" self.api.d.sleep() self.api.unlock_screen() self.api.clean_tasks() self.api.launch_app("Sample Trust Agent") self.api.click_with_timeout("resourceId", self.api.ui.revoke_trust) self.api.d.sleep() self.api.d.wait.update(timeout=3000) self.api.d.wakeup() for _ in range(5): if self.api.check_ui_exists("resourceId", self.api.ui.lock_clock_view): self.api.d( resourceId=self.api.ui.lock_screen_scroll_view).swipe.up() if not self.api.check_ui_exists("resourceId", self.api.ui.lock_clock_view): break assert self.api.check_ui_exists("resourceId", self.api.ui.lock_pin_pad), \ "[ERROR]: fail to lock screen by pin code" self.api.d.sleep() self.api.unlock_screen() self.api.set_lock_swipe() self.api.uninstall_apps_by_adb("com.android.trustagent.testsample")
class ProvisionDevice(UIATestBase): """ @summary: Test cases for provision device """ def setUp(self): super(ProvisionDevice, self).setUp() self._test_name = __name__ self.function = Function() self.api = ApiImpl() self.api.unlock_screen() print "[Setup]: %s" % self._test_name def tearDown(self): super(ProvisionDevice, self).tearDown() print "[Teardown]: %s" % self._test_name def testProvision_Device_with_Device_Owner(self): """ provision device with device owner during OOBE :return: None """ self.api.d.wakeup() self.function.push_uiautomator_jar() g_common_obj.set_vertical_screen() if not self.api.check_ui_exists("packageName", "com.google.android.setupwizard"): self.api.d.press.home() if self.api.check_ui_exists("description", "Apps"): self.api.clean_tasks() self.api.factory_reset() time.sleep(1200) self.api = ApiImpl() self.api.d.wakeup() g_common_obj.set_vertical_screen() else: while not self.api.check_ui_exists( "resourceId", "com.google.android.setupwizard:id/welcome_title"): self.api.d.press.back() assert self.api.check_ui_exists("resourceId", "com.google.android.setupwizard:id/welcome_title"), \ "[ERROR]: Please run test cases at the beginning of OOBE" # for unencrypted device, just bypass encryption when provision device # the encryption test cases will raise this problem if os.popen("adb -s {0} shell getprop ro.crypto.state".format( self.api.serial)).read().strip() == "unencrypted": os.popen("adb -s {0} root".format(self.api.serial)).read().strip() time.sleep(5) os.popen( "adb -s {0} shell setprop persist.sys.no_req_encrypt true". format(self.api.serial)).read().strip() time.sleep(5) self.api.oobe_setup(True) self.api.unlock_screen() self.api.clean_tasks() self.api.d.press.home() time.sleep(5) self.api.click_with_timeout("text", "GOT IT") try: self.api.api_demo_launch() assert self.api.check_ui_exists("textContains", "Device Owner", 5), \ "[ERROR]: fail to provision device as device owner" g_common_obj.set_vertical_screen() finally: self.api.keep_awake() def testWiFi_Connection_Pretest(self): """ Check WiFi connection in pretest :return: None """ # read wifi info from /etc/oat/sys.conf by default if it exist assert os.path.isfile( "/etc/oat/sys.conf" ), "[ERROR]: Missing config file /etc/oat/sys.config in host" cfg_file = "/etc/oat/sys.conf" self.ssid = self.config.read(cfg_file, 'wifisetting').get("ssid") self.password = self.config.read(cfg_file, 'wifisetting').get("passwd") self.security = self.config.read(cfg_file, 'wifisetting').get("security") self.retry_wifi = self.config.read('tests.tablet.dut_init.conf', 'init_list').get("connect_wifi") # check ui element "Apps" to make sure we are at oobe stage self.api.d.press.home() if self.api.check_ui_exists("description", "Apps"): self.api.set_lock_swipe() self.api.clean_tasks() self.api.settings_sub_launch("Backup & reset") assert self.api.check_ui_exists( "text", "Factory data reset", 5), "fail to detect factory data reset" self.api.click_with_timeout("text", "Factory data reset") self.api.click_with_timeout( "resourceId", "com.android.settings:id/initiate_master_clear") assert self.api.check_ui_exists("resourceId", "com.android.settings:id/execute_master_clear", 5), \ "fail to detect erase everything" self.api.click_with_timeout( "resourceId", "com.android.settings:id/execute_master_clear") time.sleep(600) # reboot device g_common_obj2.system_reboot(90) for _ in range(30): self.api = ApiImpl() self.api.d = g_common_obj.get_device() self.api.d.wakeup() if self.api.check_ui_exists( "resourceId", "com.google.android.setupwizard:id/welcome_title"): break time.sleep(10) self.api.d.wakeup() g_common_obj.set_vertical_screen() # keep device awake # self.api.keep_awake() # enable unknown sources self.api.unknown_source_control(True) # will check for 10 times and will back to welcome page if it's not for _ in range(10): if self.api.check_ui_exists( "resourceId", "com.google.android.setupwizard:id/welcome_title"): break # just back to welcome page self.api.d.press.back() # launch WiFi Settings by intent self.api.launch_app_by_intents("android.settings.WIFI_SETTINGS", False) assert self.api.check_ui_exists( "textMatches", "Wi.Fi"), "[ERROR]: fail to launch wifi settings" # try to connect wifi for retry in range(int(self.retry_wifi)): # turn on wifi if it is off if self.api.check_ui_exists("text", "Off"): self.api.d(text="Off").right(text="OFF").click() time.sleep(10) if self.api.d(resourceId="android:id/list").scrollable: self.api.d(scrollable=True).scroll.vert.to( text=self.ssid) # scroll to ssid if self.api.check_ui_exists("text", self.ssid): # if wifi ap is not hidden if self.api.check_ui_exists( "text", "Connected"): # break if wifi is connected break self.api.click_with_timeout("text", self.ssid) # input password if needed if self.api.check_ui_exists( "resourceId", "com.android.settings:id/password"): self.api.d(resourceId="com.android.settings:id/password" ).set_text(self.password) # click "Connect": a)first time to connect b)reconnect to wifi if failed before if self.api.check_ui_exists("text", "Connect"): self.api.click_with_timeout("text", "Connect") # click "Done" if wifi is connecting if self.api.check_ui_exists("text", "Done"): self.api.click_with_timeout("text", "Done") else: # connect to hidden wifi ap self.api.d.press.menu() self.api.d(text="Add network").click.wait() self.api.d(text="Enter the SSID").set_text(self.ssid) self.api.d(resourceId="com.android.settings:id/security", index=1).click.wait() self.api.d(text=self.security).click.wait() self.api.d( resourceId="com.android.settings:id/password").set_text( self.password) self.api.d(text="Save").click.wait() time.sleep(10) # wifi should be connected now assert self.api.check_ui_exists( "text", self.ssid), "[ERROR]: WiFi SSID does't exist" assert self.api.check_ui_exists( "text", "Connected"), "[ERROR]: Fail to connect WiFi" # back to oobe self.api.d.press.back() def testPretest_for_reliability(self): """ provision device if needed """ # read wifi info from /etc/oat/sys.conf by default if it exist assert os.path.isfile( "/etc/oat/sys.conf" ), "[ERROR]: Missing config file /etc/oat/sys.config in host" cfg_file = "/etc/oat/sys.conf" self.ssid = self.config.read(cfg_file, 'wifisetting').get("ssid") self.password = self.config.read(cfg_file, 'wifisetting').get("passwd") self.security = self.config.read(cfg_file, 'wifisetting').get("security") self.retry_wifi = self.config.read('tests.tablet.dut_init.conf', 'init_list').get("connect_wifi") # check ui element "Apps" to make sure we are at oobe stage self.api.d.press.home() self.api.d.wait.update(timeout=5000) if self.api.check_ui_exists("description", "Apps"): # self.api.set_lock_swipe() # self.api.clean_tasks() # self.api.settings_sub_launch("Backup & reset") # assert self.api.check_ui_exists("text", "Factory data reset", 5), "fail to detect factory data reset" # self.api.click_with_timeout("text", "Factory data reset") # self.api.click_with_timeout("resourceId", "com.android.settings:id/initiate_master_clear") # assert self.api.check_ui_exists("resourceId", "com.android.settings:id/execute_master_clear", 5), \ # "fail to detect erase everything" # self.api.click_with_timeout("resourceId", "com.android.settings:id/execute_master_clear") self.api.factory_reset() time.sleep(600) # reboot device g_common_obj2.system_reboot(90) for _ in range(30): # self.api = ApiImpl() self.api.d = g_common_obj.get_device() self.api.d.wakeup() if self.api.check_ui_exists( "resourceId", "com.google.android.setupwizard:id/welcome_title"): break time.sleep(10) self.api.d.wakeup() g_common_obj.set_vertical_screen() # keep device awake # self.api.keep_awake() # enable unknown sources self.api.unknown_source_control(True) # will check for 10 times and will back to welcome page if it's not for _ in range(10): if self.api.check_ui_exists( "resourceId", "com.google.android.setupwizard:id/welcome_title"): break # just back to welcome page self.api.d.press.back() # launch WiFi Settings by intent self.api.launch_app_by_intents("android.settings.WIFI_SETTINGS", False) assert self.api.check_ui_exists( "textMatches", "Wi.Fi"), "[ERROR]: fail to launch wifi settings" # try to connect wifi for retry in range(int(self.retry_wifi)): # turn on wifi if it is off if self.api.check_ui_exists("text", "Off"): self.api.d(text="Off").right(text="OFF").click() time.sleep(10) if self.api.d(resourceId="android:id/list").scrollable: self.api.d(scrollable=True).scroll.vert.to( text=self.ssid) # scroll to ssid if self.api.check_ui_exists("text", self.ssid): # if wifi ap is not hidden if self.api.check_ui_exists( "text", "Connected"): # break if wifi is connected break self.api.click_with_timeout("text", self.ssid) # input password if needed if self.api.check_ui_exists( "resourceId", "com.android.settings:id/password"): self.api.d(resourceId="com.android.settings:id/password" ).set_text(self.password) # click "Connect": a)first time to connect b)reconnect to wifi if failed before if self.api.check_ui_exists("text", "Connect"): self.api.click_with_timeout("text", "Connect") # click "Done" if wifi is connecting if self.api.check_ui_exists("text", "Done"): self.api.click_with_timeout("text", "Done") else: # connect to hidden wifi ap self.api.d.press.menu() self.api.d(text="Add network").click.wait() self.api.d(text="Enter the SSID").set_text(self.ssid) self.api.d(resourceId="com.android.settings:id/security", index=1).click.wait() self.api.d(text=self.security).click.wait() self.api.d( resourceId="com.android.settings:id/password").set_text( self.password) self.api.d(text="Save").click.wait() time.sleep(10) # wifi should be connected now assert self.api.check_ui_exists( "text", self.ssid), "[ERROR]: WiFi SSID does't exist" assert self.api.check_ui_exists( "text", "Connected"), "[ERROR]: Fail to connect WiFi" # back to oobe self.api.d.wakeup() self.function.push_uiautomator_jar() g_common_obj.set_vertical_screen() while not self.api.check_ui_exists( "resourceId", "com.google.android.setupwizard:id/welcome_title"): self.api.d.wakeup() self.api.d.press.back() assert self.api.check_ui_exists("resourceId", "com.google.android.setupwizard:id/welcome_title"), \ "[ERROR]: Please run test cases at the beginning of OOBE" # for unencrypted device, just bypass encryption when provision device # the encryption test cases will raise this problem if os.popen("adb -s {0} shell getprop ro.crypto.state".format( self.api.serial)).read().strip() == "unencrypted": os.popen("adb -s {0} root".format(self.api.serial)).read().strip() time.sleep(5) os.popen( "adb -s {0} shell setprop persist.sys.no_req_encrypt true". format(self.api.serial)).read().strip() time.sleep(5) self.api.d.wakeup() self.api.oobe_setup(True) self.api.unlock_screen() self.api.clean_tasks() self.api.d.press.home() time.sleep(5) self.api.click_with_timeout("text", "GOT IT") try: self.api.unlock_screen() self.api.launch_app("Sample MDM") assert self.api.check_ui_exists("textContains", "Device Owner", 5), \ "[ERROR]: fail to provision device as device owner" g_common_obj.set_vertical_screen() finally: self.api.keep_awake() self.api.clean_tasks() self.api.enable_system_applications(False)
class DeviceControl(UIATestBase): """ @summary: Test cases for device control """ def setUp(self): super(DeviceControl, self).setUp() self._test_name = __name__ self.api = ApiImpl() self.api.unlock_screen() self.api.clean_tasks() print "[Setup]: %s" % self._test_name def tearDown(self): super(DeviceControl, self).tearDown() print "[Teardown]: %s" % self._test_name def testReboot_OS(self): """ reboot device :return: None """ g_common_obj2.system_reboot(90) for _ in range(20): self.api = ApiImpl() self.api.d.wakeup() if self.api.check_ui_exists("resourceId", self.api.ui.lock_clock_view): break time.sleep(10) g_common_obj.set_vertical_screen() self.api.unlock_screen() if self.api.check_ui_exists("textContains", "isn't responding", 5): self.api.click_with_timeout("text", "OK") assert self.api.check_ui_exists( "description", "Apps", 5), "[ERROR]: fail to detect Apps launcher" def testWiFi_Relaunch(self): """ on/off wifi :return: None """ self.api.launch_app_by_intents("android.settings.WIFI_SETTINGS", False) if not self.api.check_ui_exists("textMatches", "Wi.Fi", 5): self.api.settings_sub_launch("Wi.Fi") try: for _ in range(2): if self.api.check_ui_exists("text", "On"): self.api.click_with_timeout( "resourceId", "com.android.settings:id/switch_bar") self.api.d(text="Off").wait.exists(timeout=5000) wifi_state = "" for i in range(10): wifi_state = os.popen( "adb -s {0} shell dumpsys wifi".format( self.api.serial)).read().strip() if wifi_state.find("Wi-Fi is disabled") != -1: break time.sleep(2) assert wifi_state.find( "Wi-Fi is disabled" ) != -1, "Fail to turn off wifi: {0}".format(wifi_state) else: self.api.click_with_timeout( "resourceId", "com.android.settings:id/switch_bar") self.api.d(text="On").wait.exists(timeout=5000) wifi_state = "" for i in range(10): wifi_state = os.popen( "adb -s {0} shell dumpsys wifi".format( self.api.serial)).read().strip() if wifi_state.find("Wi-Fi is enabled") != -1: break time.sleep(2) assert wifi_state.find( "Wi-Fi is enabled" ) != -1, "Fail to turn on wifi {0}".format(wifi_state) finally: if self.api.check_ui_exists("text", "Off"): self.api.click_with_timeout( "resourceId", "com.android.settings:id/switch_bar") def testBT_Relaunch(self): """ on/off bt :return: None """ self.api.launch_app_by_intents("android.settings.BLUETOOTH_SETTINGS", False) self.api.d(text="Bluetooth").wait.exists(timeout=5000) if not self.api.check_ui_exists("text", "Bluetooth"): self.api.settings_sub_launch("Bluetooth") # for i in range(2): # if self.api.check_ui_exists("text", "On"): # self.api.click_with_timeout("resourceId", "com.android.settings:id/switch_bar") # self.api.d(text="Off").wait.exists(timeout=5000) # else: # self.api.click_with_timeout("resourceId", "com.android.settings:id/switch_bar") # self.api.d(text="On").wait.exists(timeout=5000) # time.sleep(5) # for _ in range(2): # if self.api.check_ui_exists("text", "On"): # self.api.click_with_timeout("resourceId", "com.android.settings:id/switch_bar") # self.api.d(text="Off").wait.exists(timeout=5000) # bt_state = "" # for i in range(10): # bt_state = os.popen( # "adb -s {0} shell dumpsys bluetooth_manager".format(self.api.serial)).read().strip() # if bt_state.find("enabled: false") != -1: # break # time.sleep(2) # assert bt_state.find("enabled: false") != -1, "Fail to turn off bleutooth: {0}".format(bt_state) # else: # self.api.click_with_timeout("resourceId", "com.android.settings:id/switch_bar") # self.api.d(text="On").wait.exists(timeout=5000) # bt_state = "" # for i in range(10): # bt_state = os.popen( # "adb -s {0} shell dumpsys bluetooth_manager".format(self.api.serial)).read().strip() # if bt_state.find("enabled: true") != -1: # break # time.sleep(2) # assert bt_state.find("enabled: true") != -1, "Fail to turn on bleutooth {0}".format(bt_state) for _ in range(2): if self.api.check_ui_exists("text", "On"): self.api.click_with_timeout( "resourceId", "com.android.settings:id/switch_bar") self.api.d(text="Off").wait.exists(timeout=5000) for i in range(3): if self.api.check_ui_exists("text", "Off"): break time.sleep(5) assert self.api.check_ui_exists("text", "Off"), "fail to turn off BT" else: self.api.click_with_timeout( "resourceId", "com.android.settings:id/switch_bar") self.api.d(text="On").wait.exists(timeout=5000) for i in range(3): if self.api.check_ui_exists("text", "On"): break time.sleep(5) assert self.api.check_ui_exists("text", "On"), "fail to turn on BT" time.sleep(5) def testVolume_Increase_Decrease(self): """ verify vol +/- after setup device owner :return: None """ for i in range(3): time.sleep(1) self.api.d.press.volume_down() time.sleep(5) for i in range(3): time.sleep(1) self.api.d.press.volume_up() vol_first = self.api.get_notification_volume_by_dumpsys() for i in range(3): time.sleep(1) self.api.d.press.volume_down() vol_second = self.api.get_notification_volume_by_dumpsys() assert vol_first != vol_second, "[ERROR]: fail to decrease volume" for i in range(3): time.sleep(1) self.api.d.press.volume_up() vol_third = self.api.get_notification_volume_by_dumpsys() assert vol_second != vol_third, "[ERROR]: fail to increase volume" def testGPS_Relaunch(self): """ verify that able to turn on/off GPS :return: None """ self.api.launch_app_by_intents( "android.settings.LOCATION_SOURCE_SETTINGS", False) self.api.click_with_timeout("text", "Agree", 3) if not self.api.check_ui_exists("text", "Location"): self.api.settings_sub_launch("Location") self.api.click_with_timeout("text", "Agree", 3) for _ in range(2): if self.api.check_ui_exists("text", "On"): off_state = False for i in range(3): if self.api.check_ui_exists("text", "On"): self.api.click_with_timeout( "resourceId", "com.android.settings:id/switch_bar") if self.api.check_ui_exists("text", "Off"): off_state = True break assert off_state, "fail to turn off GPS" else: on_state = False for j in range(3): if self.api.check_ui_exists("text", "Off"): self.api.click_with_timeout( "resourceId", "com.android.settings:id/switch_bar") self.api.click_with_timeout("text", "Agree", 3) if self.api.check_ui_exists("text", "On"): on_state = True break assert on_state, "fail to turn on GPS" if self.api.check_ui_exists("text", "Off"): self.api.click_with_timeout("resourceId", "com.android.settings:id/switch_bar") self.api.click_with_timeout("text", "Agree", 3) def testNFC_Relaunch(self): """ verify relaunching NFC after device owner provisioning :return: None """ self.api.launch_app_by_intents("android.settings.SETTINGS", False) if not self.api.check_ui_exists("text", "More"): self.api.d(scrollable=True).scroll.vert.to(text="More") self.api.click_with_timeout("text", "More") assert self.api.check_ui_exists("text", "Android Beam"), "not support NFC" self.api.click_with_timeout("text", "Android Beam") for _ in range(2): if self.api.check_ui_exists("text", "On"): self.api.click_with_timeout( "resourceId", "com.android.settings:id/switch_widget") assert self.api.check_ui_exists( "text", "Off"), "fail to turn off Android Beam" else: self.api.click_with_timeout( "resourceId", "com.android.settings:id/switch_widget") assert self.api.check_ui_exists( "text", "On"), "fail to turn on Android Beam" time.sleep(2)
class MultiUserSupport(UIATestBase): """ @summary: Test cases for multi user support """ def setUp(self): super(MultiUserSupport, self).setUp() self._test_name = __name__ self.api = ApiImpl() self.api.unlock_screen() self.api.d.watchers.run() self.api.clean_tasks() print "[Setup]: %s" % self._test_name def tearDown(self): super(MultiUserSupport, self).tearDown() # reboot device since there is a chance that we get error before switch back to owner user # that will impact some later testing g_common_obj2.system_reboot(90) for _ in range(20): self.api = ApiImpl() self.api.d.wakeup() if self.api.check_ui_exists("resourceId", self.api.ui.lock_clock_view): break time.sleep(5) g_common_obj.set_vertical_screen() self.api.remove_other_users_by_id() print "[Teardown]: %s" % self._test_name def testAdd_Shift_Remove_User(self): """ verify that able to add and remove user under device owner :return: None """ self.api.remove_other_users_by_id() self.api.settings_sub_launch("Accounts") if self.api.check_ui_exists("text", "Work", 5): self.api.click_with_timeout("text", "Remove work profile") self.api.click_with_timeout("text", "Delete", 10) self.api.launch_app_by_intents("android.settings.USER_SETTINGS", False) # launch settings if not self.api.check_ui_exists("text", "Users", 5): self.api.settings_sub_launch("Users") if self.api.check_ui_exists( "text", "New user"): # remove "New user" if it already exist if self.api.check_ui_exists("resourceId", "com.android.settings:id/trash_user"): self.api.d(text="New user").right( resourceId="com.android.settings:id/trash_user").click() self.api.click_with_timeout("text", "Delete") elif self.api.check_ui_exists( "resourceId", "com.android.settings:id/manage_user"): self.api.d(text="New user").right( resourceId="com.android.settings:id/manage_user").click() self.api.click_with_timeout("text", "Remove user") self.api.click_with_timeout("text", "Delete") self.api.clean_tasks() self.api.launch_app_by_intents( "android.settings.USER_SETTINGS", False) # launch settings if not self.api.check_ui_exists("text", "Users", 5): self.api.settings_sub_launch("Users") for _ in range(10): if self.api.check_ui_exists("text", "Set up now"): break if self.api.check_ui_exists("textContains", "Add user"): self.api.click_with_timeout("textContains", "Add user") self.api.click_with_timeout("text", "User") self.api.click_with_timeout("text", "OK") assert self.api.check_ui_exists( "text", "Set up now"), "[ERROR]: fail to create new user" self.api.click_with_timeout("text", "Set up now") time.sleep( 90 ) # try to sleep 90 seconds since usb device will disconnect when switching user for _ in range(10): self.api.d.wakeup() if self.api.check_ui_exists("resourceId", self.api.ui.lock_clock_view): assert self.api.check_ui_exists("resourceId", self.api.ui.lock_clock_view), \ "[ERROR]: fail to switch to new user" self.api.unlock_screen() break time.sleep(5) self.api.launch_app_by_intents("android.settings.USER_SETTINGS", False) assert self.api.check_ui_exists( "textContains", "You (New User)", 5), "[ERROR]: fail to switch to new user" self.api.click_with_timeout("textContains", "Owner", 5) time.sleep( 90 ) # try to sleep 90 seconds since usb device will disconnect when switching user for _ in range(10): self.api.d.wakeup() if self.api.check_ui_exists("resourceId", self.api.ui.lock_clock_view): assert self.api.check_ui_exists("resourceId", self.api.ui.lock_clock_view), \ "[ERROR]: fail to switch back to owner" self.api.unlock_screen() break time.sleep(5) self.api.remove_other_users_by_id() def testGuest_Shift(self): """ verify that able to switch to guest user :return: None """ self.api.settings_sub_launch("Accounts") if self.api.check_ui_exists("text", "Work"): self.api.click_with_timeout("text", "Remove work profile") self.api.click_with_timeout("text", "Delete") self.api.launch_app_by_intents("android.settings.USER_SETTINGS", False) # launch settings self.api.d(text="Users").wait.exists(timeout=5000) if not self.api.check_ui_exists("text", "Users"): self.api.settings_sub_launch("Users") self.api.click_with_timeout("text", "Guest") time.sleep( 90 ) # try to sleep 90 seconds since usb device will disconnect when switching user if self.api.check_ui_exists("textContains", "Welcome back", 5): self.api.click_with_timeout("text", "Yes, continue") self.api.d.sleep() for _ in range(10): self.api.d.wakeup() if self.api.check_ui_exists("description", "Apps"): break if self.api.check_ui_exists("resourceId", self.api.ui.lock_clock_view): self.api.unlock_screen() break time.sleep(5) self.api.launch_app_by_intents("android.settings.USER_SETTINGS", False) # launch settings self.api.d(text="Users").wait.exists(timeout=10000) if not self.api.check_ui_exists("text", "Users"): self.api.settings_sub_launch("Users") assert self.api.check_ui_exists( "text", "Remove guest"), "[ERROR]: fail to switch to guest" self.api.click_with_timeout("text", "Remove guest", 5) self.api.click_with_timeout("text", "Remove", 5) time.sleep( 90 ) # try to sleep 90 seconds since usb device will disconnect when switching user for _ in range(10): self.api.d.wakeup() if self.api.check_ui_exists("resourceId", self.api.ui.lock_clock_view): self.api.unlock_screen() break time.sleep(5) assert self.api.check_ui_exists( "text", "Guest"), "[ERROR]: fail to switch back"
class IterationControl(UIATestBase): """ @summary: Profile Owner Provisioning """ def setUp(self): super(IterationControl, self).setUp() self._test_name = __name__ self.api = ApiImpl() self.api.unlock_screen() self.api.clean_tasks() print "[Setup]: %s" % self._test_name def tearDown(self): super(IterationControl, self).tearDown() print "[Teardown]: %s" % self._test_name def testCreateNotification_Remove_20_times(self): """ verify iteration control by create/remove notifications for 20 times :return: None """ self.api.uninstall_apps_by_adb("com.android.trustagent.testsample") self.api.unknown_source_control(True) for _ in range(10): self.api.api_demo_launch() self.api.click_with_timeout("resourceId", self.api.ui.app_provision) assert self.api.check_ui_exists("text", "Install An App Silently"), \ "fail to detect install app silently button at {0}".format(_) self.api.click_with_timeout("text", "Install An App Silently") self.api.click_with_timeout("text", "OK", 10) self.api.d.sleep() time.sleep(2) self.api.d.wakeup() assert self.api.check_ui_exists("text", "Sample Trust Agent"), \ "fail to detect the install notification in lock screen at {0}".format(_) self.api.d(text="Sample Trust Agent").swipe.right() self.api.d.wakeup() assert not self.api.check_ui_exists("text", "Sample Trust Agent"), \ "fail to remove the installed notification at {0}".format(_) self.api.unlock_screen() assert self.api.check_ui_exists("text", "Uninstall An App Silently"), \ "fail to detect uninstall button at {0}".format(_) self.api.click_with_timeout("text", "Uninstall An App Silently") self.api.click_with_timeout("text", "OK", 10) self.api.d.sleep() time.sleep(2) self.api.d.wakeup() assert self.api.check_ui_exists("text", "Sample Trust Agent"), \ "fail to detect the remove notification in lock screen at {0}".format(_) self.api.d(text="Sample Trust Agent").swipe.right() self.api.d.wakeup() assert not self.api.check_ui_exists("text", "Sample Trust Agent"), \ "fail to clear the removed notification at {0}".format(_) self.api.unlock_screen() self.api.clean_tasks() def testLaunchBT_FightMode_WorkProfile_50_times(self): """ On/off BT in fight mode :return: None """ self.api.settings_sub_launch("More") if self.api.d(text="Airplane mode").right( resourceId="android:id/switchWidget").checked: self.api.d(text="Airplane mode").right( resourceId="android:id/switchWidget").click() self.api.launch_app_by_intents("android.settings.BLUETOOTH_SETTINGS", False) if not self.api.check_ui_exists("text", "Bluetooth"): self.api.clean_tasks() self.api.settings_sub_launch("Bluetooth") if self.api.check_ui_exists("text", "Off"): self.api.click_with_timeout("resourceId", "com.android.settings:id/switch_bar") time.sleep(5) assert self.api.check_ui_exists("text", "On"), "fail to turn bleutooth on" self.api.clean_tasks() for _ in range(50): self.api.settings_sub_launch("More") assert self.api.check_ui_exists("text", "Airplane mode"), \ "fail to detect airplane mode at {0}".format(_) if not self.api.d(text="Airplane mode").right( resourceId="android:id/switchWidget").checked: self.api.d(text="Airplane mode").right( resourceId="android:id/switchWidget").click() time.sleep(5) self.api.launch_app_by_intents( "android.settings.BLUETOOTH_SETTINGS", False) if not self.api.check_ui_exists("text", "Bluetooth"): self.api.clean_tasks() self.api.settings_sub_launch("Bluetooth") assert self.api.check_ui_exists("text", "Bluetooth"), \ "fail to detect bluetooth after enable fight mode at {0}".format(_) assert self.api.check_ui_exists("text", "Off"), \ "BT wasn't off after enable fight mode at {0}".format(_) else: self.api.d(text="Airplane mode").right( resourceId="android:id/switchWidget").click() time.sleep(10) self.api.launch_app_by_intents( "android.settings.BLUETOOTH_SETTINGS", False) if not self.api.check_ui_exists("text", "Bluetooth"): self.api.clean_tasks() self.api.settings_sub_launch("Bluetooth") assert self.api.check_ui_exists("text", "Bluetooth"), \ "fail to detect bluetooth after enable fight mode at {0}".format(_) assert self.api.check_ui_exists("text", "On"), \ "BT wasn't on after enable fight mode at {0}".format(_) self.api.clean_tasks() def testLaunchWiFi_FlightMode_WorkProfile_50_times(self): """ On/off WiFi in fight mode :return: None """ self.api.settings_sub_launch("More") if self.api.d(text="Airplane mode").right( resourceId="android:id/switchWidget").checked: self.api.d(text="Airplane mode").right( resourceId="android:id/switchWidget").click() self.api.launch_app_by_intents("android.settings.WIFI_SETTINGS", False) if not self.api.check_ui_exists("text", u'Wi\u2011Fi'): self.api.clean_tasks() self.api.settings_sub_launch(u'Wi\u2011Fi') if self.api.check_ui_exists("text", "Off"): self.api.click_with_timeout("resourceId", "com.android.settings:id/switch_bar") time.sleep(5) assert self.api.check_ui_exists("text", "On"), "fail to turn wifi on" self.api.clean_tasks() for _ in range(50): self.api.settings_sub_launch("More") assert self.api.check_ui_exists("text", "Airplane mode"), \ "fail to detect airplane mode at {0}".format(_) if not self.api.d(text="Airplane mode").right( resourceId="android:id/switchWidget").checked: self.api.d(text="Airplane mode").right( resourceId="android:id/switchWidget").click() time.sleep(5) self.api.launch_app_by_intents( "android.settings.WIFI_SETTINGS", False) if not self.api.check_ui_exists("text", u'Wi\u2011Fi'): self.api.clean_tasks() self.api.settings_sub_launch(u'Wi\u2011Fi') assert self.api.check_ui_exists("text", u'Wi\u2011Fi'), \ "fail to detect Wi-Fi after enable fight mode at {0}".format(_) assert self.api.check_ui_exists("text", "Off"), \ "WiFi wasn't off after enable fight mode at {0}".format(_) else: self.api.d(text="Airplane mode").right( resourceId="android:id/switchWidget").click() time.sleep(10) self.api.launch_app_by_intents( "android.settings.WIFI_SETTINGS", False) if not self.api.check_ui_exists("text", u'Wi\u2011Fi'): self.api.clean_tasks() self.api.settings_sub_launch(u'Wi\u2011Fi') assert self.api.check_ui_exists("text", u'Wi\u2011Fi'), \ "fail to detect Wi-Fi after enable fight mode at {0}".format(_) assert self.api.check_ui_exists("text", "On"), \ "WiFi wasn't on after enable fight mode at {0}".format(_) self.api.clean_tasks()
class IterationControl(UIATestBase): """ @summary: Profile Owner Provisioning """ def setUp(self): super(IterationControl, self).setUp() self._test_name = __name__ g_common_obj2.system_reboot(90) for _ in range(20): self.api = ApiImpl() self.api.d = g_common_obj.get_device() self.api.d.wakeup() if self.api.check_ui_exists("resourceId", self.api.ui.lock_clock_view): break time.sleep(5) self.api.unlock_screen() # self.api = ApiImpl() # self.api.unlock_screen() self.api.clean_tasks() if not self.api.locate_apps("Work Sample MDM"): self.api.setup_managed_profile(True) self.api.enable_system_applications(True) time.sleep(10) self.api.clean_tasks() if not self.api.locate_apps("Work Downloads"): self.api.unhide_applications(True) time.sleep(10) self.api.clean_tasks() if not self.api.locate_apps("Work Chrome"): self.api.enable_system_applications(True) time.sleep(10) self.api.clean_tasks() print "[Setup]: %s" % self._test_name def tearDown(self): super(IterationControl, self).tearDown() print "[Teardown]: %s" % self._test_name def testAddAllSystemApp_Hide_20_times(self): """ hide and un-hide system apps for 20 times :return: None """ for _ in range(20): self.api.hide_applications(True) self.api.d.press.home() self.api.d(description="Apps").click.wait() self.api.d.wait.update(timeout=10000) assert not self.api.locate_apps( "Work Downloads" ), "Still able to detect Work Downloads at {0}".format(_) self.api.clean_tasks() self.api.unhide_applications(True) self.api.d.press.home() self.api.d(description="Apps").click.wait() self.api.d.wait.update(timeout=15000) self.api.click_with_timeout("text", "OK") assert self.api.locate_apps( "Work Downloads", 5), "Fail to detect Work Downloads at {0}".format(_) self.api.clean_tasks() def testCamera_WorkProfile_Launch_Close_50times(self): """ launch and close google camera under managed profile :return: None """ # self.api.launch_app("Work Camera") self.api.launch_app_by_activity( "com.android.camera2/com.android.camera.CameraLauncher", True) self.api.d(packageName="com.android.camera2").wait.exists(timeout=5000) for i in range(5): if not self.api.check_ui_exists( "resourceId", "com.android.packageinstaller:id/permission_allow_button"): break self.api.click_with_timeout( "resourceId", "com.android.packageinstaller:id/permission_allow_button") self.api.click_with_timeout("text", "NEXT") if self.api.check_ui_exists("packageName", "com.google.android.GoogleCamera"): assert self.api.check_ui_exists("packageName", "com.google.android.GoogleCamera"), \ "fail to launch work camera at first time" else: assert self.api.check_ui_exists("packageName", "com.android.camera2"), \ "fail to launch work camera2 at first time" self.api.clean_tasks() for _ in range(50): # self.api.launch_app("Work Camera") self.api.launch_app_by_activity( "com.android.camera2/com.android.camera.CameraLauncher", True) self.api.d(packageName="com.android.camera2").wait.exists( timeout=5000) assert not self.api.check_ui_exists( "text", "Camera error"), "Detect camera error at {0}".format(_) if self.api.check_ui_exists("packageName", "com.google.android.GoogleCamera"): assert self.api.check_ui_exists("packageName", "com.google.android.GoogleCamera"), \ "fail to launch work camera at {0}".format(_) else: assert self.api.check_ui_exists("packageName", "com.android.camera2"), \ "fail to launch work camera2 at {0}".format(_) self.api.clean_tasks() def testRemoveRecentTasks_WorkProfile_50_times(self): """ remove recent tasks for 50 times under managed profile :return: None """ for _ in range(50): self.api.api_demo_po_launch() self.api.clean_tasks() self.api.d.press.recent() time.sleep(5) assert not self.api.check_ui_exists("resourceId", self.api.ui.dismiss_task), \ "Detect dismiss task at {0}".format(_) self.api.d.press.home() def testChrome_WorkProfile_10MSNTabs_Close_50times(self): """ verify iteration control by close 10 tabs in badged chrome app for 50 times :return: None """ self.api.launch_app_by_intents( "android.intent.action.VIEW -c android.intent.category.BROWSABLE -d http://www.bing.com", True) for i in range(5): if self.api.check_ui_exists("text", "Welcome to Chrome"): self.api.click_with_timeout( "resourceId", "com.android.chrome:id/terms_accept") self.api.click_with_timeout("text", "Next") self.api.click_with_timeout("text", "No thanks") self.api.click_with_timeout( "resourceId", "com.android.chrome:id/got_it_button") break self.api.clean_tasks() model = os.popen("adb -s {0} shell getprop ro.product.model".format( self.api.serial)).read().strip() if model.find("sltmrd") != -1 or model.find("s3gr") != -1: for i in range(50): for j in range(10): self.api.launch_app_by_intents( "android.intent.action.VIEW -c android.intent.category.BROWSABLE -d http://www.bing.com", True) time.sleep(5) self.api.d.press.home() self.api.clean_tasks() self.api.d.press("recent") assert not self.api.check_ui_exists("resourceId", self.api.ui.dismiss_task), \ "fail to close chrome at {0}".format(i) self.api.d.press.home() else: for _ in range(50): self.api.launch_app_by_intents( "android.intent.action.VIEW -c android.intent.category.BROWSABLE -d http://www.bing.com", True) for j in range(9): self.api.d.press.menu() if self.api.check_ui_exists("text", "New tab", 5): self.api.click_with_timeout("text", "New tab") else: self.api.click_with_timeout("text", "New incognito tab") if self.api.check_ui_exists( "resourceId", "com.android.chrome:id/url_bar"): self.api.d(resourceId="com.android.chrome:id/url_bar" ).set_text("www.bing.com") else: self.api.d( resourceId="com.android.chrome:id/search_box_text" ).set_text("www.bing.com") self.api.d.press.enter() time.sleep(5) self.api.clean_tasks() self.api.d.press("recent") assert not self.api.check_ui_exists("resourceId", self.api.ui.dismiss_task), \ "fail to close multi tabs chrome at {0}".format(_) self.api.d.press.home() def testCreateNotification_Remove_20_times(self): """ verify iteration control by create/remove notifications for 20 times :return: None """ self.api.api_demo_po_launch() self.api.click_with_timeout("resourceId", self.api.ui.vpn_management) for _ in range(20): self.api.unlock_screen() self.api.click_with_timeout("resourceId", self.api.ui.install_ca_cert) self.api.click_with_timeout("text", "Select All", 5) self.api.click_with_timeout("resourceId", "android:id/button1", 5) self.api.d.sleep() time.sleep(3) network_notification = False for i in range(5): self.api.d.wakeup() if self.api.check_ui_exists("text", "Network may be monitored"): network_notification = True break assert network_notification, \ "Fail to detect Network may be monitored in lock screen at {0}".format(_) self.api.unlock_screen() self.api.click_with_timeout("resourceId", self.api.ui.uninstall_all_user_ca_cert, 5) self.api.click_with_timeout("resourceId", "android:id/button1", 5) self.api.d.sleep() time.sleep(3) network_notification = True for i in range(3): self.api.d.wakeup() if not self.api.check_ui_exists("text", "Network may be monitored"): network_notification = False break assert not network_notification, \ "Still detect Network may be monitored in lock screen at {0}".format(_) self.api.unlock_screen() def testAddCrossProfileWidget_Remove_50_times(self): """ verify iteration control by add/remove badged widgets for 50 times :return: None """ for _ in range(50): self.api.clean_tasks() self.api.add_x_profile_widget_provider(True) work_widget = False self.api.d(text="Work Clock").wait.exists(timeout=5000) for i in range(3): if self.api.check_ui_exists( "description", "Work Calendar") or self.api.check_ui_exists( "description", "Work Clock"): work_widget = True break assert work_widget, "fail to detect work calendar/clock widget at {0}".format( _) self.api.clean_tasks() self.api.remove_x_profile_widget_provider(True) work_widget = True for i in range(3): if not self.api.check_ui_exists( "description", "Work Calendar") and not self.api.check_ui_exists( "description", "Work Clock"): work_widget = False break assert not work_widget, "detect work calendar/clock widget at {0}".format( _)
class AppData(UIATestBase): """ @summary: check app data """ def setUp(self): super(AppData, self).setUp() self._test_name = __name__ self.api = ApiImpl() self.api.unlock_screen() self.api.clean_tasks() print "[Setup]: %s" % self._test_name def tearDown(self): super(AppData, self).tearDown() print "[Teardown]: %s" % self._test_name def testCrossProfileWidgetInfo(self): """ verify that widgets for primary user and work profile are both exists :return: None """ try: self.api.add_x_profile_widget_provider(True) if self.api.is_android_L_build(): self.api.d(text="Analog clock").wait.exists(timeout=5000) assert self.api.check_ui_exists("text", "Analog clock"), "fail to detect Analog clock widget" assert self.api.d(text="Analog clock").right(text="Analog clock").exists, \ "fail to detect two clock widget" else: work_widget = False self.api.d(text="Work Clock").wait.exists(timeout=5000) for _ in range(3): if self.api.check_ui_exists( "description", "Work Calendar") or self.api.check_ui_exists("description", "Work Clock"): work_widget = True break assert work_widget, "fail to detect work calendar/clock widget" finally: self.api.clean_tasks() self.api.remove_x_profile_widget_provider(True) self.api.d.press.home() def testCrossProfileAppInfo(self): """ verify that app info between primary user and work profile are different :return: None """ if not self.api.launch_app_by_activity(self.api.ui.chrome, True): self.api.launch_app("Work Chrome") # for i in range(5): # if not self.api.check_ui_exists("resourceId", "com.android.packageinstaller:id/permission_allow_button"): # break # self.api.click_with_timeout("resourceId", "com.android.packageinstaller:id/permission_allow_button") # time.sleep(5) # self.api.click_with_timeout("text", "NEXT") self.api.d(packageName="com.android.chrome").wait.exists(timeout=5000) for _ in range(3): self.api.unlock_screen() if self.api.check_ui_exists("text", "Welcome to Chrome"): self.api.click_with_timeout("resourceId", "com.android.chrome:id/terms_accept") self.api.click_with_timeout("text", "Next") self.api.click_with_timeout("text", "No thanks") self.api.click_with_timeout("resourceId", "com.android.chrome:id/got_it_button") self.api.d.wait.update(timeout=3000) break self.api.launch_app_by_intents( "android.settings.APPLICATION_DETAILS_SETTINGS -d package:com.android.chrome", False) self.api.d(packageName="com.android.settings").wait.exists(timeout=5000) # if not self.api.check_ui_exists("text", "App info", 5): # # self.api.launch_app_by_intents("android.settings.APPLICATION_SETTINGS", False) # self.api.settings_sub_launch("Apps") # if self.api.is_android_L_build(): # self.api.click_with_timeout("text", "Running") # self.api.click_with_timeout("text", "All") # else: # if self.api.check_ui_exists("text", "All apps"): # self.api.click_with_timeout("text", "All apps") # self.api.click_with_timeout("text", "Personal") # elif self.api.check_ui_exists("text", "Work"): # self.api.click_with_timeout("text", "Work") # self.api.click_with_timeout("text", "Personal") # if not self.api.check_ui_exists("text", "Camera", 5): # self.api.d(scrollable=True).scroll.vert.to(text="Camera") # self.api.click_with_timeout("text", "Camera") # time.sleep(5) if self.api.is_android_L_build(): self.api.click_with_timeout("text", "Clear data") self.api.click_with_timeout("text", "OK") data_size = self.api.d(resourceId="com.android.settings:id/data_size_text").text else: self.api.click_with_timeout("text", "Storage") assert self.api.check_ui_exists("text", "Data"), "fail to detect Cache" self.api.click_with_timeout("text", "Clear data") self.api.click_with_timeout("text", "OK") data_size = self.api.d(text="Data").right(resourceId="android:id/summary").text self.api.launch_app_by_intents( "android.settings.APPLICATION_DETAILS_SETTINGS -d package:com.android.chrome", True) self.api.d(packageName="com.android.settings").wait.exists(timeout=5000) # if not self.api.check_ui_exists("text", "App info", 5): # # self.api.launch_app_by_intents("android.settings.APPLICATION_SETTINGS", True) # self.api.settings_sub_launch("Apps") # if self.api.is_android_L_build(): # self.api.click_with_timeout("text", "Running") # self.api.click_with_timeout("text", "All") # else: # if self.api.check_ui_exists("text", "All apps"): # self.api.click_with_timeout("text", "All apps") # self.api.click_with_timeout("text", "Work") # elif self.api.check_ui_exists("text", "Personal"): # self.api.click_with_timeout("text", "Personal") # self.api.click_with_timeout("text", "Work") # if not self.api.check_ui_exists("text", "Camera", 5): # self.api.d(scrollable=True).scroll.vert.to(text="Camera") # self.api.click_with_timeout("text", "Camera") # time.sleep(5) if self.api.is_android_L_build(): data_size_work = self.api.d(resourceId="com.android.settings:id/data_size_text").text else: self.api.click_with_timeout("text", "Storage") assert self.api.check_ui_exists("text", "Data"), "fail to detect Cache under work profile" data_size_work = self.api.d(text="Data").right(resourceId="android:id/summary").text assert data_size.encode('ascii', 'ignore') != data_size_work.encode('ascii', 'ignore'), \ "the cache size are same between primary user and work profile" def testCrossProfileIsolation(self): """ verify cross profile isolation when work profile is enabled :return: None """ if not self.api.locate_apps("Work Clock"): self.api.enable_system_applications(True) set_alarm = "android.intent.action.SET_ALARM " \ "--ei android.intent.extra.alarm.HOUR {1} " \ "--ei android.intent.extra.alarm.MINUTES {2}" show_alarm = "android.intent.action.SHOW_ALARMS" self.api.launch_app_by_intents(show_alarm, True) if self.api.check_ui_exists("text", "Complete action using"): self.api.click_with_timeout("text", "Clock") self.api.click_with_timeout("resourceId", "android:id/button_always") for _ in range(3): if not self.api.check_ui_exists("text", u'11:11\u200aAM'): break self.api.click_with_timeout("text", u'11:11\u200aAM') self.api.click_with_timeout("text", "Cancel") self.api.click_with_timeout("resourceId", "com.android.deskclock:id/delete") self.api.launch_app_by_intents(set_alarm.format(self.api.serial, '11', '11'), True) if self.api.check_ui_exists("text", "Complete action using"): self.api.click_with_timeout("text", "Clock") self.api.click_with_timeout("resourceId", "android:id/button_always") assert self.api.check_ui_exists("text", u'11:11\u200aAM'), "fail to create new alarm for work profile" self.api.launch_app_by_intents(show_alarm, False) if self.api.check_ui_exists("text", "Complete action using"): self.api.click_with_timeout("text", "Clock") self.api.click_with_timeout("resourceId", "android:id/button_always") assert not self.api.check_ui_exists("text", u'11:11\u200aAM'), "detect the alarm which set in work profile" self.api.clean_tasks() self.api.launch_app_by_intents(show_alarm, False) for _ in range(3): if not self.api.check_ui_exists("text", u'10:10\u200aAM'): break self.api.click_with_timeout("text", u'10:10\u200aAM') self.api.click_with_timeout("text", "Cancel") self.api.click_with_timeout("resourceId", "com.android.deskclock:id/delete") self.api.launch_app_by_intents(set_alarm.format(self.api.serial, '10', '10'), False) if self.api.check_ui_exists("text", "Complete action using"): self.api.click_with_timeout("text", "Clock") self.api.click_with_timeout("resourceId", "android:id/button_always") assert self.api.check_ui_exists("text", u'10:10\u200aAM'), "fail to create new alarm" self.api.launch_app_by_intents(show_alarm, True) assert not self.api.check_ui_exists("text", u'10:10\u200aAM'), "detect the alarm which set in primary"
class GMSBehavior(UIATestBase): """ @summary: check app behavior under work profile """ def setUp(self): super(GMSBehavior, self).setUp() self._test_name = __name__ self.api = ApiImpl() self.api.unlock_screen() self.api.clean_tasks() print "[Setup]: %s" % self._test_name def tearDown(self): super(GMSBehavior, self).tearDown() print "[Teardown]: %s" % self._test_name def testGMS_Account_WorkProfile_Add(self): """ verify that able to add google account in profile owner :return: None """ assert os.path.isfile("/etc/oat/sys.conf"), "/etc/oat/sys.conf doesn't exists" account = self.config.read("/etc/oat/sys.conf", "google_account").get("user_name") password = self.config.read("/etc/oat/sys.conf", "google_account").get("password") self.api.launch_app_by_intents("android.settings.SYNC_SETTINGS", False) self.api.d(packageName="com.android.settings").wait.exists(timeout=5000) if not self.api.check_ui_exists("text", "Accounts"): self.api.settings_launch() if not self.api.check_ui_exists("text", "Accounts") and self.api.d(scrollable=True).exists: self.api.d(scrollable=True).scroll.vert.to(textContains="Accounts") self.api.click_with_timeout("text", "Accounts") for _ in range(5): if not self.api.check_ui_exists("text", "Google"): break self.api.click_with_timeout("text", "Google") time.sleep(2) self.api.d.press.menu() self.api.click_with_timeout("text", "Remove account") self.api.click_with_timeout("text", "Remove account") time.sleep(5) self.api.clean_tasks() self.api.add_google_account(account, password, True) self.api.d.press.home() self.api.clean_tasks() self.api.settings_sub_launch("Accounts") assert self.api.check_ui_exists("text", "Google"), "fail to detect google account" def testGMS_Account_WorkProfile_Remove(self): """ verify that able to remove google account in profile owner :return: None """ account = self.config.read("/etc/oat/sys.conf", "google_account").get("user_name") password = self.config.read("/etc/oat/sys.conf", "google_account").get("password") self.api.settings_sub_launch("Accounts") if not self.api.check_ui_exists("text", "Google"): self.api.clean_tasks() self.api.add_google_account(account, password, True) self.api.clean_tasks() self.api.settings_sub_launch("Accounts") self.api.click_with_timeout("text", "Google") time.sleep(5) self.api.d.press.menu() self.api.click_with_timeout("text", "Remove account") self.api.click_with_timeout("text", "Remove account") time.sleep(5) assert not self.api.check_ui_exists("text", "Google"), "fail to remove google account"
class GMSDataRemove(UIATestBase): """ @summary: Test cases for apps control with GMS app in work profile """ def setUp(self): super(GMSDataRemove, self).setUp() self._test_name = __name__ self.api = ApiImpl() self.api.unlock_screen() self.api.clean_tasks() print "[Setup]: %s" % self._test_name def tearDown(self): super(GMSDataRemove, self).tearDown() print "[Teardown]: %s" % self._test_name def testGMSApp_WorkProfile_Clear_Cache(self): # if not self.api.launch_app_by_activity(self.api.ui.camera, True): # launch camera to generate cache # self.api.launch_app("Work Camera") # for i in range(5): # if not self.api.check_ui_exists("resourceId", "com.android.packageinstaller:id/permission_allow_button"): # break # self.api.click_with_timeout("resourceId", "com.android.packageinstaller:id/permission_allow_button") # time.sleep(5) # self.api.click_with_timeout("text", "NEXT") # # launch app info for Google Camera # self.api.launch_app_by_intents( # "android.settings.APPLICATION_DETAILS_SETTINGS -d package:com.google.android.GoogleCamera", True) # # launch app info from Apps Settings if fail to launch it by intent directly # if not self.api.check_ui_exists("text", "App info", 5): # self.api.launch_app_by_intents("android.settings.APPLICATION_SETTINGS", True) # if self.api.is_android_L_build(): # self.api.click_with_timeout("text", "Running") # self.api.click_with_timeout("text", "All") # else: # if self.api.check_ui_exists("text", "All apps"): # self.api.click_with_timeout("text", "All apps") # self.api.click_with_timeout("text", "Work") # if not self.api.check_ui_exists("text", "Camera", 5): # self.api.d(scrollable=True).scroll.vert.to(text="Camera") # self.api.click_with_timeout("text", "Camera") # time.sleep(10) self.api.launch_app_by_activity(self.api.ui.chrome, True) for _ in range(5): if self.api.check_ui_exists("text", "Welcome to Chrome"): self.api.click_with_timeout( "resourceId", "com.android.chrome:id/terms_accept") self.api.click_with_timeout("text", "Next") self.api.click_with_timeout("text", "No thanks") self.api.click_with_timeout( "resourceId", "com.android.chrome:id/got_it_button") self.api.d.wait.update(timeout=3000) break self.api.launch_app_by_intents( "android.settings.APPLICATION_DETAILS_SETTINGS -d package:com.android.chrome", True) self.api.d.wait.update(timeout=5000) if self.api.is_android_L_build(): assert self.api.check_ui_exists("text", "Clear cache", 5), \ "[ERROR]: fail to launch apps control for Google Chrome" cache_size = self.api.d( resourceId="com.android.settings:id/cache_size_text").text assert cache_size.encode('ascii', 'ignore') != "12.00KB", \ "[ERROR]: cache size is equal to default size 12.00KB" self.api.click_with_timeout("text", "Clear cache") cache_size = self.api.d( resourceId="com.android.settings:id/cache_size_text").text assert cache_size.encode('ascii', 'ignore') == "12.00KB", \ "[ERROR]: cache size is not equal to 12.00KB after clear" else: assert self.api.check_ui_exists("text", "Storage", 5), "fail to detect storage" self.api.click_with_timeout("text", "Storage") cache_size = self.api.d(text="Cache").right( resourceId="android:id/summary").text assert cache_size.encode('ascii', 'ignore') != "12.00 KB", \ "[ERROR]: cache size is equal to default size 12.00 KB" self.api.click_with_timeout("text", "Clear cache") cache_size = self.api.d(text="Cache").right( resourceId="android:id/summary").text assert cache_size.encode('ascii', 'ignore') == "12.00 KB", \ "[ERROR]: cache size is not equal to 12.00 KB after clear" def testGMSApp_WorkProfile_Clear_Data(self): # if not self.api.launch_app_by_activity(self.api.ui.camera, True): # self.api.launch_app("Work Camera") # for i in range(5): # if not self.api.check_ui_exists("resourceId", "com.android.packageinstaller:id/permission_allow_button"): # break # self.api.click_with_timeout("resourceId", "com.android.packageinstaller:id/permission_allow_button") # time.sleep(5) # self.api.click_with_timeout("text", "NEXT") # self.api.launch_app_by_intents( # "android.settings.APPLICATION_DETAILS_SETTINGS -d package:com.google.android.GoogleCamera", True) # if not self.api.check_ui_exists("text", "App info", 5): # self.api.launch_app_by_intents("android.settings.APPLICATION_SETTINGS", True) # if self.api.is_android_L_build(): # self.api.click_with_timeout("text", "Running") # self.api.click_with_timeout("text", "All") # else: # if self.api.check_ui_exists("text", "All apps"): # self.api.click_with_timeout("text", "All apps") # self.api.click_with_timeout("text", "Work") # if not self.api.check_ui_exists("text", "Camera", 5): # self.api.d(scrollable=True).scroll.vert.to(text="Camera") # self.api.click_with_timeout("text", "Camera") # time.sleep(10) self.api.launch_app_by_activity(self.api.ui.chrome, True) for _ in range(5): if self.api.check_ui_exists("text", "Welcome to Chrome"): self.api.click_with_timeout( "resourceId", "com.android.chrome:id/terms_accept") self.api.click_with_timeout("text", "Next") self.api.click_with_timeout("text", "No thanks") self.api.click_with_timeout( "resourceId", "com.android.chrome:id/got_it_button") self.api.d.wait.update(timeout=3000) break self.api.launch_app_by_intents( "android.settings.APPLICATION_DETAILS_SETTINGS -d package:com.android.chrome", True) self.api.d.wait.update(timeout=5000) if self.api.is_android_L_build(): assert self.api.check_ui_exists("text", "Clear data", 5), \ "[ERROR]: fail to launch apps control for Google Chrome" cache_size = self.api.d( resourceId="com.android.settings:id/cache_size_text").text data_size = self.api.d( resourceId="com.android.settings:id/data_size_text").text assert cache_size.encode( 'ascii', 'ignore' ) != "0.00B", "[ERROR]: cache size is 0.00B before clear data" assert data_size.encode( 'ascii', 'ignore' ) != "0.00B", "[ERROR]: data size is 0.00B before clear data" self.api.click_with_timeout("text", "Clear data") self.api.click_with_timeout("text", "OK") cache_size = self.api.d( resourceId="com.android.settings:id/cache_size_text").text data_size = self.api.d( resourceId="com.android.settings:id/data_size_text").text assert cache_size.encode( 'ascii', 'ignore' ) == "0.00B", "[ERROR]: cache size is not 0.00B after clear data" assert data_size.encode( 'ascii', 'ignore' ) == "0.00B", "[ERROR]: data size is not 0.00B after clear data" else: assert self.api.check_ui_exists("text", "Storage", 5), "fail to detect storage" self.api.click_with_timeout("text", "Storage") cache_size = self.api.d(text="Cache").right( resourceId="android:id/summary").text data_size = self.api.d(text="Data").right( resourceId="android:id/summary").text assert cache_size.encode( 'ascii', 'ignore' ) != "0.00 B", "[ERROR]: cache size is 0.00 B before clear data" assert data_size.encode( 'ascii', 'ignore' ) != "0.00 B", "[ERROR]: data size is 0.00 B before clear data" self.api.click_with_timeout("text", "Clear data") self.api.click_with_timeout("text", "OK") cache_size = self.api.d(text="Cache").right( resourceId="android:id/summary").text data_size = self.api.d(text="Data").right( resourceId="android:id/summary").text assert cache_size.encode('ascii', 'ignore') == "0.00 B", \ "[ERROR]: cache size is not 0.00 B after clear data" assert data_size.encode('ascii', 'ignore') == "0.00 B", \ "[ERROR]: data size is not 0.00 B after clear data"
class Cert(UIATestBase): """ @summary: Test cases for apps control with GMS app in work profile """ def setUp(self): super(Cert, self).setUp() self._test_name = __name__ self.api = ApiImpl() self.api.unlock_screen() self.api.clean_tasks() print "[Setup]: %s" % self._test_name def tearDown(self): super(Cert, self).tearDown() print "[Teardown]: %s" % self._test_name def testAddCert(self): """ verify adding certs in work profile :return: None """ self.api.api_demo_po_launch() self.api.click_with_timeout("resourceId", self.api.ui.vpn_management) self.api.d(resourceId=self.api.ui.install_ca_cert).wait.exists( timeout=5000) self.api.click_with_timeout("resourceId", self.api.ui.install_ca_cert) self.api.d(text="mytestcert5.cer").wait.exists(timeout=5000) self.api.click_with_timeout("text", "Select All") self.api.click_with_timeout("text", "Install CA Cert") self.api.launch_app_by_intents("android.settings.SECURITY_SETTINGS", False) self.api.d(packageName="com.android.settings").wait.exists( timeout=5000) if not self.api.check_ui_exists("text", "Security"): self.api.settings_sub_launch("Security") if not self.api.check_ui_exists("text", "Trusted credentials"): self.api.d(scrollable=True).scroll.vert.to( text="Trusted credentials") self.api.click_with_timeout("text", "Trusted credentials") self.api.d(text="User").wait.exists(timeout=5000) self.api.click_with_timeout("text", "User") self.api.d(text="Work").wait.exists(timeout=5000) self.api.click_with_timeout("text", "Work") assert self.api.check_ui_exists( "text", "intel5"), "fail to detect installed cert in work profile" def testRemoveCert(self): """ verify that able to remove installed cert file from settings :return: None """ self.api.launch_app_by_intents("android.settings.SECURITY_SETTINGS", False) self.api.d(packageName="com.android.settings").wait.exists( timeout=5000) if not self.api.check_ui_exists("text", "Security"): self.api.settings_sub_launch("Security") if not self.api.check_ui_exists("text", "Trusted credentials"): self.api.d(scrollable=True).scroll.vert.to( text="Trusted credentials") self.api.click_with_timeout("text", "Trusted credentials") self.api.d(text="User").wait.exists(timeout=5000) self.api.click_with_timeout("text", "User") self.api.d(text="Work").wait.exists(timeout=5000) self.api.click_with_timeout("text", "Work") if not self.api.check_ui_exists("text", "intel5"): self.api.click_with_timeout("text", "Work") self.api.click_with_timeout("text", "intel5") if not self.api.check_ui_exists("text", "Remove"): self.api.d(scrollable=True).scroll.vert.to(text="Remove") self.api.click_with_timeout("text", "Remove") self.api.click_with_timeout("text", "OK") try: assert not self.api.check_ui_exists("text", "intel5"), \ "fail to remove installed cert under work profile" finally: self.api.api_demo_po_launch() self.api.click_with_timeout("resourceId", self.api.ui.vpn_management) self.api.d( resourceId=self.api.ui.uninstall_all_user_ca_cert).wait.exists( timeout=5000) self.api.click_with_timeout("resourceId", self.api.ui.uninstall_all_user_ca_cert) self.api.d(text="Yes").wait.exists(timeout=5000) self.api.click_with_timeout("text", "Yes") def testClearCredentials(self): """ verify removing certs in work profile :return: None """ cert_file = self.api.download_file_from_artifactory( self.api.remote.cert_file['sub_path'], self.api.remote.cert_file['name']) assert cert_file is not None, "[ERROR]: fail to download CA Cert file" self.api.set_lock_pin() if self.api.is_android_L_build(): os.popen( "adb -s {0} push {1} /mnt/shell/emulated/0/Download/".format( self.api.serial, cert_file)) else: os.popen( "adb -s {0} push {1} /storage/emulated/0/Download/".format( self.api.serial, cert_file)) self.api.launch_app_by_intents("android.settings.SECURITY_SETTINGS", False) self.api.d(packageName="com.android.settings").wait.exists( timeout=5000) if not self.api.check_ui_exists("text", "Security"): self.api.settings_sub_launch("Security") if not self.api.check_ui_exists("text", "Install from SD card"): self.api.d(scrollable=True).scroll.vert.to( text="Install from SD card") self.api.click_with_timeout("text", "Install from SD card") if not self.api.check_ui_exists("text", "Internal storage"): x = self.api.d.info['displayWidth'] y = self.api.d.info['displayHeight'] self.api.d.swipe(0, y / 2, x / 2, y / 2, steps=10) self.api.click_with_timeout("text", "Internal storage") self.api.click_with_timeout("text", "Download") assert self.api.check_ui_exists( "text", "key_alpha.cer"), "fail to detect cert file in Download" self.api.click_with_timeout("text", "key_alpha.cer") self.api.d(resourceId="com.android.certinstaller:id/credential_name" ).set_text("hello") self.api.click_with_timeout("text", "OK") if not self.api.check_ui_exists("text", "Clear credentials"): self.api.d(scrollable=True).scroll.vert.to( text="Clear credentials") try: assert self.api.d(text="Clear credentials" ).enabled, "there isn't any cert file exist" self.api.click_with_timeout("text", "Clear credentials") self.api.click_with_timeout("text", "OK") assert not self.api.d( text="Clear credentials").enabled, "fail to remove certs" finally: self.api.set_lock_swipe()