コード例 #1
0
ファイル: ProfileOwner.py プロジェクト: zenghui0-0/tempfile
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(
                _)
コード例 #2
0
ファイル: NotProvision.py プロジェクト: zenghui0-0/tempfile
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"
コード例 #3
0
ファイル: ProfileOwner.py プロジェクト: zenghui0-0/tempfile
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()