Esempio n. 1
0
 def __init__(self, d):
     self.d = d
     self.report_data = {}
     self.report_data["build_number"] = adb.read_adb(
         "adb shell getprop ro.build.display.id")
     self.report_data["model_number"] = adb.read_adb(
         "adb shell getprop ro.product.model")
     self.report_data["android_version"] = adb.read_adb(
         "adb shell getprop ro.build.version.release")
Esempio n. 2
0
 def __init__(self, d):
     self.d = d
     self.camera = Camera(self.d)
     self.switchcamera = []
     self.camera_report_details = []
     self.path = image_comparison.get_path()
     self.facility = adb.read_adb("adb shell getprop ro.product.model")
 def acquire_facility(self):
     '''
     获取当前手机的国家版本
     :return: NCA:尼加拉瓜   KHM:柬埔寨
     '''
     versions = adb.read_adb('adb shell getprop ro.build.display.id')
     if 'KHM' in versions:
         return 'KHM'
     elif 'NCA' in versions:
         return 'NCA'
 def setup(self):
     self.facility = adb.read_adb(
         "adb shell getprop ro.product.model")  # 获取设备的版本号
     start_time = time.strftime("%Y-%m-%d %H:%M:%S",
                                time.localtime(time.time()))
     self.d.screen_on()
     if self.d(resourceId="com.android.systemui:id/emergency_call_button"):
         self.d.unlock()
     print('>>>>>>>>>>>>>>>>>>>>>>>>>>停止所有运行的app')
     self.d.app_stop_all()
     self.camera.CameraOff()
     self.camera.CameraOn()
     self.camera.Pop_Up()
     self.camera.PictureMode(facility=self.facility)
     time.sleep(5)
     print(start_time)
     return start_time
Esempio n. 5
0
 def Case_built_in_apk_versions(self):
     '''
     验证内置apk的版本是否正确
     :return:
     '''
     app_list = []
     result = 'pass'
     apk_versions = {}
     result_message = ''
     versions = adb.read_adb('adb shell getprop ro.build.display.id')
     if 'KHM' in versions:
         app_list = ['CooBill', 'CooTV', 'CamTalk', '酷管家']
     elif 'NCA' in versions:
         app_list = ['CooBill', 'CooTV', 'Mi CooTel', 'NicTalk', '酷管家']
     self.settings.stop()
     self.settings.start()
     while True:
         if self.settings.list_apps() == True:
             self.settings.click_operation_app()
             while True:
                 for i in app_list:
                     page_app_name = self.settings.acquire_page_app_name()
                     if i in page_app_name:
                         self.settings.click_app_name(i)
                         time.sleep(2)
                         versions = self.settings.acquire_app_versions()
                         print(i + '的版本信息为:' + versions)
                         apk_versions[i] = versions
                 slide_page = self.settings.slide_page()
                 if slide_page == True:
                     break
             if slide_page == True:
                 break
         else:
             self.d.swipe(0.275, 0.845, 0.377, 0.045)
     for dict_apk_name in apk_versions:
         if dict_apk_name in app_list:
             app_list.remove(dict_apk_name)
     if app_list != []:
         print('没有找到这个apk的版本信息', app_list)
         self.d.screenshot(self.path +
                           "apk_versions_img\\没有找到这个apk的版本信息.jpg")
         result = 'fail'
         result_message = '没有找到这个apk的版本信息', app_list
     self.settings.stop()
     return result, result_message, apk_versions
Esempio n. 6
0
 def Case_enter_camera(self):
     '''
     相机的切换前后摄拍照和摄像
     :return:
     '''
     result = 'pass'
     result_message = ''
     print('相机切换前后摄拍照,请手动查看')
     facility = adb.read_adb("adb shell getprop ro.product.model")
     self.camera.CameraOff()
     self.camera.CameraOn()
     self.camera.Pop_Up()
     self.camera.PictureMode(facility)
     if self.camera.Menu_picture() == False:
         self.d.screenshot(self.path + "camera_img\\进入相机模式出现异常.jpg")
         result = 'fail'
         result_message = result_message + '没有进入相机模式'
     else:
         self.camera.Photograph()
         time.sleep(2)
         self.camera.switch_camera()
         time.sleep(2)
         self.camera.Photograph()
     self.camera.VideoMode()
     if self.camera.Menu_video() == False:
         self.d.screenshot(self.path + "camera_img\\进入视频模式出现异常.jpg")
         result = 'fail'
         result_message = result_message + '没有进入视频模式'
     else:
         self.camera.Photograph()
         time.sleep(10)
         self.camera.Photograph()
         self.camera.switch_camera()
         time.sleep(3)
         self.camera.Photograph()
         time.sleep(10)
         self.camera.Photograph()
     self.camera.CameraOff()
     if self.camera.Menu() != False:
         self.d.screenshot(self.path + "camera_img\\退出相机模式出现异常.jpg")
         result = 'fail'
         result_message = result_message + '没有退出相机模式'
     self.camera.CameraOff()
     return result, result_message
Esempio n. 7
0
    def case3(self,num=201, ping_num=100):
        '''
        无线网络和移动网络中首选网络模式切换
        :param num: 不断切换网络的次数, 若执行50次,就填入51
        :return:
        '''
        self.setting.auto_connect_wifi()  # 自动连接wifi
        self.d.screen_on()
        result = "pass"
        result_data = "pass"
        err_wifi_count = 1
        err_data_count = 1

        for i in range(num):
            sleep(2)
            self.d.screen_on()
            if self.d(resourceId="com.android.settings:id/switch_text", text=u"开启").wait(timeout=3.0):
                print(">>>WIFI已开启")
                if self.d(resourceId="android:id/title")[0].wait(timeout=2):
                    print(">>>WIFI已开启时, 可正常搜索到WIFI")
                    print(self.d(resourceId="android:id/title")[0].get_text())
                    if self.d(resourceId="android:id/summary", text=u"已连接").wait(timeout=10.0):
                        self.d.screen_on()
                        wifi_name = self.d(resourceId="android:id/title")[0].get_text()
                        print(">>>WIFI已开启时,正常连接到WIFI:" + wifi_name)
                        adb_msg_wifi = adb.read_adb("adb shell ping -c "+str(ping_num)+" www.sina.com")
                        # print(adb_msg_wifi)
                        if "0% packet loss" in adb_msg_wifi or "1% packet loss" in adb_msg_wifi:
                            print("pass")
                        else:
                            print("WIFI存在丢包情况")
                            self.d.screen_on()
                            err_wifi_image = self.path + "image\\setting\\error无线网络和移动网络中首选网络模式切换WIFI存在丢包情况" + str(
                                err_wifi_count) + ".png"
                            self.d.screenshot(err_wifi_image)
                            self.log_data.append(err_wifi_image + "\n" + adb_msg_wifi)
                            err_wifi_count = err_wifi_count + 1
                            result = "fail"
                    else:
                        print("WIFI连接异常")
                        self.d.screen_on()
                        err_wifi_image = self.path + "image\\setting\\error无线网络和移动网络中首选网络模式切换WIFI连接异常" + str(
                            err_wifi_count) + ".png"
                        self.d.screenshot(err_wifi_image)
                        self.log_data.append(err_wifi_image + "\n")
                        err_wifi_count = err_wifi_count + 1
                        result = "fail"
                self.d.screen_on()
                if self.d(resourceId="com.android.systemui:id/emergency_call_button"):
                    self.d.unlock()
                    self.setting.start()
                    self.setting.list_wlan()
                self.setting.wlan_switch()
                self.d.press("back")
                self.d.screen_on()
            print("进入数据测试")
            for count in range(4):
                self.d.screen_on()
                if self.d(resourceId="com.android.systemui:id/emergency_call_button"):
                    self.d.unlock()
                apk = self.d.current_app()
                packageName = apk['package']
                if packageName != "com.android.phone":
                    self.setting.start()
                elif self.d(resourceId="com.android.settings:id/title", text=u"更多").wait(timeout=2) != True:
                    self.setting.start()
                self.setting.list_more()
                self.setting.more_mobile_network()
                # count = random.randint(0, 3)
                self.setting.more_mb_network_type()
                if count == 0:
                    data_type = "4G"
                elif count == 1:
                    data_type = "3G/2G"
                elif count == 2:
                    data_type = "2G"
                else:
                    data_type = "4G/3G/2G"
                if self.setting.more_mb_network_type_cut(data_type):
                    print("网络切换成功,等待10秒")
                    sleep(10)
                    adb_msg_data = adb.read_adb("adb shell ping -c " + str(ping_num) + " www.sina.com")
                    print(adb_msg_data)
                    if "unknown host www.sina.com" in adb_msg_data:
                        print("数据连接异常")
                        err_data_image = self.path + "image\\setting\\error无线网络和移动网络中首选网络模式切换数据连接异常" + str(
                            err_data_count) + ".png"
                        self.d.screenshot(err_data_image)
                        self.log_data.append(err_data_image + "\t " + data_type + "\n" + adb_msg_data)
                        err_data_count = err_data_count + 1
                        result_data = ""
                        result = "fail"
                        continue
                    elif "0% packet loss" in adb_msg_data or "1% packet loss" in adb_msg_data:
                        print(result_data)
                    else:
                        result_data = "fail"
                        print(result_data)

                    if result_data == "fail":
                        print("首选网络类型为:" + data_type + "时;数据存在丢包情况")
                        self.d.screen_on()
                        err_data_image = self.path + "image\\setting\\error无线网络和移动网络中首选网络模式切换数据存在丢包情况" + str(
                            err_data_count) + ".png"
                        self.d.screenshot(err_data_image)
                        self.log_data.append(err_data_image + "\n 连接方式为:" + data_type + "\n" + adb_msg_data)
                        err_wifi_count = err_data_count + 1
                        result = "fail"
                        result_data = "pass"
                else:
                    print("ERROR 切换 首选网络类型 失败,请检查是否插入sim卡")
                    self.d.screen_on()
                    err_data_image = self.path + "image\\setting\\error无线网络和移动网络中首选网络模式切换数据首选网络类型切换失败" + str(
                        err_data_count) + ".png"
                    self.d.screenshot(err_data_image)
                    self.log_data.append(err_data_image + "\n")
                    err_wifi_count = err_data_count + 1
                    result = "fail"
                    result_data = "pass"
                    break
            self.d.screen_on()
            if self.d(resourceId="com.android.systemui:id/emergency_call_button"):
                self.d.unlock()
            self.setting.start()
            self.setting.list_wlan()
            self.setting.wlan_switch()

        return result
Esempio n. 8
0
    def case2(self, num=201, ping_num=100):
        '''
        不断从数据连接与WIFI之前切换,检查是否会出现无法切换,无法上网等现象(默认已插入sim卡)
        :param num: 不断切换网络的次数, 若执行50次,就填入51
        :return:
        '''
        self.d.screen_on()
        self.setting.auto_connect_wifi()   # 自动连接wifi
        err_wifi_count = 1
        err_data_count = 1
        result = "pass"
        for i in range(num):
            sleep(2)
            self.d.screen_on()
            if self.d(resourceId="com.android.settings:id/switch_text", text=u"开启").wait(timeout=2.0):
                if self.d(resourceId="android:id/title")[0].get_text() != '':
                    print(">>>WIFI已开启时, 可正常搜索到WIFI")
                    print(self.d(resourceId="android:id/title")[0].get_text())
                    if self.d(resourceId="android:id/summary", text=u"已连接").wait(timeout=2.0):
                        wifi_name = self.d(resourceId="android:id/title")[0].get_text()
                        print(">>>WIFI已开启时,正常连接到WIFI:" + wifi_name)
                        adb_msg_wifi = adb.read_adb("adb shell ping -c "+str(ping_num)+" www.baidu.com")
                        print(adb_msg_wifi)
                        if "0% packet loss" in adb_msg_wifi or "1% packet loss" in adb_msg_wifi:
                            print("pass")
                        else :
                            print("WIFI存在丢包情况")
                            self.d.screen_on()
                            err_wifi_image = self.path + "image\\setting\\error不断从数据连接与WIFI之前切换WIFI存在丢包情况" + str(err_wifi_count) + ".png"
                            self.d.screenshot(err_wifi_image)
                            self.log_data.append(err_wifi_image + "\n" + adb_msg_wifi)
                            err_wifi_count = err_wifi_count+1
                            result = "fail"
                    else :
                        print("WIFI连接异常")

                        err_wifi_image = self.path + "image\\setting\\error不断从数据连接与WIFI之前切换WIFI连接异常" + str(err_wifi_count) + ".png"
                        self.d.screenshot(err_wifi_image)
                        self.log_data.append(err_wifi_image + "\n")
                        err_wifi_count = err_wifi_count + 1
                        self.setting.wlan_switch()
                        self.d.screen_on()
                        result = "fail"
                        continue
            else :
                self.d.screen_on()
                adb_msg_data = adb.read_adb("adb shell ping -c "+str(ping_num)+" www.baidu.com")
                print(adb_msg_data)
                if "0% packet loss" in adb_msg_data or "1% packet loss" in adb_msg_data:
                    print("pass")
                elif "unknown host www.baidu.com" in adb_msg_data :
                    print("数据连接异常")
                    err_data_image = self.path + "image\\setting\\error不断从数据连接与WIFI之前切换数据连接异常" + str(
                        err_data_count) + ".png"
                    self.d.screenshot(err_data_image)
                    self.log_data.append(err_data_image + "\n" + adb_msg_data)
                    err_data_count = err_data_count + 1
                    result = "fail"
                else:
                    print("数据存在丢包情况")
                    err_data_image = self.path + "image\\setting\\error不断从数据连接与WIFI之前切换数据存在丢包情况"+str(err_data_count)+".png"
                    self.d.screenshot(err_data_image)
                    self.log_data.append(err_data_image + "\n" + adb_msg_data)
                    err_data_count = err_data_count + 1
                    result = "fail"
            self.d.screen_on()
            if self.d(resourceId="com.android.systemui:id/emergency_call_button"):
                self.d.unlock()
            apk = self.d.current_app()
            packageName = apk['package']
            if packageName != "com.android.settings":
                self.setting.start()
                self.setting.list_wlan()
            self.setting.wlan_switch()
        return result
Esempio n. 9
0
    def Case_SD_update(self):
        result='pass'
        result_message=''
        print('---------->请将升级包放到指定的目录;\n请保证目录只有一个升级包;\n尼加拉瓜版本升级目录:NCA_update;\n柬埔寨版本升级目录:KHM_update;')
        if adb.acquire_battery_message(self.path)>31:
            versions = adb.read_adb('adb shell getprop ro.build.display.id')
            update_file = ""
            if 'KHM' in versions:
                files = os.listdir(self.path + 'update_file\\KHM_update')
                if files == []:
                    print('没有升级包不执行升级')
            elif 'NCA' in versions:
                files = os.listdir(self.path+'update_file\\NCA_update')
                if files==[]:
                    print('没有升级包不执行升级')
            print("\n\n####################\n请在10分钟内,在"+self.path+"update_file\ 路径下根据版本放入指定目录\n请保证目录只有一个升级包;\n尼加拉瓜版本升级文件夹:NCA_update;\n柬埔寨版本升级文件夹:KHM_update;\n\n")
            time.sleep(60*10)
            self.message.start_message()
            message_num = self.message.message_num()
            self.message.stop_message()
            if 'KHM' in versions:
                files = os.listdir(self.path + 'update_file\\KHM_update')
                if files==[]:
                    print('没有找到升级包,升级失败')
                else:
                    self.camtalk.add_linkman()
                    for i in files:
                        print(i)
                        update_file=i
                        adb.read_adb('adb push '+self.path+'update_file\\KHM_update\\'+i+' /sdcard/')
                        os.remove(self.path+'update_file\\KHM_update\\'+i)
                    self.settings.enter_about_phone()
                    self.settings.click_system_upgrade()
                    self.settings.click_system_update_set()
                    if self.settings.click_SD_update()==True:
                        self.settings.click_install()
                        time.sleep(400)
                        self.d = u2.connect()
                        self.__init__(self.d)
                        for i in range(0, 10):
                            if adb.detection_terminal_connect() == True:
                                break
                            else:
                                time.sleep(20)
                        self.d.screen_on()
                        if self.camtalk.verification_add_linkman()==False:
                            result='fail'
                            result_message = result_message + '验证联系人失败\n'
                        self.message.start_message()
                        message_num1 = self.message.message_num()
                        self.message.stop_message()
                        if message_num!=message_num1:
                            result = 'fail'
                            result_message = result_message + '验证短信数量失败\n'

                    else:
                        self.settings.click_folder()
                        self.settings.select_updete_file(update_file)
                        self.settings.click_install()
                        time.sleep(400)
                        self.d = u2.connect()
                        self.__init__(self.d)
                        for i in range(0,10):
                            if adb.detection_terminal_connect()==True:
                                break
                            else:
                                time.sleep(20)
                        self.d.screen_on()
                        if self.camtalk.verification_add_linkman()==False:
                            result='fail'
                            result_message=result_message+'验证联系人失败\n'
                        self.message.start_message()
                        message_num1 = self.message.message_num()
                        self.message.stop_message()
                        if message_num!=message_num1:
                            result = 'fail'
                            result_message = result_message + '验证短信数量失败\n'
            elif 'NCA' in versions:
                files = os.listdir(self.path+'update_file\\NCA_update')
                if files==[]:
                    print('没有找到升级包,升级失败')
                else:
                    self.nictalk.add_linkman()
                    for i in files:
                        adb.read_adb('adb push '+self.path+'update_file\\NCA_update\\'+i+' /sdcard/')
                        os.remove(self.path + 'update_file\\NCA_update\\' + i)
                    self.settings.enter_about_phone()
                    self.settings.click_system_upgrade()
                    self.settings.click_system_update_set()
                    if self.settings.click_SD_update()==True:
                        self.settings.click_install()
                        time.sleep(400)
                        self.d = u2.connect()
                        self.__init__(self.d)
                        for i in range(0,10):
                            if adb.detection_terminal_connect()==True:
                                break
                            else:
                                time.sleep(20)
                        self.d.screen_on()
                        if self.nictalk.verification_add_linkman()==False:
                            result = 'fail'
                            result_message = result_message + '验证联系人失败\n'
                        self.message.start_message()
                        message_num1 = self.message.message_num()
                        self.message.stop_message()
                        if message_num!=message_num1:
                            result = 'fail'
                            result_message = result_message + '验证短信数量失败\n'
                    else:
                        self.settings.click_folder()
                        self.settings.select_updete_file(update_file)
                        self.settings.click_install()
                        time.sleep(400)
                        self.d = u2.connect()
                        self.__init__(self.d)
                        for i in range(0,10):
                            if adb.detection_terminal_connect()==True:
                                break
                            else:
                                time.sleep(20)
                        self.d.screen_on()
                        if self.nictalk.verification_add_linkman()==False:
                            result = 'fail'
                            result_message = result_message + '验证联系人失败\n'
                        self.message.start_message()
                        message_num1 = self.message.message_num()
                        self.message.stop_message()
                        if message_num!=message_num1:
                            result = 'fail'
                            result_message = result_message + '验证短信数量失败\n'
        else:
            print('当前手机电量无法完成升级')
        return result,result_message
Esempio n. 10
0
    def Case_recover_factory(self):
        result = 'pass'
        result_message = ''
        self.settings.recover_factory_set()
        print("\n\n已进行恢复出厂设置,请在手机重启成功后手动选择与电脑的连接\n\n")
        time.sleep(60*5)
        for i in range(0, 20):
            if adb.detection_terminal_connect() == True:
                break
            else:
                time.sleep(30)
        time.sleep(20)
        print("\n\n开始执行安装uiautomator,请手动勾选允许安装\n\n")
        self.init_operation.init_equipment()
        time.sleep(50)
        self.d=u2.connect()
        self.__init__(self.d)

        versions = adb.read_adb('adb shell getprop ro.build.display.id')
        if 'KHM' in versions:
            if self.settings.change_language()=='柬埔寨':
                print('---------->恢复出厂设置语言恢复正确')
            else:
                result='fail'
                print('---------->恢复出厂设置,语言没有正确恢复')
                result_message=result_message+'语言没有恢复出厂设置\n'
            self.settings.display_setting()
            self.settings.auto_connect_wifi()
            if self.camtalk.assert_login() == True:
                if  '柬埔寨' in self.camtalk.acquire_state_name():
                    print('---------->talk恢复出厂设置正确')
                else:
                    result = 'fail'
                    print('---------->talk恢复出厂设置国家显示错误')
                    result_message = result_message + 'talk恢复出厂设置国家显示错误\n'
            else:
                result = 'fail'
                print('---------->talk没有进入登录界面')
                result_message = result_message + 'talk没有进入登录界面\n'
            self.chrome.start()
            if self.chrome.KHM_assert_browse_history() == True:
                print('---------->浏览器没有访问记录,恢复出厂设置正常')
            else:
                result = 'fail'
                print('---------->浏览器还有访问记录,恢复出厂设置失败')
                result_message = result_message + '浏览器还有访问记录,恢复出厂设置失败\n'
        elif 'NCA' in versions:
            if self.settings.change_language() == '尼加拉瓜':
                print('---------->恢复出厂设置语言恢复正确')
            else:
                result='fail'
                print('---------->恢复出厂设置,语言没有正确恢复')
                result_message = result_message + '恢复出厂设置,语言没有正确恢复\n'
            self.settings.display_setting()
            self.settings.auto_connect_wifi()
            if self.nictalk.assert_login() == True:
                if  '尼加拉瓜' in self.nictalk.acquire_state_name():
                    print('---------->talk恢复出厂设置正确')
                else:
                    result = 'fail'
                    print('---------->talk恢复出厂设置国家显示错误')
                    result_message = result_message + 'talk恢复出厂设置国家显示错误\n'
            else:
                result = 'fail'
                print('---------->talk没有进入登录界面')
                result_message = result_message + 'talk没有进入登录界面'
            if self.chrome.KHM_assert_browse_history() == True:
                print('---------->浏览器没有访问记录,恢复出厂设置正常')
            else:
                result = 'fail'
                print('---------->浏览器还有访问记录,恢复出厂设置失败')
                result_message = result_message + '浏览器还有访问记录,恢复出厂设置失败\n'
        self.message.start_message()
        if self.message.message_num()==0:
            print('短信成功恢复出厂设置')
        else:
            result = 'fail'
            print('短信没有恢复出厂设置')
            result_message = result_message + '短信没有恢复出厂设置\n'
        self.camera.CameraOn()
        if self.camera.Pop_Up()==False:
            result='fail'
            print('---------->相机没有恢复出厂设置')
            result_message=result_message+'相机没有恢复出厂设置\n'
        else:
            print('相机恢复出厂设置正常')
        self.music.start()
        if self.music.acquire_music_list()==True:
            result = 'fail'
            print('---------->音乐没有恢复出厂设置')
            result_message = result_message + '音乐没有恢复出厂设置\n'
        else:
            print('音乐恢复出厂设置正常')
        return result,result_message
Esempio n. 11
0
    def data_connection(self):
        actual_result = ""
        result = "pass"
        chrome = Chrome(self.d)
        self.settings.close_wifi()
        for i in range(2):
            if self.settings.check_mcwill_data_switch():
                if self.settings.check_mcwill_data_status():
                    self.d.press("home")
                    chrome.start()
                    if chrome.check_open_baidu() == False:
                        err_msg = "McWill数据已连接时打开百度失败"
                        print(err_msg)
                        actual_result = actual_result + "\n" + err_msg
                        result = "fail"
                        err_screenshot = self.path + "data_connection\\" + err_msg + ".png"
                        self.d.screenshot(err_screenshot)
                    else:
                        print("McWill数据已连接时打开百度成功")
                    break
                else:
                    err_msg = "McWill数据状态为未连接"
                    print(err_msg)
                    actual_result = actual_result + "\n" + err_msg
                    result = "fail"
                    err_screenshot = self.path + "data_connection\\" + err_msg + ".png"
                    self.d.screenshot(err_screenshot)
                    break
            else:
                result = "fail"
                err_msg = "默认McWill数据为关闭状态"
                actual_result = actual_result + "\n" + err_msg
                err_screenshot = self.path + "data_connection\\" + err_msg + ".png"
                self.d.screenshot(err_screenshot)
                print(err_msg)
                self.settings.cut_mcwill_data_switch()
        self.d.press("home")

        # 关闭McWill,使用默认网络类型访问网络
        self.settings.cut_mcwill_data_switch("off")
        network_type = self.settings.cut_simcard_network_type("get")
        if "4G/3G/2G" in network_type:
            pass
        else:
            result = "fail"
            err_msg = "默认首选网络类型错误"
            actual_result = actual_result + "\n" + err_msg
            err_screenshot = self.path + "data_connection\\" + err_msg + ".png"
            self.d.screenshot(err_screenshot)
            print(err_msg)
            self.settings.cut_simcard_network_type("4G/3G/2G")
        self.d.press("home")
        chrome.start()
        if chrome.check_open_baidu() == False:
            err_msg = "默认网络模式时打开百度失败"
            print(err_msg)
            actual_result = actual_result + "\n" + err_msg
            result = "fail"
            err_screenshot = self.path + "data_connection\\" + err_msg + ".png"
            self.d.screenshot(err_screenshot)
        else:
            print(network_type + "网络模式时打开百度成功")

        # 切换网络类型访问网络
        network_type = ["4G", "3G/2G", "2G"]
        for i in network_type:
            self.settings.cut_simcard_network_type(i)
            self.d.press("home")
            chrome.start()
            if i == "2G":
                adb_msg = adb.read_adb("adb shell ping -c 100 www.baidu.com")
                print(adb_msg)
                if "0%" in adb_msg or "1%" in adb_msg or "2%" in adb_msg or "3%" in adb_msg or "4%" in adb_msg or "5%" in adb_msg:
                    print("pass")
                elif "unknown host" in adb_msg:
                    result = "fail"
                    err_msg = "网络模式2G时连接异常"
                    print(err_msg)
                    actual_result = actual_result + "\n" + err_msg
                else:
                    result = "fail"
                    err_msg = "网络模式2G时存在丢包的现象"
                    print(err_msg)
                    actual_result = actual_result + "\n" + err_msg
            else:
                if chrome.check_open_baidu() == False:
                    if i == "3G/2G":
                        i = "3G2G"
                    err_msg = i + "网络模式时打开百度失败"
                    print(err_msg)
                    actual_result = actual_result + "\n" + err_msg
                    result = "fail"
                    err_screenshot = self.path + "data_connection\\" + err_msg + ".png"
                    self.d.screenshot(err_screenshot)
                else:
                    print(i + "网络模式时打开百度成功")

        # 测试完毕,将设置恢复到初始
        self.settings.cut_mcwill_data_switch()
        self.settings.cut_simcard_network_type("4G/3G/2G")
        self.d.press("home")
        return actual_result, result
Esempio n. 12
0
 def Case_start_built_in_apk(self):
     '''
     开启所有内置app
     :return:
     '''
     num = 0
     result = 'pass'
     result_message = ''
     built_in_apk_list = []
     #获取内置的apk信息
     apk = self.d.adb_shell('pm list packages -s ')
     #将内置apk信息写入文件
     with open(self.path + 'log_message\\adb_instruct.txt', 'w') as f:
         f.write(apk)
     # 将内置apk信息读出处理换行符处理:'package:'
     #将处理后的信息加入list
     with open(self.path + 'log_message\\adb_instruct.txt', 'r') as f:
         for j in f.readlines():
             i = j.strip('\n')
             built_in_apk_list.append(i.replace("package:", ''))
     #获取预期的apk信息
     apk_dict = self.KHM_apk_dict()
     #获取当前连接手机的版本信息
     versions = adb.read_adb('adb shell getprop ro.build.display.id')
     if 'KHM' in versions:
         apk_dict = self.KHM_apk_dict()
     elif 'NCA' in versions:
         apk_dict = self.NCA_apk_dict()
     #循环遍历出
     for apk_name in apk_dict:
         print('%s---------->正在执行' % num + apk_name)
         if apk_dict[apk_name][0] in built_in_apk_list:
             print('---------->这是一个内置apk')
             print('---------->开启' + apk_name)
             self.d.app_start(pkg_name=apk_dict[apk_name][0],
                              activity=apk_dict[apk_name][1])
             time.sleep(3)
             print('---------->开始截图')
             self.d.screenshot(self.path + 'built_in_apk_img\\开启' +
                               apk_name + '的截图.jpg')
             time.sleep(3)
             print('---------->停止apk')
             if apk_name == '酷管家':
                 self.d.press("home")
                 continue
             elif apk_name == 'cooTv':
                 self.d.press("back")
                 if self.d(resourceId="android:id/message").wait(timeout=3):
                     self.d(resourceId="android:id/button1").click()
             self.d.app_stop(pkg_name=apk_dict[apk_name][0])
             now_start_apk = self.d.current_app()
             if now_start_apk['package'] == apk_dict[apk_name][0]:
                 print('---------->没有退出apk')
                 self.d.screenshot(self.path + 'built_in_apk_img\\没有退出' +
                                   apk_name + 'apk.jpg')
                 result = 'fail'
                 result_message = result_message + '退出' + apk_name + '失败'
                 self.d.press("home")
             time.sleep(3)
             print('---------->开始截图')
             self.d.screenshot(self.path + 'built_in_apk_img\\关闭' +
                               apk_name + '的截图.jpg')
             time.sleep(3)
         else:
             print('---------->这不是一个内置apk')
             result = 'fail'
             result_message = result_message + '这不是一个内置apk\n开启apk的截图目录为:' + self.path + 'built_in_apk_img'
         num += 1
     return result, result_message