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 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 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 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 setUp(self): super(ProfileOwnerProvisioning, self).setUp() self._test_name = __name__ self.api = ApiImpl() self.api.unlock_screen() self.api.clean_tasks() print "[Setup]: %s" % self._test_name
def testRebootOSADB(self): """ reboot device by 'adb reboot' while setting up work profile :return: None """ if self.api.locate_apps("Work Sample MDM"): self.api.remove_managed_profile(True) self.api.clean_tasks() self.api.api_demo_launch() self.api.click_with_timeout("resourceId", self.api.ui.setup_managed_profile) if not self.api.is_android_L_build(): self.api.click_with_timeout("text", "No", 5) self.api.click_with_timeout("text", "Set up", 10) self.api.click_with_timeout("text", "OK") self.api.click_with_timeout("text", "OK") 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.unlock_screen() if self.api.check_ui_exists("textContains", "isn't responding", 5): self.api.click_with_timeout("text", "OK") self.api.clean_tasks() assert self.api.check_ui_exists("description", "Apps"), "Fail to detect Apps Launcher"
def setUp(self): super(IntentForwarding, self).setUp() self._test_name = __name__ self.api = ApiImpl() self.api.unlock_screen() self.api.clean_tasks() print "[Setup]: %s" % self._test_name
class IntentForwarding(UIATestBase): """ @summary: Test cases for apps control with GMS app in work profile """ def setUp(self): super(IntentForwarding, 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(IntentForwarding, self).tearDown() print "[Teardown]: %s" % self._test_name def testLaunchPhotosAlbum_Work(self): self.api.launch_app_by_intents( "android.intent.action.GET_CONTENT -d 'file:///null.jpg' -t 'image/*'", True) assert self.api.check_ui_exists("text", "Recent"), "fail to detect recent item" if not self.api.check_ui_exists("text", "Photos"): 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) assert self.api.check_ui_exists("text", "Photos"), "fail to detect photos item" assert self.api.check_ui_exists( "textContains", "Personal"), "fail to detect personal apps"
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 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
class CheckDeviceOwnerAfterGOTA(UIATestBase): def setUp(self): super(CheckDeviceOwnerAfterGOTA, self).setUp() self._test_name = __name__ cfg_file = os.path.join(os.environ.get('TEST_DATA_ROOT', ''), 'tests.tablet.gota.conf') self.cfg = self.config.read(cfg_file, 'gota') self.gota = gotaImpl(self.cfg) self.api = ApiImpl() self.d = g_common_obj.get_device() print "[Setup]: %s" % self._test_name self.ssid = self.config.read(cfg_file, 'wifisetting').get("ssid") self.passwd = self.config.read(cfg_file, 'wifisetting').get("passwd") def tearDown(self): print "[Teardown]: %s" % self._test_name super(CheckDeviceOwnerAfterGOTA, self).tearDown() self.cfg = None def testCheckDeviceOwnerAfterGOTA(self): print "[RunTest]: %s" % self.__str__() #flash DUT base_build = self.cfg.get("base_build") self.gota.phone_flash_tool_build_zip_file(base_build) self.gota.push_uiautomator_jar() g_common_obj.set_vertical_screen() #check Connect AP before gota self.gota.launch_settings() print "self.ssid: %s" % self.ssid print "self.passwd: %s" % self.passwd if self.ssid == None: print "using default ap setting" self.gota.connect_AP("SHZ13F-OTC-irda101", "zxcvbnm!?") else: print "using config ap setting" self.gota.connect_AP(self.ssid, self.passwd) print "[Info] --- Connect ap before gota" #setup init DUT self.gota.enable_developer_option() self.gota.keep_awake() self.gota.close_lock_screen() self.gota.accept_unknow_resource() self.gota.unverify_apps_over_USB() self.d.press.back() self.d.press.back() #setup Sample MDM in oobe self.api.oobe_setup(True) #check Sample MDM(Profile Owner) before gota self.api.launch_app("Sample MDM") self.assertFalse( self.d(text="Sample MDM(Profile Owner)").exists, "[ERROR]:Fail to provision device as device owner") #check data in personal profile before gota self.gota.check_AFW_data_in_personal_profile_before_GOTA() #download and install GOTA package self.gota.download_package_and_auto_retry() self.gota.restart_and_install_package() #check Sample MDM(Profile Owner) after gota self.gota.check_AFW_devices_owner_after_GOTA()
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 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 setUp(self): super(CheckDeviceOwnerAfterGOTA, self).setUp() self._test_name = __name__ cfg_file = os.path.join(os.environ.get('TEST_DATA_ROOT', ''), 'tests.tablet.gota.conf') self.cfg = self.config.read(cfg_file, 'gota') self.gota = gotaImpl(self.cfg) self.api = ApiImpl() self.d = g_common_obj.get_device() print "[Setup]: %s" % self._test_name self.ssid = self.config.read(cfg_file, 'wifisetting').get("ssid") self.passwd = self.config.read(cfg_file, 'wifisetting').get("passwd")
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() 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 setUp(self): super(CheckBasicInfoBeforeGOTA, self).setUp() cfg_file = os.path.join(os.environ.get('TEST_DATA_ROOT', ''), 'tests.tablet.gota.conf') globle_file = os.path.join(os.environ.get('TEST_DATA_ROOT', ''), 'tests.tablet.gota.conf') self._test_name = __name__ print "[Setup]: %s" % self._test_name self.cfg = self.config.read(cfg_file, 'gota') self.gota = gotaImpl(self.cfg) self.system = SystemImpl(self.cfg) self.apk = ApkInstallUninstallImpl(self.cfg) self.ssid = self.config.read(cfg_file,'wifisetting').get("ssid") self.passwd = self.config.read(cfg_file,'wifisetting').get("passwd") self.d = g_common_obj.get_device() self.locator = ApkInstallUninstallImpl.Locator(self.d) self.serial = g_common_obj2.getSerialNumber() self.api = ApiImpl() self.remote = Remote()
def testFactoryResetSupport(self): """ verify that able to factory reset device successfully :return: None """ 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() assert self.api.check_ui_exists("resourceId", "com.google.android.setupwizard:id/welcome_title"), \ "fail to detect welcome title in setup wizard" # try to skip setup wizard by click four corner for i in range(5): self.api.d.wakeup() x = self.api.d.info['displayWidth'] y = self.api.d.info['displayHeight'] self.api.click_with_timeout("text", "Allow") if self.api.check_ui_exists("text", "GOT IT"): self.api.click_with_timeout("text", "GOT IT") break self.api.d.click(50, 50) self.api.d.click(x - 50, 50) self.api.d.click(x - 50, y - 50) self.api.d.click(50, y - 50) time.sleep(5) self.api.keep_awake()
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 testCreateWorkProfile_Remove_50_times(self): """ create and delete work profile for 50 times :return: None """ self.api.api_demo_launch() if self.api.check_ui_exists("textContains", "Device Owner", 5): self.api.click_with_timeout("resourceId", self.api.ui.device_provision) self.api.click_with_timeout("resourceId", self.api.ui.clear_device_owner_app) self.api.click_with_timeout("text", "Yes") 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) g_common_obj.set_vertical_screen() self.api.unlock_screen() for _ in range(50): if not self.api.locate_apps("Work Sample MDM"): self.api.setup_managed_profile(True) # time.sleep(5) # self.api.settings_sub_launch("Accounts") # assert self.api.check_ui_exists("text", "Accounts"), # "fail to launch settings at {0}".format(_) # assert self.api.check_ui_exists("text", "Work"), # "fail to detect work section in accounts at {0}".format(_) assert self.api.is_work_profile_enabled( ), "fail to detect work section in accounts at {0}".format(_) self.api.click_with_timeout("text", "Remove work profile") self.api.d.wait.update(timeout=3000) self.api.click_with_timeout("text", "Delete") self.api.d.wait.update(timeout=3000) assert self.api.check_ui_exists("text", "Accounts"), \ "fail to detect accounts after remove work profile at {0}".format(_) assert not self.api.check_ui_exists("text", "Work"), \ "fail to detect work section in accounts at {0}".format(_) self.api.clean_tasks()
def testDiskEncryptionStatus(self): """ verify the encryption status of device :return: """ ret = os.popen("adb -s {0} shell getprop ro.crypto.state".format(self.api.serial)).read().strip() if ret != 'encrypted': try: self.api.keep_awake() self.api.launch_app_by_intents("android.settings.SECURITY_SETTINGS", False) assert self.api.check_ui_exists("text", "Encryption", 5), "Fail to detect Encryption option" if not self.api.check_ui_exists("text", "Encrypted", 5): if self.api.check_ui_exists("text", "Encrypt phone"): self.api.click_with_timeout("text", "Encrypt phone") else: self.api.click_with_timeout("text", "Encrypt tablet") assert not self.api.check_ui_exists("resourceId", "com.android.settings:id/warning_low_charge"), \ "fail to encrypt device due to low battery" assert not self.api.check_ui_exists("resourceId", "com.android.settings:id/warning_unplugged"), \ "fail to encrypt due to need to replug in charger" self.api.click_with_timeout("resourceId", "com.android.settings:id/initiate_encrypt") self.api.click_with_timeout("resourceId", "com.android.settings:id/execute_encrypt") for _ in range(3): self.api.d.server.stop() finally: time.sleep(600) self.api = ApiImpl() g_common_obj2.system_reboot(90) for i in range(30): 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) or \ self.api.check_ui_exists("resourceId", "com.google.android.setupwizard:id/welcome_title"): break time.sleep(10) g_common_obj.set_vertical_screen() self.api.unlock_screen() ret = os.popen("adb -s {0} shell getprop ro.crypto.state".format(self.api.serial)).read().strip() assert ret == 'encrypted', "fail to encrypt device"
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 GMSBehavior(UIATestBase): """ @summary: test cases for GMSBehavior """ 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_Add(self): """ verify that able to add google account in device 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.settings_sub_launch("Accounts") if self.api.check_ui_exists("text", "Google"): 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, False) 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_Remove(self): """ verify that able to remove google account in device 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, False) 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 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 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)
def setUp(self): super(Settings, self).setUp() self._test_name = __name__ self.api = ApiImpl() self.api.unlock_screen() print "[Setup]: %s" % self._test_name
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)
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()
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"