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 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 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"