def enter_chrome(self): ''' 一次浏览器主页检查 (google) 共检测两次,首次检测通过,截图名为:《一次浏览器主页检查.png》,新增窗口检测通过,截图名为:《一次浏览器主页检查,新增一个新的窗口.png》; 若检测失败,则截图名为:《一次浏览器主页检查,出现异常.jpg》 :return:result为pass 即为通过 ''' actual_result = "" result = "pass" chrome = Chrome(self.d) chrome.start() for i in range(2): if chrome.check_home(): if i == 0: name = "一次浏览器主页检查" else: name = "一次浏览器主页检查,新增一个新的窗口" img_name = self.path + "chrome\\" + name + ".jpg" self.d.screenshot(img_name) chrome_img = self.path + "picture\\chrome.jpg" if image_comparison.compare_image_with_histogram( chrome_img, img_name): pass else: err_msg = name + ":可正常检测到元素,但页面显示与期望不完全一致" print(err_msg) actual_result = actual_result + "\n" + err_msg result = "fail" break else: result = "fail" err_msg = "一次浏览器主页检查,出现异常" img_name = self.path + "chrome\\" + err_msg + ".jpg" self.d.screenshot(img_name) actual_result = actual_result + "\n" + err_msg print(">>>>>>>>>>>> 新增一个新的窗口,检测是否正常") chrome.window_add() chrome.stop() return actual_result, result
class Update(): def __init__(self,d): self.d=d self.chrome=Chrome(d) self.music=Music(d) self.init_operation=Init_Operation() self.nictalk = NicTalk(self.d) self.camtalk = CamTalk(self.d) self.qq=Tx_QQ(self.d) self.clock=Clock(self.d) self.camera=Camera(self.d) self.settings = Settings(self.d) self.message=Message1(self.d) self.path = os.path.abspath(os.path.join(os.getcwd(), "../..")) + "\\enter_resource\\" self.init_operation=Init_Operation() def set_up(self, test_time='1'): 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.settings.display_setting() self.settings.auto_connect_wifi() self.d.press("home") print("开始测试:" + test_time) print(start_time) return start_time 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 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 def teardown(self): end_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())) return end_time def run(self): self.update_report = [] start_time1 = self.set_up(test_time='开始测试:一次SD卡升级') actul_reselt = '' path = '' try: result1, result_message1 = self.Case_SD_update() except BaseException as e: result1 = 'Fail' print("except:", e) actul_reselt = str(e)[7:] result_message1 = '一次SD卡升级出现异常' print( "=====>>>>>执行测试:一次SD卡升级出现异常<<<<<=====") self.d.screen_on() # 判断是否锁屏状态 if self.d(resourceId="com.android.systemui:id/emergency_call_button"): self.d.unlock() path = self.path + 'built_in_apk_img\\' + "一次SD卡升级出现异常.jpg" self.d.screenshot(path) self.d.app_stop_all() end_time1 = self.teardown() self.update_report.append( {"t_module": "B34:SD卡升级", "t_case": "入口测试","t_steps": "一次SD卡升级", "t_expected_result": "1.手机能过SD卡正确升级,检查联系人和短信是否丢失", "t_actual_result": actul_reselt + '\n' + path + '\n' + result_message1, "t_start_time": start_time1, "t_end_time": end_time1, "t_reference_result": result1, "t_result": ""}) time.sleep(5) start_time2 = self.set_up(test_time='入口测试完成后恢复出厂设置') actul_reselt = '' path = '' try: result2, result_message2 = self.Case_recover_factory() except BaseException as e: result2 = 'Fail' print("except:", e) actul_reselt = str(e)[7:] result_message2 = '入口测试完成后恢复出厂设置' print( "=====>>>>>执行测试:入口测试完成后恢复出厂设置,出现异常<<<<<=====") self.d.screen_on() # 判断是否锁屏状态 if self.d(resourceId="com.android.systemui:id/emergency_call_button"): self.d.unlock() path = self.path + 'built_in_apk_img\\' + "入口测试完成后恢复出厂设置出现异常.jpg" self.d.screenshot(path) self.d.app_stop_all() end_time2 = self.teardown() self.update_report.append( {"t_module": "B38恢复出厂设置", "t_case": "入口测试", "t_steps": "入口测试完成后恢复出厂设置", "t_expected_result": "1.系统还原为默认状况,语音,设置等信息都为默认,之前操作记录和保存信息都被删除,无网页浏览痕迹,通话记录,拍摄相片,录音文件等", "t_actual_result": actul_reselt + '\n' + path + '\n' + result_message2, "t_start_time": start_time2, "t_end_time": end_time2, "t_reference_result": result2, "t_result": ""}) time.sleep(5) return self.update_report
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
class Ts_Chrome(): def __init__(self, d): self.d = d self.chrome = Chrome(self.d) self.path = image_comparison.get_path() self.log_data = [] self.chrome_report_details = [] def set_up(self, casename): print(casename) self.d.screen_on() # 判断是否锁屏状态 if self.d(resourceId="com.android.systemui:id/emergency_call_button"): self.d.unlock() # 停止并启动设置 self.chrome.stop() self.d.app_stop_all() self.chrome.start() # 获取设置的内存、cpu等信息 adb.get_meminfo(self.d) adb.get_battery(self.d) adb.get_cpuinfo(self.d) # 获取当前时间,并保存测试开始前的截图 nowTime = datetime.datetime.now().strftime('%Y-%m-%d') # 现在 time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') self.d.screenshot(self.path + "image\\chrome\\" + casename + nowTime + ".jpg") return time def case1(self, window=100, num=30): ''' 多次切换浏览器中的窗口,打开window个窗口;切换num次窗口,并打开sina.com 网页 ''' result = "pass" for i in range(window): print(">>Chrome窗口界面:第" + str(i) + "次添加窗口") self.d.screen_on() # 判断是否锁屏状态 if self.d( resourceId="com.android.systemui:id/emergency_call_button" ): self.d.unlock() self.chrome.switcher_window() self.chrome.window_add() for i in range(num): self.chrome.connect_url("www.sina.com.cn") self.chrome.swipe_window() return result def case2(self, window=100, url=[ "www.baidu.com", "www.sina.com.cn", "www.iqiyi.com", "news.qq.com", "m.qidian.com" ]): ''' 后台播放音乐,挂QQ进入网页,反复退出进入网络,检查是否会出现异 ''' music = Music(self.d) qq = Tx_QQ(self.d) browser_uc = Browser_UC(self.d) qq.login_qq() music.start_background_play() result = "pass" self.chrome.start() for i in range(window): self.d.screen_on() # 判断是否锁屏状态 if self.d( resourceId="com.android.systemui:id/emergency_call_button" ): self.d.unlock() num = random.randint(0, 3) if num == 0: self.chrome.switcher_window() self.chrome.window_add() elif num == 1: url_num = random.randint(0, len(url) - 1) self.chrome.connect_url(url[url_num]) elif num == 2: self.chrome.swipe_window() elif num == 3: try: browser_uc.open_browser() except BaseException as e: print("第三方app出现异常:", e) self.d.app_stop_all() self.chrome.start() return result def tear_down(self, casename): self.d.screen_on() nowTime = datetime.datetime.now().strftime('%Y-%m-%d') # 现在 time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') self.d.screenshot(self.path + "image\\chrome\\" + casename + nowTime + ".jpg") adb.get_meminfo(self.d) adb.get_battery(self.d) adb.get_cpuinfo(self.d) self.chrome.stop() print(casename) return time def run(self): window = 100 actual_result = "" err_path = "" starttime1 = self.set_up("开始测试:Chrome切换" + str(window) + "次浏览器中的窗口") try: t_reference_result1 = self.case1() except BaseException as e: t_reference_result1 = "fail" print("except:", e) actual_result = str(e)[7:] print("=====>>>>>执行测试:Chrome切换" + str(window) + "次浏览器中的窗口;出现异常<<<<<=====") self.d.screen_on() # 判断是否锁屏状态 if self.d( resourceId="com.android.systemui:id/emergency_call_button" ): self.d.unlock() err_path = self.path + "image\\chrome\\Chrome切换" + str( window) + "次浏览器中的窗口;出现异常.jpg" self.d.screenshot(err_path) self.chrome.stop() self.d.app_stop_all() endtime1 = self.tear_down("结束测试:Chrome切换" + str(window) + "次浏览器中的窗口") self.chrome_report_details.append({ "t_module": "Chrome", "t_case": "压力测试", "t_steps": "多次切换浏览器中的窗口", "t_expected_result": "每次均能成功切换,无异常发生", "t_actual_result": actual_result + "\n" + err_path, "t_start_time": starttime1, "t_end_time": endtime1, "t_reference_result": t_reference_result1, "t_result": "" }) sleep(2) actual_result = "" err_path = "" starttime2 = self.set_up("开始测试:后台播放音乐,挂QQ进入网页,反复退出进入网络" + str(window) + "次,检查是否会出现异常") try: t_reference_result2 = self.case2() except BaseException as e: t_reference_result2 = "c" print("except:", e) actual_result = str(e)[7:] print("=====>>>>>执行测试:后台播放音乐,挂QQ进入网页,反复退出进入网络" + str(window) + "次;出现异常<<<<<=====") self.d.screen_on() # 判断是否锁屏状态 if self.d( resourceId="com.android.systemui:id/emergency_call_button" ): self.d.unlock() err_path = self.path + "image\\chrome\\Chrome后台播放音乐,挂QQ进入网页,反复退出进入网络" + str( window) + "次;出现异常.jpg" self.d.screenshot(err_path) self.chrome.stop() self.d.app_stop_all() endtime2 = self.tear_down("结束测试:后台播放音乐,挂QQ进入网页,反复退出进入网络" + str(window) + "次,检查是否会出现异常") self.chrome_report_details.append({ "t_module": "Chrome", "t_case": "压力测试", "t_steps": "后台播放音乐,挂QQ进入网页,反复退出进入网络" + str(window) + "次", "t_expected_result": "检查是否会出现异常", "t_actual_result": actual_result + "\n" + err_path, "t_start_time": starttime2, "t_end_time": endtime2, "t_reference_result": t_reference_result2, "t_result": "" }) return self.chrome_report_details
def enter_Wlan(self): ''' 连接WLAN并使用WLAN启动chrome浏览器上网 :return: ''' result = "pass" actual_result = "" self.settings.start() self.settings.list_wlan() if self.settings.get_wlan_switch() == "开启": err_msg = "首次启动设置WLAN应为关闭状态!!" print(err_msg) actual_result = actual_result + "\n" + err_msg result = "fail" self.settings.wlan_switch() if self.settings.get_wlan_switch() == "关闭": off_original = self.path + "settings\\WLAN关闭时.png" self.d.screenshot(off_original) self.settings.wlan_switch() if self.settings.get_wlan_switch() == "开启": on_original = self.path + "settings\\WLAN开启时.png" self.d.screenshot(on_original) time.sleep(3) if self.d(resourceId="android:id/title")[0].get_text() != '': print(">>>WIFI已开启时, 可正常搜索到WIFI") else: err_msg = "WIFI已开启时,等待3秒未搜索到可用WIFI" print(err_msg) err_screenshot = self.path + "settings\\" + err_msg + ".png" self.d.screenshot(err_screenshot) actual_result = actual_result + "\n" + err_msg result = "fail" self.settings.wlan_switch() for i in range(3): if self.settings.get_wlan_switch() == "关闭": comparison = self.path + "settings\\WLAN关闭时" + str(i) + ".png" self.d.screenshot(comparison) if not (image_comparison.compare_image_with_histogram( off_original, comparison)): err_msg = "WIFI关闭时" + str(i) + "对比失败" print(err_msg) actual_result = actual_result + "\n" + err_msg result = "fail" self.settings.wlan_switch() time.sleep(2) if self.settings.get_wlan_switch() == "开启": comparison = self.path + "settings\\WLAN开启时" + str(i) + ".png" self.d.screenshot(comparison) if self.d(resourceId="android:id/title")[0].get_text() != '': print(">>>WIFI已开启时, 可正常搜索到WIFI") print(self.d(resourceId="android:id/title")[0].get_text()) else: err_msg = "WIFI已开启" + str(i) + "时,等待3秒未搜索到可用WIFI" print(err_msg) actual_result = actual_result + "\n" + err_msg result = "fail" self.settings.wlan_switch() self.settings.auto_connect_wifi() self.d.press("home") chrome = Chrome(self.d) 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 + "settings\\" + err_msg + ".png" self.d.screenshot(err_screenshot) return actual_result, result