Example #1
0
class CheckBasicInfoBeforeGOTA(UIATestBase):
    """
    @summary: Test basic GOTA update
    """

    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 tearDown(self):
        print "[Teardown]: %s" % self._test_name
        super(CheckBasicInfoBeforeGOTA, self).tearDown()
        self.cfg = None

    def testCheckBasicInfoBeforeGOTA(self):
        """
        This test case is to test basic GOTA update function

        Test Case Precondition:
        set screen lock as none, and sleep time to be more than 10 minutes

        Test Case Step:
        1. test GOTA update

        Expect Result:
        1. DUT can GOTA update successfully

        The real implementation will be in SystemImpl class.
        """

        print "[RunTest]: %s" % self.__str__()

        base=self.cfg.get("base")
        target=self.cfg.get("target")
        base_build=self.cfg.get("base_build")
        gota_test_run_by_testplan = self.cfg.get("gota_test_run_by_testplan")
        self.gota.download_gota_content_artifactory('/GOTA/','gota.zip')
        print "finish download"
        base_bios=self.cfg.get("base_bios")
        host_file=self.cfg.get("host_file")
        client_file=self.cfg.get("client_file")
        base_fingerprint=self.cfg.get("base_fingerprint")
        google_account=self.cfg.get("google_account")
        google_password=self.cfg.get("google_password")
        apk_name=self.cfg.get("apk_name")
        apk_file=self.cfg.get("apk_file")
        apk_website=self.cfg.get("apk_website")
        host_mp3_file=self.cfg.get("host_mp3_file")
        client_mp3_file=self.cfg.get("client_mp3_file")
        sdcard_file = self.cfg.get("sdcard_file")
        oem_file = self.cfg.get("oem_file")
        timezone = self.cfg.get("timezone")

        g_common_obj.root_on_device()
        self.gota.mount_device()
        self.gota.unlock_screen()
        print "[INFO]connect wifi ....."
        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("shz13-otc-irda102","qweasdzxc")
        else:
            print "using config ap setting"
            self.gota.connect_AP(self.ssid,self.passwd)
        self.d.press.home()
        #add for file operation start
        exist = os.path.exists("/tmp/GOTA_test")
        if False == exist:
            os.mkdir("/tmp/GOTA_test")
        date = os.popen("date").read()
        filename=date.replace(" ","",6).strip('\n')
        gota_record="/tmp/GOTA_test/"+filename+".log"
        os.mknod(gota_record)
        fp=open(gota_record,'a')
        fp.write("latest GOTA test:"+gota_record+"\n")
        fp.close()
        self.gota.update_info(gota_record)
        self.gota.insert_info("GOTA status","before GOTA")

        #add for file operation end
        cache_before_gota=os.popen("adb -s %s shell df |grep -E '/cache '" %self.serial).read()
        fplist=cache_before_gota.split()
        cache_used=fplist[2].encode('utf-8')
        self.gota.insert_info("Cache patition used before GOTA",cache_used)
        data_before_gota=os.popen("adb -s %s shell df |grep -E '/data '" %self.serial).read()
        fplist=data_before_gota.split()
        data_used=fplist[2].encode('utf-8')
        self.gota.insert_info("Data patition used before GOTA",data_used)

        #1.check the bios version before gota
        BIOS_before_GOTA = os.popen("adb -s %s shell getprop ro.bootloader" %self.serial).read()
        BIOS_before_GOTA=BIOS_before_GOTA.replace("\n","",1)
        self.gota.insert_info("BIOS before GOTA",BIOS_before_GOTA)
        print "[INFO]: 1. check the bios version before gota is: %s" %BIOS_before_GOTA
        #2.push sample.txt file into dut before gota
        if host_file.count("http")!=0:
            file_path="/tmp/resource_ota"
            self.gota.file_download(host_file,file_path)
            host_file="%s/%s" %(file_path, host_file.split("/")[-1])
            print "[INFO]: The host file is: %s" %host_file
        self.system.adb_push_file(host_file, client_file)
        exist = self.system.file_exists(client_file, "DEVICE")
        print "[INFO]: 2. check the push file before gota is: %s" %client_file
        #3.check the fingerprint before gota
        Fingerprint_before_GOTA = os.popen("adb -s %s shell getprop ro.build.fingerprint" %self.serial).read()
        Fingerprint_before_GOTA=Fingerprint_before_GOTA.replace("\n","",1)
        self.gota.insert_info("Fingerprint before GOTA",Fingerprint_before_GOTA)
        print "[INFO]: 3. check the fingerprint before gota is: %s" %Fingerprint_before_GOTA
        #4.install apk before gota
        self.gota.unlock_screen()
        time.sleep(2)
        self.locator.btn_apps.click()
        print "*************************"
        print apk_name
        print "*************************"
        resource = "/tmp/resource_apk/" + apk_file
        if not self.apk.apk_check(apk_name):
            cmd = "adb -s %s install %s"%(self.serial, resource)
            print cmd
            pipe=os.popen(cmd).read()
            print pipe
        print "[INFO]: 4. check the installed apk before gota is: %s" %apk_name
        #5.push mp3 file into dut before gota
        if host_mp3_file.count("http")!=0:
            file_path="/tmp/resource_ota"
            self.gota.file_download(host_mp3_file,file_path)
            host_mp3_file="%s/%s" %(file_path, host_mp3_file.split("/")[-1])
            print "[INFO]: The host file is: %s" %host_mp3_file
        self.system.adb_push_file(host_mp3_file, client_mp3_file)
        assert self.system.file_exists(client_mp3_file, "DEVICE"), "[ERROR]: The client file %s does not exist" % client_mp3_file
        print "[INFO]: 5. check the mp3 before gota is: %s" %client_mp3_file
        self.system.adb_push_file(host_file, sdcard_file)
        exist=self.system.file_exists(sdcard_file, "DEVICE")
        print "[INFO]: 6. check the sdcard file before gota is: %s" %sdcard_file
        assert self.system.file_exists(oem_file, "DEVICE"), "[ERROR]: The oem file %s does not exist before gota" % oem_file
        print "[INFO]: 7. check the oem file before gota is: %s" %oem_file
        OStime_before_GOTA = os.popen("adb -s %s shell date +%%s" %self.serial).read()
        print ("%s" %OStime_before_GOTA )

        cmd="OStime_before_GOTA:"+OStime_before_GOTA
        OStime_before_GOTA=OStime_before_GOTA.replace("\n","",1)
        self.gota.insert_info("OStime before GOTA",OStime_before_GOTA)
        print "[haley]: 8. OStime_before_GOTA is: %s" % OStime_before_GOTA
        self.gota.unlock_screen()
        time.sleep(1)
        status=self.gota.check_encryption_status()
        print "[INFO]: 9. check encryption status before gota is: %s" %status
        self.gota.insert_info("Encryption status before GOTA",status)
        self.gota.update_info(gota_record)
        exist=self.system.file_exists(client_file, "DEVICE")
        print "[INFO]: 10. check the emmc push file before gota is: %s" %client_file
        if g_common_obj2.getAndroidVersion()=='L':
            mdm_apk = self.api.download_file_from_artifactory(self.remote.sample_mdm['sub_path'],self.remote.sample_mdm['name'])
        else:
            mdm_apk = self.api.download_file_from_artifactory(self.remote.sample_mdm['sub_path'],self.remote.sample_mdm['name_m'])    
        old_dir = os.getcwd()
        os.chdir(os.path.split(mdm_apk)[0])
        if g_common_obj2.getAndroidVersion()=='L':
            self.api.install_apps(self.remote.sample_mdm['pkg_name'],self.remote.sample_mdm['name'].split('.apk')[0])
        else:
            self.api.install_apps(self.remote.sample_mdm['pkg_name'],self.remote.sample_mdm['name_m'].split('.apk')[0])
        os.chdir(old_dir)
        self.gota.check_AFW_profile_work_before_GOTA()
        self.gota.check_AFW_data_in_managed_profile_before_GOTA()
        self.gota.check_AFW_data_in_personal_profile_before_GOTA()
        #self.gota.check_AFW_chrome_restriction_before_GOTA()
        print "[Info] --- Profile work Sample MDM is successful before gota"
Example #2
0
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()