Ejemplo n.º 1
0
class ConfigGoogleAccount(UIATestBase):
    def setUp(self):
        self._test_name = __name__
        print
        print "[Setup]: %s" % self._test_name
        cfg_file = 'tests.tablet.dut_init.conf'
        self.username = self.config.read(cfg_file,
                                         'google_account').get("user_name")
        self.passwd = self.config.read(cfg_file,
                                       'google_account').get("password")
        self.retry_num = self.config.read(
            cfg_file, 'init_list').get("configure_google_account")
        self.retry_num = int(self.retry_num)
        self.d = g_common_obj.get_device()
        self.func = Function()

    def tearDown(self):
        print "[Teardown]: %s" % self._test_name

    def testConfigGoogleAccount(self):
        """
        Configure google account
        """
        print "[RunTest]: %s" % self.__str__()

        self.d.wakeup()
        if self.d(resourceId="com.android.systemui:id/lock_icon"):
            self.func.close_lock_screen()

        succeed = False
        for i in range(self.retry_num):
            try:
                android_version_release = g_common_obj.adb_cmd_capture_msg(
                    "getprop |grep 'version.release'").split(':')[-1].strip()
                if (android_version_release
                        == '[8.0.0]') or (android_version_release
                                          == '[8.1.0]'):
                    self.func.add_google_account_mr1(self.username,
                                                     self.passwd)
                succeed = True
                break
            except Exception as e:
                print e
        assert succeed
Ejemplo n.º 2
0
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"