How to use test_device_info method in Airtest

Best Python code snippet using Airtest

test_project_U3__bac.py

Source:test_project_U3__bac.py Github

copy

Full Screen

1#!/usr/bin/env python2# _*_ coding:utf-8 _*_3__author__ = 'Curry'4'''5description:6 一、项目名称:U3项目自动化测试7 二、涵盖测试模块:8 1、云卡和实体卡切换9 2、Flash10 3、显示11 4、加入云卡后的稳定性12'''13import pytest, subprocess, time, os, allure, sys, random14# 获取项目路径15BASEDIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))16sys.path.append(BASEDIR)17from common import models, logger18from common.ui_operation import S20i_uiOpration19from config import settings, U3_settings20import uiautomator2 as u221# from pywinauto import application22from openpyxl import load_workbook23# 获取项目名称24project_name = os.path.basename(__file__).split('.')[0]25# 创建log对象26log_name = '.'.join(['_'.join([project_name, time.strftime('%Y%m%d%H%M%S', time.localtime())]), "log"])27log_file = os.path.join(BASEDIR, "logs", log_name)28log = logger.Logger(screen_output=True, log_level='logging.INFO', log_file=log_file).create_logger()29def screenShot(d, title):30 '''31 在uiautomator2的截图函数上封装的截图方法32 :param33 d:uiautomator2对象34 title: 自定义截图的名称35 :return: 返回截图的路径36 '''37 screenShot_file = '/'.join([test_record_path, '.'.join([title, 'png'])])38 d.screenshot(screenShot_file)39 return screenShot_file40def pull_ScreenRecord(d, title):41 list = d.adb_shell('ls /sdcard/ScreenRecord/record/')42 ScreenRecord_list = list.strip().split('\n')43 file = '/'.join(['/sdcard/ScreenRecord/record', ScreenRecord_list[-1]])44 save_file = '/'.join([test_record_path, '.'.join([title, 'mp4'])])45 d.pull(src=file, dst=save_file)46 return save_file47@allure.feature('云卡和实体卡切换')48class Test_CloudSimAndPhysicalSimSwitch:49 # 测试类起始函数50 def setup_class(self):51 # self.start_SwitchComTool = application.Application().start(settings.Qualcomm_SwitchCom_file) # 启动高通自动切口工具52 log.info("-"*20 + "Start Test_CloudSimAndPhysicalSimSwitch" + "-"*20)53 self.u3 = models.U3(device_id=U3_settings.test_device_info['id'], log_project=log)54 self.s20i = models.Glocalme(device_id=U3_settings.auxiliary_device_info['id'], log_project=log)55 self.u3.wait_device_connect() # 等待测试设备连接56 self.s20i.wait_device_connect() # 等待辅助设备连接57 # 执行uiautomator2的init操作,在测试设备端安装uiautomator app,minicap和minitouch,atx-agent58 uiautomator2_init = subprocess.getoutput("python -m uiautomator2 init")59 # self.u3_d = u2.connect(U3_settings.test_device_info['id'])60 self.s20i_d = u2.connect('c58790e3')61 self.s20i.wakey() # 设置辅助机屏幕常亮62 # 判断辅助机屏幕是否锁屏状态,如果锁屏就给设备解锁(仅适用滑动解锁)63 if self.s20i_d(resourceId="com.android.systemui:id/lock_icon").exists():64 self.s20i_d.xpath('//android.widget.FrameLayout').click()65 self.s20i_d(resourceId="com.android.systemui:id/lock_icon").click()66 version = self.u3.get_current_version() # 获取测试设备的版本67 self.test_result_path = os.path.join(BASEDIR, 'TestCaseAndResult', 'TestResult', project_name)68 if not os.path.exists(self.test_result_path):69 os.makedirs(self.test_result_path) # 创建测试结果文件夹,并以测试版本命名70 self.test_result_file_path = os.path.join(self.test_result_path, '.'.join([version, 'xlsx'])) # 创建一个以测试版本号命名的Excel表71 if os.path.exists(self.test_result_file_path):72 self.wb = load_workbook(self.test_result_file_path)73 else:74 # 打开测试用例表75 self.wb = load_workbook(os.path.join(BASEDIR, 'TestCaseAndResult', 'TestCase', '整机测试内容_无屏MIFI.xlsx'))76 self.ws = self.wb.active # 激活表77 self.ws1 = self.wb["云卡和实体卡切换"] # 选择表78 def setup(self):79 for i in range(2):80 self.s20i_d.press('home')81 self.s20i_d(resourceId="com.android.systemui:id/recent_apps").click()82 if self.s20i_d(resourceId="com.android.systemui:id/clear_all_button").exists(3):83 self.s20i_d(resourceId="com.android.systemui:id/clear_all_button").click()84 log.info("cleared background app success.")85 else:86 log.info('no background app running.')87 self.s20i_d.press('home')88 # @pytest.mark.skip(msg="test")89 def test01(self):90 log.info("start %s" % sys._getframe().f_code.co_name)91 time.sleep(0.5)92 with allure.step("第一步:拔出实体卡后重启设备"):93 while True:94 inp = input('\033[35;0m%s' % '请拔出实体卡, 确认操作完成后输入y继续(输入q退出测试):')95 if inp == 'y':96 break97 elif inp == 'q':98 log.error('用户退出测试,结束测试, inp:%s' % inp)99 assert False100 else:101 log.error("输入错误,输入为:%s" % inp)102 time.sleep(0.5)103 continue104 self.u3.reboot()105 time.sleep(5)106 self.u3.wait_network_connect()107 time.sleep(1)108 with allure.step('第二步:测试设备关机,插入实体卡后开机,登陆webui界面查看是否显示选择登陆界面'):109 while True:110 inp = input('\033[35;0m%s' % '请将测试设备关机,并插入实体卡后开机,确认操作完成后输入y继续(输入q退出测试):')111 if inp == 'y':112 break113 elif inp == 'q':114 log.error('用户退出测试,结束测试, inp:%s' % inp)115 assert False116 else:117 log.error("输入错误,输入为:%s" % inp)118 time.sleep(0.5)119 continue120 self.u3.wait_device_connect()121 self.open_webui()122 test_result_01 = pytest.assume(self.s20i_d(text="A new physical SIM is detected, please select the way you want to use mobile data.").exists(10))123 if not test_result_01:124 self.ws1['G2'] = "FAIL"125 FailScreenShot_file = screenShot(d=self.s20i_d, title='test01_Step2_fail')126 file = open(FailScreenShot_file, 'rb').read()127 allure.attach(file, 'test01 step2 failed screenshot', allure.attachment_type.PNG)128 assert False129 with allure.step('第三步:选择实体卡登陆'):130 self.s20i_d(resourceId="text_sim_1").click() # 选择sim卡131 self.s20i_d(text="Apply").click()132 test_result_02 = pytest.assume(self.s20i_d(resourceId="notice_cnt", text="You will use SIM 1(Manual) for Internet.").exists(10)) # 判断是否弹窗提示使用实体卡133 self.s20i_d(resourceId="notice_btn_ok").click()134 self.u3.wait_network_connect()135 time.sleep(3)136 test_result_03 = pytest.assume(self.u3.login_type() == 0) # 判断测试机是否使用实体卡137 if all([test_result_02, test_result_03]):138 self.ws1['G2'] = "PASS"139 else:140 self.ws1['G2'] = "FAIL"141 log.error('测试结果test_result_01:%stest_result_02:%s' % (test_result_01, test_result_02))142 def test02(self):143 log.info("start %s" % sys._getframe().f_code.co_name)144 time.sleep(0.5)145 with allure.step("第一步:拔出实体卡后重启设备"):146 while True:147 inp = input('\033[35;0m%s' % '请拔出实体卡, 确认操作完成后输入y继续(输入q退出测试):')148 if inp == 'y':149 break150 elif inp == 'q':151 log.error('用户退出测试,结束测试, inp:%s' % inp)152 assert False153 else:154 log.error("输入错误,输入为:%s" % inp)155 time.sleep(0.5)156 continue157 self.u3.reboot()158 time.sleep(5)159 self.u3.wait_network_connect()160 time.sleep(1)161 with allure.step('第二步:测试设备关机,插入实体卡后开机'):162 while True:163 inp = input('\033[35;0m%s' % '请将测试设备关机, 并插入实体卡后开机,确认操作完成后输入y继续(输入q退出测试):')164 if inp == 'y':165 break166 elif inp == 'q':167 log.error('用户退出测试,结束测试, inp:%s' % inp)168 assert False169 else:170 log.error("输入错误,输入为:%s" % inp)171 time.sleep(0.5)172 continue173 self.u3.wait_device_connect()174 time.sleep(3)175 with allure.step('第三步:辅助机连接测试机wifi,打开浏览器进入webUi界面,选择云卡登陆'):176 self.open_webui()177 self.s20i_d(resourceId="text_sim_0").click() # 选择云卡178 self.s20i_d(text="Apply").click()179 test_result_01 = pytest.assume(self.s20i_d(resourceId="notice_cnt", text="You will use Cloud SIM(Manual) for Internet.").exists(10)) # 判断是否弹窗提示使用云卡180 self.s20i_d(resourceId="notice_btn_ok").click()181 time.sleep(3)182 self.u3.wait_network_connect()183 time.sleep(5)184 test_result_02 = pytest.assume(self.u3.login_type() == 1) # 判断测试机是否使用云卡185 if not all([test_result_01, test_result_02]):186 self.ws1['G3'] = "FAIL"187 FailScreenShot_file = screenShot(d=self.s20i_d, title='Step2_fail')188 file = open(FailScreenShot_file, 'rb').read()189 allure.attach(file, '开机云卡登陆失败webui的截图', allure.attachment_type.PNG)190 assert False191 with allure.step("第四步: 切换SIM卡登陆"):192 self.login_webui()193 # 进入SIM卡管理界面,切换到SIM卡登陆194 self.s20i_d(text="Settings").click()195 self.s20i_d(text="SIM card management").click()196 self.s20i_d(resourceId="sim_select").click()197 self.s20i_d(resourceId="text_sim_1").click()198 self.s20i_d(text="Apply").click()199 test_result_01 = pytest.assume(self.s20i_d(resourceId="notice_cnt", text="You will use SIM 1(Manual) for Internet.").exists(10)) # 判断是否弹窗提示使用实体卡200 self.s20i_d(resourceId="notice_btn_ok").click()201 time.sleep(3)202 self.u3.wait_network_connect()203 time.sleep(5)204 test_result_02 = pytest.assume(self.u3.login_type() == 0) # 判断测试机是否使用实体卡205 if not all([test_result_01, test_result_02]):206 self.ws1['G3'] = "FAIL"207 FailScreenShot_file = screenShot(d=self.s20i_d, title='Step3_fail')208 file = open(FailScreenShot_file, 'rb').read()209 allure.attach(file, '切换云卡登陆失败webui的截图', allure.attachment_type.PNG)210 assert False211 with allure.step("第五步:切换到云卡登陆"):212 time.sleep(90) # 此处设置90秒等待,以免切换卡太频繁导致无法切换213 self.s20i_d(resourceId="sim_select").click()214 self.s20i_d(resourceId="text_sim_0").click()215 self.s20i_d(text="Apply").click()216 time.sleep(3)217 self.u3.wait_network_connect()218 time.sleep(5)219 test_result_03 = pytest.assume(self.u3.login_type() == 1) # 判断测试机是否使用云卡220 if not test_result_03:221 self.ws1['G3'] = "FAIL"222 FailScreenShot_file = screenShot(d=self.s20i_d, title='Step4_fail')223 file = open(FailScreenShot_file, 'rb').read()224 allure.attach(file, '切换云卡登陆失败webui的截图', allure.attachment_type.PNG)225 else:226 self.ws1['G3'] = "PASS"227 # @pytest.mark.skip()228 def test03(self):229 log.info("start %s" % sys._getframe().f_code.co_name)230 time.sleep(0.5)231 with allure.step('第一步:测试设备关机,拨出实体卡后开机'):232 inp = input('\033[35;0m请将测试设备关机,拔出实体卡后开机,确认操作完成后输入y继续:')233 if inp == 'y':234 self.u3.wait_device_connect()235 self.u3.wait_network_connect()236 time.sleep(1)237 else:238 log.error('用户操作失败,结束测试, inp:%s' % inp)239 self.ws1['G4'] = "NONE"240 assert False241 with allure.step("第二步:插入SIM卡"):242 inp = input('\033[35;0m请插入实体卡,确认操作完成后输入y继续:')243 if inp == 'y':244 self.u3.wait_device_connect()245 else:246 log.error('用户操作失败,结束测试, inp:%s' % inp)247 self.ws1['G4'] = "NONE"248 assert False249 with allure.step("第三步:辅助机连接测试机wifi,登陆webui界面切换SIM卡"):250 time.sleep(30)251 self.open_webui()252 self.login_webui()253 self.s20i_d(text="Settings").click()254 self.s20i_d(text="SIM card management").click()255 self.s20i_d(resourceId="sim_select").click()256 # 点击选择SIM 1,查看是否可以设置为SIM 1,此动作重复两次257 for i in range(2):258 self.s20i_d(resourceId="text_sim_1").click()259 time.sleep(1)260 sim_selected = self.s20i_d.xpath('//*[@resource-id="span_radio_state_1"]/android.view.View[2]').exists # 判断是否可以选择实体卡登陆,return True or False261 # global test03_result262 test03_result = pytest.assume(sim_selected == False)263 if test03_result:264 self.ws1['G4'] = "PASS"265 else:266 self.ws1['G4'] = "FAIL"267 FailScreenShot_file = screenShot(d=self.s20i_d, title='Step4_fail')268 file = open(FailScreenShot_file, 'rb').read()269 allure.attach(file, '实体卡切换按钮置灰失败的截图', allure.attachment_type.PNG)270 def test04(self):271 log.info("start %s" % sys._getframe().f_code.co_name)272 time.sleep(0.5)273 with allure.step("第一步:拔出实体卡后重启设备"):274 while True:275 inp = input('\033[35;0m%s' % '请拔出实体卡, 确认操作完成后输入y继续(输入q退出测试):')276 if inp == 'y':277 break278 elif inp == 'q':279 log.error('用户退出测试,结束测试, inp:%s' % inp)280 assert False281 else:282 log.error("输入错误,输入为:%s" % inp)283 time.sleep(0.5)284 continue285 self.u3.reboot()286 time.sleep(5)287 self.u3.wait_network_connect()288 time.sleep(1)289 with allure.step("第二步:插入SIM卡,重启,选择云卡登陆"):290 while True:291 inp = input('\033[35;0m%s' % '请插入实体卡, 确认操作完成后输入y继续(输入q退出测试):')292 if inp == 'y':293 break294 elif inp == 'q':295 log.error('用户退出测试,结束测试, inp:%s' % inp)296 assert False297 else:298 log.error("输入错误,输入为:%s" % inp)299 time.sleep(0.5)300 continue301 self.u3.reboot()302 time.sleep(3)303 self.u3.wait_device_connect()304 time.sleep(30)305 self.open_webui()306 self.s20i_d(resourceId="text_sim_0").click() # 选择云卡307 self.s20i_d(text="Apply").click()308 time.sleep(3)309 self.u3.wait_network_connect()310 time.sleep(3)311 test_result_01 = pytest.assume(self.u3.login_type() == 1) # 判断测试机是否使用云卡312 if test_result_01:313 self.ws1['G5'] = "PASS"314 else:315 FailScreenShot_file = screenShot(d=self.s20i_d, title='test04_step2_fail')316 file = open(FailScreenShot_file, 'rb').read()317 allure.attach(file, 'test04 cloudsim login failed ScreenShot', allure.attachment_type.PNG)318 self.ws1['G5'] = "FAIL"319 def test05(self):320 log.info("start %s" % sys._getframe().f_code.co_name)321 time.sleep(0.5)322 with allure.step("第一步:拔出实体卡后重启设备"):323 while True:324 inp = input('\033[35;0m%s' % '请拔出实体卡, 确认操作完成后输入y继续(输入q退出测试):')325 if inp == 'y':326 break327 elif inp == 'q':328 log.error('用户退出测试,结束测试, inp:%s' % inp)329 assert False330 else:331 log.error("输入错误,输入为:%s" % inp)332 time.sleep(0.5)333 continue334 self.u3.reboot()335 time.sleep(5)336 self.u3.wait_network_connect()337 time.sleep(1)338 with allure.step("第二步:插入SIM卡,重启,选择云卡登陆"):339 while True:340 inp = input('\033[35;0m%s' % '请插入实体卡, 确认操作完成后输入y继续(输入q退出测试):')341 if inp == 'y':342 break343 elif inp == 'q':344 log.error('用户退出测试,结束测试, inp:%s' % inp)345 assert False346 else:347 log.error("输入错误,输入为:%s" % inp)348 time.sleep(0.5)349 continue350 self.u3.reboot()351 time.sleep(3)352 self.u3.wait_device_connect()353 time.sleep(30)354 self.open_webui()355 self.s20i_d(resourceId="text_sim_0").click() # 选择云卡356 self.s20i_d(text="Apply").click()357 time.sleep(3)358 self.u3.wait_network_connect()359 time.sleep(3)360 test_result_01 = pytest.assume(self.u3.login_type() == 1) # 判断测试机是否使用云卡361 if not test_result_01:362 FailScreenShot_file = screenShot(d=self.s20i_d, title='Step5_fail')363 file = open(FailScreenShot_file, 'rb').read()364 allure.attach(file, 'test05 change cloudSim failed ScreenShot', allure.attachment_type.PNG)365 self.ws1['G6'] = "FAIL"366 assert False367 with allure.step("第三步:拔插sim卡,登陆webui界面切换SIM卡登陆"):368 while True:369 inp = input('\033[35;0m%s' % '请插拔实体卡, 确认操作完成后输入y继续(输入q退出测试):')370 if inp == 'y':371 break372 elif inp == 'q':373 log.error('用户退出测试,结束测试, inp:%s' % inp)374 assert False375 else:376 log.error("输入错误,输入为:%s" % inp)377 time.sleep(0.5)378 continue379 self.open_webui()380 self.login_webui()381 self.s20i_d(text="Settings").click()382 self.s20i_d(text="SIM card management").click()383 self.s20i_d(resourceId="sim_select").click()384 self.s20i_d(resourceId="text_sim_1").click() # 选择实体卡385 self.s20i_d(text="Apply").click()386 test_result_02 = pytest.assume(self.s20i_d(resourceId="notice_cnt", text="You will use SIM 1(Manual) for Internet.").exists(10)) # 判断是否弹窗提示使用实体卡387 if not test_result_02:388 FailScreenShot_file = screenShot(d=self.s20i_d, title='test05_Step3_fail')389 file = open(FailScreenShot_file, 'rb').read()390 allure.attach(file, 'test05 step3 failed ScreenShot', allure.attachment_type.PNG)391 self.s20i_d(resourceId="notice_btn_ok").click()392 self.u3.wait_network_connect()393 time.sleep(3)394 test_result_03 = pytest.assume(self.u3.login_type() == 0) # 判断测试机是否使用实体卡395 if all([test_result_02, test_result_03]):396 self.ws1['G6'] = "PASS"397 else:398 self.ws1['G6'] = "FAIL"399 def test06(self):400 log.info("start %s" % sys._getframe().f_code.co_name)401 time.sleep(0.5)402 with allure.step("第一步:选择云卡登陆,云卡登陆过程中拔插SIM卡"):403 if self.u3.login_type() == 0:404 self.open_webui()405 self.login_webui()406 self.s20i_d(text="Settings").click()407 self.s20i_d(text="SIM card management").click()408 self.s20i_d(resourceId="sim_select").click()409 self.s20i_d(resourceId="text_sim_0").click() # 选择云卡410 self.s20i_d(text="Apply").click()411 time.sleep(3)412 elif self.u3.login_type() == 1:413 self.u3.reboot()414 self.u3.wait_device_disconnect()415 self.u3.wait_device_connect()416 # pytest.assume(self.s20i_d(resourceId="notice_cnt", text="You will use Cloud SIM(Manual) for Internet.").exists(10)) # 判断是否弹窗提示使用云卡417 # self.s20i_d(resourceId="notice_btn_ok").click()418 # self.u3.wait_network_connect()419 while not self.u3.connect_network():420 inp = input('\033[35;0m%s' % "请在云卡登陆成功之前拔插sim卡,确认操作完成后输入y继续:")421 if inp == 'y':422 if not self.u3.connect_network():423 with allure.step("第二步:云卡登陆过程中,进入webui切换SIM卡登陆"):424 for i in range(2):425 self.s20i_d.press("home")426 self.open_webui()427 self.login_webui()428 self.s20i_d(text="Settings").click()429 self.s20i_d(text="SIM card management").click()430 self.s20i_d(resourceId="sim_select").click()431 if not self.u3.connect_network():432 self.s20i_d(resourceId="text_sim_1").click() # 选择SIM卡433 self.s20i_d(text="Apply").click()434 break435 else:436 log.error("未在云卡登陆成功之前切换SIM卡,重启设备后重新执行一次。")437 self.u3.reboot()438 time.sleep(3)439 self.u3.wait_device_connect()440 time.sleep(1)441 continue442 else:443 log.error("未在云卡登陆成功之前拔插SIM卡,重启设备后重新执行一次。")444 self.u3.reboot()445 time.sleep(3)446 self.u3.wait_device_connect()447 continue448 else:449 log.error("输入错误,输入为:%s" % inp)450 time.sleep(0.5)451 continue452 test_result_01 = pytest.assume(self.s20i_d(resourceId="notice_cnt", text="You will use SIM 1(Manual) for Internet.").exists(10)) # 判断是否弹窗提示使用实体卡453 if not test_result_01:454 FailScreenShot_file = screenShot(d=self.s20i_d, title='Step6_fail')455 file = open(FailScreenShot_file, 'rb').read()456 allure.attach(file, 'test06 change physical Sim failed ScreenShot', allure.attachment_type.PNG)457 self.s20i_d(resourceId="notice_btn_ok").click()458 self.u3.wait_network_connect()459 time.sleep(5)460 test_result_02 = pytest.assume(self.u3.login_type() == 0) # 判断测试机是否使用实体卡461 if all([test_result_01, test_result_02]):462 self.ws1['G7'] = "PASS"463 else:464 self.ws1['G7'] = "FAIL"465 def test07(self):466 log.info("start %s" % sys._getframe().f_code.co_name)467 time.sleep(0.5)468 with allure.step("第一步:拔出实体卡后重启设备"):469 while True:470 inp = input('\033[35;0m%s' % '请拔出实体卡, 确认操作完成后输入y继续(输入q退出测试):')471 if inp == 'y':472 break473 elif inp == 'q':474 log.error('用户退出测试,结束测试, inp:%s' % inp)475 assert False476 else:477 log.error("输入错误,输入为:%s" % inp)478 time.sleep(0.5)479 continue480 self.u3.reboot()481 time.sleep(5)482 self.u3.wait_network_connect()483 time.sleep(1)484 with allure.step("第二步:插入SIM卡,重启,选择云卡登陆"):485 while True:486 inp01 = input('\033[35;0m请插入实体卡,确认操作完成后输入y继续(输入q退出测试):')487 if inp01 == 'y':488 break489 elif inp01 == 'q':490 log.error('用户退出测试,结束测试, inp01:%s' % inp01)491 assert False492 else:493 log.error("输入错误,输入为:%s" % inp01)494 continue495 self.u3.reboot()496 time.sleep(3)497 self.u3.wait_device_connect()498 time.sleep(30)499 self.open_webui()500 self.s20i_d(resourceId="text_sim_0").click() # 选择云卡501 self.s20i_d(text="Apply").click()502 test_result_01 = pytest.assume(self.s20i_d(resourceId="notice_cnt", text="You will use Cloud SIM(Manual) for Internet.").exists(10)) # 判断是否弹窗提示使用云卡503 self.s20i_d(resourceId="notice_btn_ok").click()504 self.u3.wait_network_connect()505 time.sleep(5)506 test_result_02 = pytest.assume(self.u3.login_type() == 1) # 判断测试机是否使用云卡507 if not all([test_result_01, test_result_02]):508 self.ws1['G8'] = "FAIL"509 FailScreenShot_file = screenShot(d=self.s20i_d, title='Step8_fail')510 file = open(FailScreenShot_file, 'rb').read()511 allure.attach(file, 'test07 change cloudSim failed ScreenShot', allure.attachment_type.PNG)512 assert False513 with allure.step("第三步:拔插SIM卡,重启设备"):514 while True:515 inp02 = input('\033[35;0m请拔插实体卡,确认操作完成后输入y继续(输入q退出测试):')516 if inp02 == 'y':517 break518 elif inp02 == 'q':519 log.error('用户退出测试,结束测试, inp02:%s' % inp02)520 assert False521 else:522 log.error("输入错误,输入为:%s" % inp02)523 continue524 self.u3.reboot()525 time.sleep(3)526 self.u3.wait_network_connect()527 time.sleep(5)528 test_result = pytest.assume(self.u3.login_type() == 1) # 判断测试机是否使用云卡529 if test_result:530 self.ws1['G7'] = "PASS"531 else:532 self.ws1['G7'] = "FAIL"533 def test08(self):534 log.info("start %s" % sys._getframe().f_code.co_name)535 time.sleep(0.5)536 with allure.step("第一步:判断当前是否使用云卡,如果不是云卡切换到云卡"):537 while True:538 inp = input('\033[35;0m%s' % '请拔出实体卡, 确认操作完成后输入y继续(输入q退出测试):')539 if inp == 'y':540 break541 elif inp == 'q':542 log.error('用户退出测试,结束测试, inp:%s' % inp)543 assert False544 else:545 log.error("输入错误,输入为:%s" % inp)546 time.sleep(0.5)547 continue548 self.u3.reboot()549 time.sleep(5)550 self.u3.wait_network_connect()551 time.sleep(1)552 with allure.step("第二步:插入带pin码的SIM卡,重启设备,登陆webui界面"):553 while True:554 inp = input('\033[35;0m%s' % '请插入带pin码的SIM卡, 确认操作完成后输入y继续(输入q退出测试):')555 if inp == 'y':556 break557 elif inp == 'q':558 log.error('用户退出测试,结束测试, inp:%s' % inp)559 assert False560 else:561 log.error("输入错误,输入为:%s" % inp)562 time.sleep(0.5)563 continue564 self.u3.reboot()565 time.sleep(5)566 self.u3.wait_device_connect()567 self.open_webui()568 test_result_01 = pytest.assume(self.s20i_d(resourceId="text_sim_1", text="SIM 1(PIN required)").exists(10)) # 判断是否出现选择登陆界面569 if not test_result_01:570 self.ws1['G9'] = "FAIL"571 FailScreenShot_file = screenShot(d=self.s20i_d, title='test08_step2_fail')572 file = open(FailScreenShot_file, 'rb').read()573 allure.attach(file, 'test08 step2 failed ScreenShot', allure.attachment_type.PNG)574 assert False575 with allure.step("第三步:切换SIM卡登陆"):576 self.s20i_d(resourceId="text_sim_1", text="SIM 1(PIN required)").click()577 self.s20i_d(text="Apply").click()578 test_result_02 = pytest.assume(self.s20i_d(resourceId="notice_cnt", text="You will use SIM 1(PIN required) for Internet.").exists(10)) # 判断是否弹窗提示使用SIM 1579 time.sleep(3)580 test_result_03 = pytest.assume(self.u3.connect_network() == False)581 if all([test_result_02, test_result_03]):582 self.ws1['G9'] = "PASS"583 else:584 self.ws1['G9'] = "FAIL"585 FailScreenShot_file = screenShot(d=self.s20i_d, title='test08_step3_fail')586 file = open(FailScreenShot_file, 'rb').read()587 allure.attach(file, 'test08 step3 change SIM 1 failed ScreenShot', allure.attachment_type.PNG)588 def test09(self):589 log.info("start %s" % sys._getframe().f_code.co_name)590 time.sleep(0.5)591 with allure.step("第一步:拔出实体卡后重启设备"):592 while True:593 inp = input('\033[35;0m%s' % '请拔出实体卡, 确认操作完成后输入y继续(输入q退出测试):')594 if inp == 'y':595 break596 elif inp == 'q':597 log.error('用户退出测试,结束测试, inp:%s' % inp)598 assert False599 else:600 log.error("输入错误,输入为:%s" % inp)601 time.sleep(0.5)602 continue603 self.u3.reboot()604 time.sleep(5)605 self.u3.wait_network_connect()606 time.sleep(1)607 with allure.step("第二步:插入实体卡后重启设备,选择云卡登陆"):608 while True:609 inp = input('\033[35;0m%s' % '请插入实体卡, 确认操作完成后输入y继续(输入q退出测试):')610 if inp == 'y':611 break612 elif inp == 'q':613 log.error('用户退出测试,结束测试, inp:%s' % inp)614 assert False615 else:616 log.error("输入错误,输入为:%s" % inp)617 time.sleep(0.5)618 continue619 self.u3.reboot()620 time.sleep(5)621 self.u3.wait_device_connect()622 self.open_webui()623 self.s20i_d(resourceId="text_sim_0").click()624 self.s20i_d(text="Apply").click()625 self.u3.wait_network_connect()626 time.sleep(3)627 test_result_01 = pytest.assume(self.u3.login_type() == 1)628 with allure.step("第三步:拔掉SIM卡,登陆webui界面切换SIM卡登陆"):629 while True:630 inp = input('\033[35;0m%s' % '请拔出实体卡, 确认操作完成后输入y继续(输入q退出测试):')631 if inp == 'y':632 break633 elif inp == 'q':634 log.error('用户退出测试,结束测试, inp:%s' % inp)635 assert False636 else:637 log.error("输入错误,输入为:%s" % inp)638 time.sleep(0.5)639 continue640 self.open_webui()641 self.login_webui()642 self.s20i_d(text="Settings").click()643 self.s20i_d(text="SIM card management").click()644 self.s20i_d(resourceId="sim_select").click()645 self.s20i_d(resourceId="text_sim_1").click() # 选择SIM卡646 self.s20i_d(text="Apply").click()647 time.sleep(30)648 self.s20i_d(resourceId="com.android.chrome:id/url_bar").click() # 点击搜索框649 self.s20i_d.send_keys("192.168.43.1", clear=True) # 在搜索框中输入192.168.43.1650 self.s20i_d.xpath('//android.widget.ListView/android.view.ViewGroup[1]').click() # 点击进入webui界面651 test_result_02 = pytest.assume(self.s20i_d(text="SIM card state(Searching)").exists(10)) # 判断potal界面是否一直显示查找SIM卡中652 if not test_result_02:653 FailScreenShot_file = screenShot(d=self.s20i_d, title='test09_step3_fail')654 file = open(FailScreenShot_file, 'rb').read()655 allure.attach(file, 'test09 step3 change SIM 1 failed ScreenShot', allure.attachment_type.PNG)656 if all([test_result_01, test_result_02]):657 self.ws1['G10'] = "PASS"658 else:659 self.ws1['G10'] = "FAIL"660 def test11(self):661 log.info("start %s" % sys._getframe().f_code.co_name)662 time.sleep(0.5)663 with allure.step("第一步:拔出实体卡后重启设备"):664 while True:665 inp = input('\033[35;0m%s' % '请拔出实体卡, 确认操作完成后输入y继续(输入q退出测试):')666 if inp == 'y':667 break668 elif inp == 'q':669 log.error('用户退出测试,结束测试, inp:%s' % inp)670 assert False671 else:672 log.error("输入错误,输入为:%s" % inp)673 time.sleep(0.5)674 continue675 self.u3.reboot()676 time.sleep(5)677 self.u3.wait_network_connect()678 time.sleep(1)679 with allure.step("第二步:插入实体卡后重启设备,选择云卡登陆"):680 while True:681 inp = input('\033[35;0m%s' % '请插入实体卡, 确认操作完成后输入y继续(输入q退出测试):')682 if inp == 'y':683 break684 elif inp == 'q':685 log.error('用户退出测试,结束测试, inp:%s' % inp)686 assert False687 else:688 log.error("输入错误,输入为:%s" % inp)689 time.sleep(0.5)690 continue691 self.u3.reboot()692 time.sleep(5)693 self.u3.wait_device_connect()694 self.open_webui()695 self.s20i_d(resourceId="text_sim_0").click()696 self.s20i_d(text="Apply").click()697 self.u3.wait_network_connect()698 time.sleep(3)699 test_result_01 = pytest.assume(self.u3.login_type() == 1)700 with allure.step("第三步:插入另外一张SIM卡,登陆web界面切换SIM卡"):701 while True:702 inp = input('\033[35;0m%s' % '请插入另外一张实体卡, 确认操作完成后输入y继续(输入q退出测试):')703 if inp == 'y':704 break705 elif inp == 'q':706 log.error('用户退出测试,结束测试, inp:%s' % inp)707 assert False708 else:709 log.error("输入错误,输入为:%s" % inp)710 time.sleep(0.5)711 continue712 self.open_webui()713 self.login_webui()714 self.s20i_d(text="Settings").click()715 self.s20i_d(text="SIM card management").click()716 self.s20i_d(resourceId="sim_select").click()717 self.s20i_d(resourceId="text_sim_1").click() # 选择SIM卡718 self.s20i_d(text="Apply").click()719 self.u3.wait_network_connect()720 time.sleep(3)721 test_result_02 = pytest.assume(self.u3.login_type() == 0) # 判断当前登陆类型是否为实体卡722 if not test_result_02:723 FailScreenShot_file = screenShot(d=self.s20i_d, title='test11_step3_fail')724 file = open(FailScreenShot_file, 'rb').read()725 allure.attach(file, 'test11 step3 failed ScreenShot', allure.attachment_type.PNG)726 if all([test_result_01, test_result_02]):727 self.ws1['G12'] = "PASS"728 else:729 self.ws1['G12'] = "FAIL"730 def test12(self):731 log.info("start %s" % sys._getframe().f_code.co_name)732 time.sleep(0.5)733 with allure.step("第一步:拔出实体卡后重启设备"):734 while True:735 inp = input('\033[35;0m%s' % '请拔出实体卡, 确认操作完成后输入y继续(输入q退出测试):')736 if inp == 'y':737 break738 elif inp == 'q':739 log.error('用户退出测试,结束测试, inp:%s' % inp)740 assert False741 else:742 log.error("输入错误,输入为:%s" % inp)743 time.sleep(0.5)744 continue745 self.u3.reboot()746 time.sleep(5)747 self.u3.wait_network_connect()748 time.sleep(1)749 with allure.step("第二步:插入实体卡后重启设备,选择云卡登陆"):750 while True:751 inp = input('\033[35;0m%s' % '请插入实体卡, 确认操作完成后输入y继续(输入q退出测试):')752 if inp == 'y':753 break754 elif inp == 'q':755 log.error('用户退出测试,结束测试, inp:%s' % inp)756 assert False757 else:758 log.error("输入错误,输入为:%s" % inp)759 time.sleep(0.5)760 continue761 self.u3.reboot()762 time.sleep(5)763 self.u3.wait_device_connect()764 self.open_webui()765 self.s20i_d(resourceId="text_sim_0").click()766 self.s20i_d(text="Apply").click()767 self.u3.wait_network_connect()768 time.sleep(3)769 test_result_01 = pytest.assume(self.u3.login_type() == 1)770 with allure.step("第三步:重启设备,查看设备是否使用云卡登陆,且登陆成功"):771 self.u3.reboot()772 time.sleep(5)773 self.u3.wait_device_connect()774 self.u3.wait_network_connect()775 time.sleep(3)776 test_result_02 = pytest.assume(self.u3.login_type() == 1)777 if all([test_result_01, test_result_02]):778 self.ws1['G13'] = "PASS"779 else:780 self.ws1['G13'] = "FAIL"781 def test13(self):782 log.info("start %s" % sys._getframe().f_code.co_name)783 time.sleep(0.5)784 with allure.step("第一步:拔出实体卡后重启设备"):785 while True:786 inp = input('\033[35;0m%s' % '请拔出实体卡, 确认操作完成后输入y继续(输入q退出测试):')787 if inp == 'y':788 break789 elif inp == 'q':790 log.error('用户退出测试,结束测试, inp:%s' % inp)791 assert False792 else:793 log.error("输入错误,输入为:%s" % inp)794 time.sleep(0.5)795 continue796 self.u3.reboot()797 time.sleep(5)798 self.u3.wait_network_connect()799 time.sleep(1)800 with allure.step("第二步:插入实体卡后重启设备,选择云卡登陆"):801 while True:802 inp = input('\033[35;0m%s' % '请插入实体卡, 确认操作完成后输入y继续(输入q退出测试):')803 if inp == 'y':804 break805 elif inp == 'q':806 log.error('用户退出测试,结束测试, inp:%s' % inp)807 assert False808 else:809 log.error("输入错误,输入为:%s" % inp)810 time.sleep(0.5)811 continue812 self.u3.reboot()813 time.sleep(5)814 self.u3.wait_device_connect()815 self.open_webui()816 self.s20i_d(resourceId="text_sim_0").click()817 self.s20i_d(text="Apply").click()818 self.u3.wait_network_connect()819 time.sleep(3)820 test_result_01 = pytest.assume(self.u3.login_type() == 1)821 with allure.step("第三步:插入另外一张SIM卡,登陆web界面"):822 while True:823 inp = input('\033[35;0m%s' % '请插入另外一张实体卡, 确认操作完成后输入y继续(输入q退出测试):')824 if inp == 'y':825 break826 elif inp == 'q':827 log.error('用户退出测试,结束测试, inp:%s' % inp)828 assert False829 else:830 log.error("输入错误,输入为:%s" % inp)831 time.sleep(0.5)832 continue833 self.u3.reboot()834 time.sleep(5)835 self.u3.wait_device_connect()836 self.open_webui()837 test_result_02 = pytest.assume(self.s20i_d(text="A new physical SIM is detected, please select the way you want to use mobile data.").exists(10))838 if not test_result_02:839 FailScreenShot_file = screenShot(d=self.s20i_d, title='test013_step3_fail')840 file = open(FailScreenShot_file, 'rb').read()841 allure.attach(file, 'test13 step3 failed ScreenShot', allure.attachment_type.PNG)842 if all([test_result_01, test_result_02]):843 self.ws1['G14'] = "PASS"844 else:845 self.ws1['G14'] = "FAIL"846 def test14(self):847 log.info("start %s" % sys._getframe().f_code.co_name)848 time.sleep(0.5)849 with allure.step("第一步:插入实体卡后重启设备,选择实体卡登陆"):850 while True:851 inp = input('\033[35;0m%s' % '请插入实体卡, 确认操作完成后输入y继续(输入q退出测试):')852 if inp == 'y':853 break854 elif inp == 'q':855 log.error('用户退出测试,结束测试, inp:%s' % inp)856 assert False857 else:858 log.error("输入错误,输入为:%s" % inp)859 time.sleep(0.5)860 continue861 self.u3.reboot()862 time.sleep(5)863 self.open_webui()864 if self.s20i_d(text="SIM card selection").exists(5):865 self.s20i_d(resourceId="text_sim_1").click()866 self.s20i_d(text="Apply").click()867 else:868 self.login_webui()869 if self.s20i_d(text="In Use: Cloud SIM").exists(3) or self.s20i_d(text="In Use: Cloud SIM(Manual)").exists(3):870 self.s20i_d(text="Settings").click()871 self.s20i_d(text="SIM card management").click()872 self.s20i_d(resourceId="sim_select").click()873 self.s20i_d(resourceId="text_sim_1").click() # 选择SIM卡874 self.s20i_d(text="Apply").click()875 self.u3.wait_network_connect()876 time.sleep(3)877 assert self.u3.login_type() == 0 # 断言是否为实体卡登陆878 with allure.step("第二步:使用SIM卡过程中,登陆webui界面切换云卡"):879 time.sleep(60) # 阻塞时间设置为60秒是为了防止云卡和实体卡频繁切换导致无法切换880 self.open_webui()881 self.login_webui()882 self.s20i_d(text="Settings").click()883 self.s20i_d(text="SIM card management").click()884 self.s20i_d(resourceId="sim_select").click()885 self.s20i_d(resourceId="text_sim_0").click() # 选择云卡登陆886 self.s20i_d(text="Apply").click()887 time.sleep(3)888 self.u3.wait_network_connect()889 time.sleep(3)890 test_result = pytest.assume(self.u3.login_type() == 1) # 判断当前登陆类型是否为云卡891 if test_result:892 self.ws1['G15'] = "PASS"893 else:894 self.ws1['G15'] = "FAIL"895 def test15(self):896 log.info("start %s" % sys._getframe().f_code.co_name)897 time.sleep(0.5)898 with allure.step("第一步:插入实体卡后重启设备,选择实体卡登陆"):899 while True:900 inp = input('\033[35;0m%s' % '请插入实体卡, 确认操作完成后输入y继续(输入q退出测试):')901 if inp == 'y':902 break903 elif inp == 'q':904 log.error('用户退出测试,结束测试, inp:%s' % inp)905 assert False906 else:907 log.error("输入错误,输入为:%s" % inp)908 time.sleep(0.5)909 continue910 self.u3.reboot()911 time.sleep(5)912 self.open_webui()913 if self.s20i_d(text="SIM card selection").exists(5):914 self.s20i_d(resourceId="text_sim_1").click()915 self.s20i_d(text="Apply").click()916 else:917 self.login_webui()918 if self.s20i_d(text="In Use: Cloud SIM").exists(3) or self.s20i_d(text="In Use: Cloud SIM(Manual)").exists(3):919 self.s20i_d(text="Settings").click()920 self.s20i_d(text="SIM card management").click()921 self.s20i_d(resourceId="sim_select").click()922 self.s20i_d(resourceId="text_sim_1").click() # 选择SIM卡923 self.s20i_d(text="Apply").click()924 time.sleep(5)925 self.u3.wait_network_connect()926 time.sleep(3)927 assert self.u3.login_type() == 0 # 断言是否为实体卡登陆928 with allure.step("第二步:拔掉SIM卡,进入webui界面查看是否显示断开连接"):929 while True:930 inp = input('\033[35;0m%s' % '请拔出实体卡, 确认操作完成后输入y继续(输入q退出测试):')931 if inp == 'y':932 break933 elif inp == 'q':934 log.error('用户退出测试,结束测试, inp:%s' % inp)935 assert False936 else:937 log.error("输入错误,输入为:%s" % inp)938 time.sleep(0.5)939 continue940 self.open_webui()941 self.login_webui()942 # test_result_01 = pytest.assume(self.s20i_d(text="Status: Disconnect").exists(5)) # 判断网络是否断开连接943 test_result_01 = pytest.assume(self.s20i_d(text="Status: Absent").exists(5)) # 判断网络是否断开连接944 if not test_result_01:945 FailScreenShot_file = screenShot(d=self.s20i_d, title='test015_step2_fail')946 file = open(FailScreenShot_file, 'rb').read()947 allure.attach(file, 'test15 step2 failed ScreenShot', allure.attachment_type.PNG)948 with allure.step("第三步:重启设备,查看云卡是否登陆成功"):949 self.u3.reboot()950 time.sleep(5)951 self.u3.wait_network_connect()952 time.sleep(3)953 test_result_02 = pytest.assume(self.u3.login_type() == 1) # 判断当前登陆类型是否为云卡954 if all([test_result_01, test_result_02]):955 self.ws1['G16'] = "PASS"956 else:957 self.ws1['G16'] = "FAIL"958 def test16(self):959 log.info("start %s" % sys._getframe().f_code.co_name)960 time.sleep(0.5)961 with allure.step("第一步:插入实体卡后重启设备,选择实体卡登陆"):962 while True:963 inp = input('\033[35;0m%s' % '请插入实体卡, 确认操作完成后输入y继续(输入q退出测试):')964 if inp == 'y':965 break966 elif inp == 'q':967 log.error('用户退出测试,结束测试, inp:%s' % inp)968 assert False969 else:970 log.error("输入错误,输入为:%s" % inp)971 time.sleep(0.5)972 continue973 self.u3.reboot()974 time.sleep(5)975 self.open_webui()976 if self.s20i_d(text="SIM card selection").exists(5):977 self.s20i_d(resourceId="text_sim_1").click()978 self.s20i_d(text="Apply").click()979 else:980 self.login_webui()981 if self.s20i_d(text="In Use: Cloud SIM").exists(3) or self.s20i_d(text="In Use: Cloud SIM(Manual)").exists(3):982 self.s20i_d(text="Settings").click()983 self.s20i_d(text="SIM card management").click()984 self.s20i_d(resourceId="sim_select").click()985 self.s20i_d(resourceId="text_sim_1").click() # 选择SIM卡986 self.s20i_d(text="Apply").click()987 self.u3.wait_network_connect()988 time.sleep(3)989 assert self.u3.login_type() == 0 # 断言是否为实体卡登陆990 with allure.step("第二步:重启设备,查看是否使用SIM卡登陆"):991 self.u3.reboot()992 self.u3.wait_device_disconnect()993 self.u3.wait_device_connect()994 self.u3.wait_network_connect()995 time.sleep(3)996 assert self.u3.login_type() == 0 # 判断当前登陆类型是否为SIM卡997 with allure.step("第三步:进入webui界面切换云卡登陆"):998 self.open_webui()999 self.login_webui()1000 self.s20i_d(text="Settings").click()1001 self.s20i_d(text="SIM card management").click()1002 self.s20i_d(resourceId="sim_select").click()1003 self.s20i_d(resourceId="text_sim_0").click() # 选择云卡1004 self.s20i_d(text="Apply").click()1005 time.sleep(5)1006 self.u3.wait_network_connect()1007 time.sleep(3)1008 test_result = pytest.assume(self.u3.login_type() == 1) # 判断当前登陆类型是否为云卡1009 if test_result:1010 self.ws1['G17'] = "PASS"1011 else:1012 self.ws1['G17'] = "FAIL"1013 def test17(self):1014 log.info("start %s" % sys._getframe().f_code.co_name)1015 time.sleep(0.5)1016 with allure.step("第一步:插入实体卡后重启设备,选择实体卡登陆"):1017 while True:1018 inp = input('\033[35;0m%s' % '请插入实体卡, 确认操作完成后输入y继续(输入q退出测试):')1019 if inp == 'y':1020 break1021 elif inp == 'q':1022 log.error('用户退出测试,结束测试, inp:%s' % inp)1023 assert False1024 else:1025 log.error("输入错误,输入为:%s" % inp)1026 time.sleep(0.5)1027 continue1028 self.u3.reboot()1029 time.sleep(5)1030 self.open_webui()1031 if self.s20i_d(text="SIM card selection").exists(5):1032 self.s20i_d(resourceId="text_sim_1").click()1033 self.s20i_d(text="Apply").click()1034 else:1035 self.login_webui()1036 if self.s20i_d(text="In Use: Cloud SIM").exists(3) or self.s20i_d(text="In Use: Cloud SIM(Manual)").exists(3):1037 self.s20i_d(text="Settings").click()1038 self.s20i_d(text="SIM card management").click()1039 self.s20i_d(resourceId="sim_select").click()1040 self.s20i_d(resourceId="text_sim_1").click() # 选择SIM卡1041 self.s20i_d(text="Apply").click()1042 self.u3.wait_network_connect()1043 time.sleep(3)1044 assert self.u3.login_type() == 0 # 断言是否为实体卡登陆1045 with allure.step("第二步:拔掉SIM卡,进入webui界面查看是否显示断开连接"):1046 while True:1047 inp = input('\033[35;0m%s' % '请拔出实体卡, 确认操作完成后输入y继续(输入q退出测试):')1048 if inp == 'y':1049 break1050 elif inp == 'q':1051 log.error('用户退出测试,结束测试, inp:%s' % inp)1052 assert False1053 else:1054 log.error("输入错误,输入为:%s" % inp)1055 time.sleep(0.5)1056 continue1057 self.open_webui()1058 self.login_webui()1059 # test_result_01 = pytest.assume(self.s20i_d(text="Status: Disconnect").exists(5)) # 判断网络是否断开连接1060 test_result_01 = pytest.assume(self.s20i_d(text="Status: Absent").exists(5)) # 判断网络是否断开连接1061 if not test_result_01:1062 FailScreenShot_file = screenShot(d=self.s20i_d, title='test017_step2_fail')1063 file = open(FailScreenShot_file, 'rb').read()1064 allure.attach(file, 'test17 step2 failed ScreenShot', allure.attachment_type.PNG)1065 with allure.step("第三步:插入SIM卡,查看设备网络是否连接成功"):1066 while True:1067 inp = input('\033[35;0m%s' % '请插入实体卡, 确认操作完成后输入y继续(输入q退出测试):')1068 if inp == 'y':1069 break1070 elif inp == 'q':1071 log.error('用户退出测试,结束测试, inp:%s' % inp)1072 assert False1073 else:1074 log.error("输入错误,输入为:%s" % inp)1075 time.sleep(0.5)1076 continue1077 self.u3.wait_network_connect()1078 time.sleep(3)1079 test_result = pytest.assume(self.u3.login_type() == 0) # 判断当前登陆类型是否为SIM卡1080 if test_result:1081 self.ws1['G18'] = "PASS"1082 else:1083 self.ws1['G18'] = "FAIL"1084 def test18(self):1085 log.info("start %s" % sys._getframe().f_code.co_name)1086 time.sleep(0.5)1087 with allure.step("第一步:插入实体卡后重启设备,选择实体卡登陆"):1088 while True:1089 inp = input('\033[35;0m%s' % '请插入实体卡, 确认操作完成后输入y继续(输入q退出测试):')1090 if inp == 'y':1091 break1092 elif inp == 'q':1093 log.error('用户退出测试,结束测试, inp:%s' % inp)1094 assert False1095 else:1096 log.error("输入错误,输入为:%s" % inp)1097 time.sleep(0.5)1098 continue1099 self.u3.reboot()1100 time.sleep(5)1101 self.open_webui()1102 if self.s20i_d(text="SIM card selection").exists(5):1103 self.s20i_d(resourceId="text_sim_1").click()1104 self.s20i_d(text="Apply").click()1105 else:1106 self.login_webui()1107 if self.s20i_d(text="In Use: Cloud SIM").exists(3) or self.s20i_d(text="In Use: Cloud SIM(Manual)").exists(3):1108 self.s20i_d(text="Settings").click()1109 self.s20i_d(text="SIM card management").click()1110 self.s20i_d(resourceId="sim_select").click()1111 self.s20i_d(resourceId="text_sim_1").click() # 选择SIM卡1112 self.s20i_d(text="Apply").click()1113 self.u3.wait_network_connect()1114 time.sleep(3)1115 assert self.u3.login_type() == 0 # 断言是否为实体卡登陆1116 with allure.step("第二步:拔掉SIM卡,进入webui界面查看是否显示断开连接"):1117 while True:1118 inp = input('\033[35;0m%s' % '请拔出实体卡, 确认操作完成后输入y继续(输入q退出测试):')1119 if inp == 'y':1120 break1121 elif inp == 'q':1122 log.error('用户退出测试,结束测试, inp:%s' % inp)1123 assert False1124 else:1125 log.error("输入错误,输入为:%s" % inp)1126 time.sleep(0.5)1127 continue1128 self.open_webui()1129 self.login_webui()1130 # test_result_01 = pytest.assume(self.s20i_d(text="Status: Disconnect").exists(5)) # 判断网络是否断开连接1131 test_result_01 = pytest.assume(self.s20i_d(text="Status: Absent").exists(5)) # 判断网络是否断开连接1132 if not test_result_01:1133 FailScreenShot_file = screenShot(d=self.s20i_d, title='test018_step2_fail')1134 file = open(FailScreenShot_file, 'rb').read()1135 allure.attach(file, 'test18 step2 failed ScreenShot', allure.attachment_type.PNG)1136 with allure.step("第三步:切换云卡登陆"):1137 if self.s20i_d(text="Wi-Fi clients").exists(3):1138 pass1139 else:1140 self.open_webui()1141 self.login_webui()1142 self.s20i_d(text="Settings").click()1143 self.s20i_d(text="SIM card management").click()1144 self.s20i_d(resourceId="sim_select").click()1145 self.s20i_d(resourceId="text_sim_0").click() # 选择云卡1146 self.s20i_d(text="Apply").click()1147 time.sleep(3)1148 self.u3.wait_network_connect()1149 time.sleep(3)1150 assert self.u3.login_type() == 1 # 断言是否为云卡登陆1151 with allure.step("第四步:切换SIM卡登陆"):1152 time.sleep(60)1153 self.open_webui()1154 self.login_webui()1155 self.s20i_d(text="Settings").click()1156 self.s20i_d(text="SIM card management").click()1157 self.s20i_d(resourceId="sim_select").click()1158 self.s20i_d(resourceId="text_sim_1").click() # 选择SIM卡1159 self.s20i_d(text="Apply").click()1160 time.sleep(30)1161 self.s20i_d(resourceId="com.android.chrome:id/url_bar").click() # 点击浏览器搜索框1162 self.s20i_d.send_keys("192.168.43.1", clear=True) # 在搜索框中输入192.168.43.11163 self.s20i_d.xpath('//android.widget.ListView/android.view.ViewGroup[1]').click() # 点击进入webui界面1164 self.login_webui()1165 test_result_02 = pytest.assume(self.s20i_d(text="Status: Connecting...").exists(5)) # 判断是否显示网络正在连接1166 if not test_result_02:1167 FailScreenShot_file = screenShot(d=self.s20i_d, title='test018_step4_fail')1168 file = open(FailScreenShot_file, 'rb').read()1169 allure.attach(file, 'test18 step4 failed ScreenShot', allure.attachment_type.PNG)1170 with allure.step("第五步:插入SIM卡,查看设备网络是否连接成功"):1171 while True:1172 inp = input('\033[35;0m%s' % '请插入实体卡, 确认操作完成后输入y继续(输入q退出测试):')1173 if inp == 'y':1174 break1175 elif inp == 'q':1176 log.error('用户退出测试,结束测试, inp:%s' % inp)1177 assert False1178 else:1179 log.error("输入错误,输入为:%s" % inp)1180 time.sleep(0.5)1181 continue1182 self.u3.wait_network_connect()1183 time.sleep(3)1184 test_result_03 = pytest.assume(self.u3.login_type() == 0) # 判断当前登陆类型是否为SIM卡1185 if all([test_result_01, test_result_02, test_result_03]):1186 self.ws1['G19'] = "PASS"1187 else:1188 self.ws1['G19'] = "FAIL"1189 def test19(self):1190 log.info("start %s" % sys._getframe().f_code.co_name)1191 time.sleep(0.5)1192 with allure.step("第一步:插入实体卡后重启设备,选择实体卡登陆"):1193 while True:1194 inp = input('\033[35;0m%s' % '请插入实体卡, 确认操作完成后输入y继续(输入q退出测试):')1195 if inp == 'y':1196 break1197 elif inp == 'q':1198 log.error('用户退出测试,结束测试, inp:%s' % inp)1199 assert False1200 else:1201 log.error("输入错误,输入为:%s" % inp)1202 time.sleep(0.5)1203 continue1204 self.u3.reboot()1205 time.sleep(5)1206 self.open_webui()1207 if self.s20i_d(text="SIM card selection").exists(5):1208 self.s20i_d(resourceId="text_sim_1").click()1209 self.s20i_d(text="Apply").click()1210 else:1211 self.login_webui()1212 if self.s20i_d(text="In Use: Cloud SIM").exists(3) or self.s20i_d(text="In Use: Cloud SIM(Manual)").exists(3):1213 self.s20i_d(text="Settings").click()1214 self.s20i_d(text="SIM card management").click()1215 self.s20i_d(resourceId="sim_select").click()1216 self.s20i_d(resourceId="text_sim_1").click() # 选择SIM卡1217 self.s20i_d(text="Apply").click()1218 self.u3.wait_network_connect()1219 time.sleep(3)1220 assert self.u3.login_type() == 0 # 断言是否为实体卡登陆1221 with allure.step("第二步:拔掉SIM卡,进入webui界面查看是否显示断开连接"):1222 while True:1223 inp = input('\033[35;0m%s' % '请拔出实体卡, 确认操作完成后输入y继续(输入q退出测试):')1224 if inp == 'y':1225 break1226 elif inp == 'q':1227 log.error('用户退出测试,结束测试, inp:%s' % inp)1228 assert False1229 else:1230 log.error("输入错误,输入为:%s" % inp)1231 time.sleep(0.5)1232 continue1233 self.open_webui()1234 self.login_webui()1235 test_result_01 = pytest.assume(self.s20i_d(text="Status: Disconnect").exists(5)) # 判断网络是否断开连接1236 if not test_result_01:1237 FailScreenShot_file = screenShot(d=self.s20i_d, title='test019_step2_fail')1238 file = open(FailScreenShot_file, 'rb').read()1239 allure.attach(file, 'test19 step2 failed ScreenShot', allure.attachment_type.PNG)1240 with allure.step("第三步:插入另外一张SIM卡,查看设备网络是否还是断开连接"):1241 while True:1242 inp = input('\033[35;0m%s' % '请插入另外一张实体卡, 确认操作完成后输入y继续(输入q退出测试):')1243 if inp == 'y':1244 break1245 elif inp == 'q':1246 log.error('用户退出测试,结束测试, inp:%s' % inp)1247 assert False1248 else:1249 log.error("输入错误,输入为:%s" % inp)1250 time.sleep(0.5)1251 continue1252 time.sleep(30)1253 self.open_webui()1254 self.login_webui()1255 test_result_02 = pytest.assume(self.s20i_d(text="Status: Disconnect").exists(5)) # 判断网络是否断开连接1256 if not test_result_02:1257 FailScreenShot_file = screenShot(d=self.s20i_d, title='test19_step3_fail')1258 file = open(FailScreenShot_file, 'rb').read()1259 allure.attach(file, 'test19 step3 failed ScreenShot', allure.attachment_type.PNG)1260 with allure.step("第四步:重启设备,查看webui界面是否显示选卡登陆界面"):1261 self.u3.reboot()1262 time.sleep(5)1263 self.u3.wait_device_connect()1264 self.open_webui()1265 test_result_03 = pytest.assume(self.s20i_d(text="A new physical SIM is detected, please select the way you want to use mobile data.").exists(10))1266 if not test_result_03:1267 FailScreenShot_file = screenShot(d=self.s20i_d, title='test019_step4_fail')1268 file = open(FailScreenShot_file, 'rb').read()1269 allure.attach(file, 'test19 step4 failed ScreenShot', allure.attachment_type.PNG)1270 if all([test_result_01, test_result_02, test_result_03]):1271 self.ws1['G20'] = "PASS"1272 else:1273 self.ws1['G20'] = "FAIL"1274 def search_wifi(self, timeout=180):1275 cur = time.time()1276 expire = cur + timeout1277 while cur < expire:1278 if not self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).exists(2): # 判断当前界面是否存在名称为“GlocalMe_OHQPJE”的wifi1279 while not self.s20i_d(resourceId="android:id/title", text="添加网络").exists(1):1280 if self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).exists(1):1281 break1282 else:1283 self.s20i_d.swipe(0.5, 0.8, 0.5, 0.3)1284 else:1285 while not self.s20i_d(resourceId="android:id/title", text="WLAN 偏好设置").exists(1):1286 if self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).exists(1):1287 break1288 else:1289 self.s20i_d.swipe(0.5, 0.3, 0.5, 0.8)1290 cur = time.time()1291 else:1292 break1293 else:1294 raise TimeoutError("wifi connect timeout.")1295 def connect_wifi(self):1296 for i in range(2):1297 self.s20i_d.press('home')1298 self.s20i_d(resourceId="com.android.systemui:id/recent_apps").click()1299 if self.s20i_d(resourceId="com.android.systemui:id/clear_all_button").exists(3):1300 self.s20i_d(resourceId="com.android.systemui:id/clear_all_button").click()1301 log.info("cleared background app success.")1302 else:1303 log.info('no background app running.')1304 self.s20i_d.press('home')1305 self.s20i_d(text="设置").click()1306 self.s20i_d(resourceId="android:id/title", text="网络和互联网").click()1307 self.s20i_d(resourceId="android:id/title", text="WLAN").click()1308 if self.s20i_d(resourceId="com.android.settings:id/switch_widget").get_text() == "关闭": # 判断wifi是否开启1309 self.s20i_d(resourceId="com.android.settings:id/switch_widget").click()1310 time.sleep(3)1311 self.search_wifi()1312 if self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).sibling(resourceId="android:id/summary", text="登录到网络").exists(3):1313 log.info("auxiliary device connect test device wifi successfully, text:登录到网络")1314 return1315 elif self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).sibling(resourceId="android:id/summary", text="已连接").exists(3):1316 log.info("auxiliary device connect test device wifi successfully, text:已连接")1317 return1318 elif self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).sibling(resourceId="android:id/summary", text="已连接,但无法访问互联网").exists(3):1319 log.info("auxiliary device connect test device wifi successfully, text:已连接,但无法访问互联网")1320 return1321 self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).click() # 点击名称为“GlocalMe”的wifi1322 if self.s20i_d(resourceId="com.android.settings:id/password").exists(3): # 判断是否弹出输入password的弹窗1323 self.s20i_d.send_keys(U3_settings.test_device_info['password'], clear=True) # 输入password1324 self.s20i_d(resourceId="android:id/button1").click()1325 elif self.s20i_d(text="取消保存").exists(3):1326 log.info("auxiliary device connect test device wifi successfully")1327 return1328 if self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).sibling(resourceId="android:id/summary", text="登录到网络").exists(3):1329 log.info("auxiliary device connect test device wifi successfully, text:登录到网络")1330 elif self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).sibling(resourceId="android:id/summary", text="已连接").exists(3):1331 log.info("auxiliary device connect test device wifi successfully, text:已连接")1332 elif self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).sibling(resourceId="android:id/summary", text="已连接,但无法访问互联网").exists(3):1333 log.info("auxiliary device connect test device wifi successfully, text:已连接,但无法访问互联网")1334 else:1335 log.error("auxiliary device connect test device wifi failed.")1336 screenShot(self.s20i_d, title="wifi_connect_fail")1337 raise ConnectionError("wifi connect error.")1338 def open_webui(self):1339 self.connect_wifi()1340 self.s20i_d(resourceId="com.android.systemui:id/center_group").click() # 返回主界面1341 self.s20i_d(text="Chrome").click() # 点击打开浏览器1342 # 判断浏览器是否第一次打开,如果第一次打开就点击设置欢迎页弹窗1343 if self.s20i_d(resourceId="com.android.chrome:id/terms_accept").exists(5):1344 try:1345 self.s20i_d(resourceId="com.android.chrome:id/terms_accept").click()1346 self.s20i_d(resourceId="com.android.chrome:id/negative_button").click()1347 self.s20i_d(resourceId="com.android.chrome:id/button_secondary").click()1348 except Exception as e:1349 log.error(e)1350 # log.info('浏览器不是第一次启动,不需要设置欢迎页')1351 # self.s20i_d(resourceId="com.android.chrome:id/home_button").click() # 点击浏览器主页按钮进入主页1352 try:1353 self.s20i_d(resourceId="com.android.chrome:id/url_bar").click() # 点击浏览器搜索框1354 except:1355 self.s20i_d(resourceId="com.android.chrome:id/search_box").click() # 点击浏览器搜索框1356 self.s20i_d.send_keys("192.168.43.1", clear=True) # 在搜索框中输入192.168.43.11357 self.s20i_d.xpath('//android.widget.ListView/android.view.ViewGroup[1]').click() # 点击进入webui界面1358 def login_webui(self):1359 if self.s20i_d(resourceId="tr_manage_my_device").exists(5):1360 self.s20i_d(resourceId="tr_manage_my_device").click() # 点击管理我的设备1361 elif self.s20i_d(text="Manage My Device").exists(5):1362 self.s20i_d(text="Manage My Device").click()1363 # 输入账号密码登陆管理界面1364 self.s20i_d(resourceId="username").click()1365 time.sleep(2)1366 self.s20i_d.click(0.342, 0.303)1367 self.s20i_d.send_keys("admin", clear=True)1368 for i in range(2):1369 self.s20i_d(resourceId="passWord").click()1370 self.s20i_d.send_keys("admin", clear=True)1371 self.s20i_d(text="Login").click()1372 def teardown(self):1373 # 每条case执行结束保存一下测试结果表1374 self.wb.save(self.test_result_file_path)1375 def teardown_class(self):1376 log.info("-" * 20 + "End Test_CloudSimAndPhysicalSimSwitch" + "-" * 20)1377 # self.d.open_notification()1378 # self.d(resourceId="com.jy.recorder:id/tv_notify_stop").click()1379 # self.start_SwitchComTool.kill()1380@pytest.mark.skip1381@allure.feature("Flash")1382class Test_Flash:1383 def setup_class(self):1384 log.info("-" * 20 + "Start Test_Flash" + "-" * 20)1385 self.u3 = models.U3(device_id=U3_settings.test_device_info['id'], log_project=log)1386 # self.g4s = models.G4S(device_id=U3_settings.G4_info['id'], log_project=log)1387 self.u3.wait_device_connect()1388 # self.g4s.wait_device_connect()1389 self._test_file = os.path.join(BASEDIR, 'config', 'test_file.zip') # 测试文件路径1390 self._test_storage_path = os.path.join(BASEDIR, 'TestCaseAndResult', 'test_storage_path') # 测试pull时文件的存放路径1391 if not os.path.exists(self._test_storage_path):1392 os.makedirs(self._test_storage_path)1393 # self._test_file_size = os.path.getsize(self._test_file)1394 self._test_file_size = round((os.path.getsize(self._test_file)/1000000), 2) # 获取测试文件大小(字节),将单位转换为MB,并保留小数点2位1395 log.info("测试文件大小:%s MB" % self._test_file_size)1396 version = self.u3.get_current_version() # 获取测试设备的版本1397 self.test_result_path = os.path.join(BASEDIR, 'TestCaseAndResult', 'TestResult', project_name)1398 if not os.path.exists(self.test_result_path):1399 os.makedirs(self.test_result_path) # 创建测试结果文件夹,并以测试版本命名1400 self.test_result_file_path = os.path.join(self.test_result_path, '.'.join([version, 'xlsx'])) # 创建一个以测试版本号命名的Excel表1401 if os.path.exists(self.test_result_file_path):1402 self.wb = load_workbook(self.test_result_file_path)1403 else:1404 # 打开测试用例表1405 self.wb = load_workbook(os.path.join(BASEDIR, 'TestCaseAndResult', 'TestCase', '整机测试内容_无屏MIFI.xlsx'))1406 self.ws = self.wb.active # 激活表1407 self.ws1 = self.wb["Flash"] # 选择表1408 def test01_push(self):1409 log.info("start %s" % sys._getframe().f_code.co_name)1410 u3_push_avg_result_list = []1411 u3_push_duration_result_list = []1412 # g4s_push_avg_result_list = []1413 for i in range(50):1414 log.info("-"*20 + "U3设备第%d次push" % (i+1) + "-"*20)1415 u3_push_start_time = time.time()1416 u3_push = self.u3.push(source_file=self._test_file, target_path='/sdcard/')1417 u3_push_end_time = time.time()1418 if u3_push:1419 u3_push_duration = round((u3_push_end_time - u3_push_start_time), 2) # 计算push时长1420 u3_push_duration_result_list.append(u3_push_duration)1421 log.info("push duration:%s" % u3_push_duration)1422 u3_push_speed = round((self._test_file_size / u3_push_duration), 2)1423 log.info("push speed:%s MB/S" % u3_push_speed) # 计算push速率1424 u3_push_avg_result_list.append(u3_push_speed)1425 else:1426 log.error("push faild.")1427 u3_push_avg_result_list.append(0)1428 time.sleep(1)1429 # log.info("-" * 20 + "G4S设备第%d次push" % (i + 1) + "-" * 20)1430 # g4s_start_time = time.time()1431 # g4s_push = self.g4s.push(source_file=self._test_file, target_path='/sdcard/') # 将测试文件push到设备sdcard目录下,返回push结果1432 # g4s_end_time = time.time()1433 # if g4s_push:1434 # g4s_push_duration = round((g4s_end_time - g4s_start_time), 2) # 计算push时长1435 # log.info("push duration:%s" % g4s_push_duration)1436 # g4s_push_speed = round((self._test_file_size / g4s_push_duration), 2)1437 # log.info("push speed:%s MB/S" % g4s_push_speed) # 计算push速率1438 # g4s_push_avg_result_list.append(g4s_push_speed)1439 # else:1440 # log.error("push faild.")1441 # g4s_push_avg_result_list.append(0)1442 # time.sleep(1)1443 log.info('u3_push_avg_result_list:%s' % str(u3_push_avg_result_list))1444 # log.info('g4s_push_avg_result_list:%s' % str(g4s_push_avg_result_list))1445 u3_push_success_list = self._remove_value_from_list(u3_push_avg_result_list, 0)1446 # g4s_push_success_list = self._remove_value_from_list(g4s_push_avg_result_list, 0)1447 if len(u3_push_success_list) != len(u3_push_avg_result_list):1448 u3_push_fail_times = len(u3_push_avg_result_list) - len(u3_push_success_list)1449 log.error("u3 push fail times: %d" % u3_push_fail_times)1450 self.ws1['H17'] = "u3 push fail times: %d" % u3_push_fail_times1451 # if len(g4s_push_success_list) != len(g4s_push_avg_result_list):1452 # g4s_push_fail_times = len(g4s_push_avg_result_list) - len(g4s_push_success_list)1453 # log.error("g4s push fail times: %d" % g4s_push_fail_times)1454 # self.ws1['H18'] = "g4s push fail times: %d" % g4s_push_fail_times1455 u3_push_avg = sum(u3_push_success_list) / len(u3_push_success_list)1456 # g4s_push_avg = sum(g4s_push_success_list) / len(g4s_push_success_list)1457 self.ws1['F17'] = round(u3_push_avg, 2)1458 # self.ws1['F18'] = round(g4s_push_avg, 2)1459 self.ws1['F32'] = len(u3_push_duration_result_list)1460 self.ws1['G32'] = round((sum(u3_push_duration_result_list) / len(u3_push_duration_result_list)), 2)1461 def test02_pull(self):1462 log.info("start %s" % sys._getframe().f_code.co_name)1463 u3_pull_result_list = []1464 # g4s_pull_result_list = []1465 u3_pull_duration_result_list = []1466 # 判断U3设备/sdcard路径下是否存在test_file.zip文件,如果不存在就push一个进去1467 if not self.u3.file_exists(file='/sdcard/test_file.zip'):1468 u3_push = self.u3.push(source_file=self._test_file, target_path='/sdcard/')1469 while not u3_push:1470 u3_push = self.u3.push(source_file=self._test_file, target_path='/sdcard/')1471 for i in range(50):1472 log.info("-"*20 + "U3设备第%d次pull" % (i+1) + "-"*20)1473 u3_pull_start_time = time.time()1474 u3_pull = self.u3.pull(source_file="/sdcard/test_file.zip", target_path=self._test_storage_path)1475 u3_pull_end_time = time.time()1476 if u3_pull:1477 u3_pull_duration = round((u3_pull_end_time - u3_pull_start_time), 2) # 计算pull时长,保留小数点后2位1478 u3_pull_duration_result_list.append(u3_pull_duration)1479 log.info("pull duration:%s" % u3_pull_duration)1480 u3_pull_speed = round((self._test_file_size / u3_pull_duration), 2) # 计算pull速度,保留小数点后2位1481 log.info("pull speed:%s" % u3_pull_speed)1482 u3_pull_result_list.append(u3_pull_speed)1483 else:1484 log.error("pull failed.")1485 u3_pull_result_list.append(0)1486 time.sleep(1)1487 log.info("u3_pull_result_list:%s" % str(u3_pull_result_list))1488 u3_pull_success_list = self._remove_value_from_list(u3_pull_result_list, 0) # 去除u3 pull结果集中为0的结果1489 if len(u3_pull_success_list) != len(u3_pull_result_list):1490 u3_pull_fail_times = len(u3_pull_result_list) - len(u3_pull_success_list) # pull 失败次数1491 log.error("u3 pull failed times: %d" % u3_pull_fail_times)1492 self.ws1['H12'] = "u3 pull failed times: %d" % u3_pull_fail_times1493 u3_pull_avg = round((sum(u3_pull_success_list) / len(u3_pull_success_list)), 2)1494 self.ws1['F12'] = u3_pull_avg1495 self.ws1['F31'] = len(u3_pull_duration_result_list)1496 self.ws1['G31'] = round((sum(u3_pull_duration_result_list) / len(u3_pull_duration_result_list)), 2)1497 '''1498 # 判断G4S设备/sdcard路径下是否存在test_file.zip文件,如果不存在就push一个进去1499 if not self.g4s.file_exists(file='/sdcard/test_file.zip'):1500 g4s_push = self.g4s.push(source_file=self._test_file, target_path='/sdcard/')1501 while not g4s_push:1502 g4s_push = self.g4s.push(source_file=self._test_file, target_path='/sdcard/')1503 for i in range(50):1504 log.info("-" * 20 + "G4S设备第%d次pull" % (i + 1) + "-" * 20)1505 g4s_pull_start_time = time.time()1506 g4s_pull = self.g4s.pull(source_file="/sdcard/test_file.zip", target_path=self._test_storage_path)1507 g4s_pull_end_time = time.time()1508 if g4s_pull:1509 g4s_pull_duration = round((g4s_pull_end_time - g4s_pull_start_time), 2) # 计算pull时长,保留小数点后2位1510 log.info("pull duration:%s" % g4s_pull_duration)1511 g4s_pull_speed = round((self._test_file_size / g4s_pull_duration), 2) # 计算pull速度,保留小数点后2位1512 log.info("pull speed:%s" % g4s_pull_speed)1513 g4s_pull_result_list.append(g4s_pull_speed)1514 else:1515 log.error("pull failed.")1516 g4s_pull_result_list.append(0)1517 time.sleep(1)1518 log.info("g4s_pull_result_list:%s" % str(g4s_pull_result_list))1519 g4s_pull_success_list = self._remove_value_from_list(g4s_pull_result_list, 0) # 去除g4s pull结果集中为0的结果1520 if len(g4s_pull_success_list) != len(g4s_pull_result_list):1521 g4s_pull_fail_times = len(g4s_pull_result_list) - len(g4s_pull_success_list) # pull 失败次数1522 log.error("g4s pull failed times: %d" % g4s_pull_fail_times)1523 self.ws1['H13'] = "g4s pull failed times: %d" % g4s_pull_fail_times1524 g4s_pull_avg = round((sum(g4s_pull_success_list) / len(g4s_pull_success_list)), 2) # 计算pull成功结果的平均值,保留小数点2位1525 self.ws1['F13'] = g4s_pull_avg1526 '''1527 def teardown(self):1528 # 每条case执行结束保存一下测试结果表1529 self.wb.save(self.test_result_file_path)1530 def teardown_class(self):1531 log.info("-" * 20 + "End Test_Flash" + "-" * 20)1532 def _remove_value_from_list(self, list, value):1533 for i in list:1534 if i == value:1535 list.remove(i)1536 return list1537@pytest.mark.skip1538@allure.feature("性能指标")1539class Test_PerformanceIndex:1540 def setup_class(self):1541 log.info("-" * 20 + "Start Test_PerformanceIndex" + "-" * 20)1542 self.u3 = models.U3(device_id=U3_settings.test_device_info['id'], log_project=log)1543 self.u3.wait_device_connect()1544 version = self.u3.get_current_version() # 获取测试设备的版本1545 self.test_result_path = os.path.join(BASEDIR, 'TestCaseAndResult', 'TestResult', project_name)1546 if not os.path.exists(self.test_result_path):1547 os.makedirs(self.test_result_path) # 创建测试结果文件夹,并以测试版本命名1548 self.test_result_file_path = os.path.join(self.test_result_path, '.'.join([version, 'xlsx'])) # 创建一个以测试版本号命名的Excel表1549 if os.path.exists(self.test_result_file_path):1550 self.wb = load_workbook(self.test_result_file_path)1551 else:1552 # 打开测试用例表1553 self.wb = load_workbook(os.path.join(BASEDIR, 'TestCaseAndResult', 'TestCase', '整机测试内容_无屏MIFI.xlsx'))1554 self.ws = self.wb.active # 激活表1555 self.ws1 = self.wb["性能指标"] # 选择表1556 def test01(self):1557 '''测试用例:重启'''1558 pass1559 def teardown(self):1560 # 每条case执行结束保存一下测试结果表1561 self.wb.save(self.test_result_file_path)1562 def teardown_class(self):1563 log.info("-" * 20 + "End Test_PerformanceIndex" + "-" * 20)1564@allure.feature("显示")1565class Test_Display:1566 def setup_class(self):1567 log.info("-" * 20 + "Start Test_Display" + "-" * 20)1568 self.u3 = models.U3(device_id=U3_settings.test_device_info['id'], log_project=log)1569 self.s20i = models.Glocalme(device_id=U3_settings.auxiliary_device_info['id'], log_project=log)1570 self.u3.wait_device_connect()1571 self.s20i.wait_device_connect()1572 self.version = self.u3.get_current_version() # 获取测试设备的版本1573 self.test_result_path = os.path.join(BASEDIR, 'TestCaseAndResult', 'TestResult', project_name)1574 if not os.path.exists(self.test_result_path):1575 os.makedirs(self.test_result_path) # 创建测试结果文件夹,并以测试版本命名1576 self.test_result_file_path = os.path.join(self.test_result_path, '.'.join([self.version, 'xlsx'])) # 创建一个以测试版本号命名的Excel表1577 if os.path.exists(self.test_result_file_path):1578 self.wb = load_workbook(self.test_result_file_path)1579 else:1580 # 打开测试用例表1581 self.wb = load_workbook(os.path.join(BASEDIR, 'TestCaseAndResult', 'TestCase', '整机测试内容_无屏MIFI.xlsx'))1582 self.ws = self.wb.active # 激活表1583 self.ws1 = self.wb["显示"] # 选择表1584 # 执行uiautomator2的init操作,在测试设备端安装uiautomator app,minicap和minitouch,atx-agent1585 uiautomator2_init = subprocess.getoutput("python -m uiautomator2 init")1586 self.s20i_d = u2.connect('c58790e3')1587 self.s20i.wakey() # 设置辅助机屏幕常亮1588 # 判断S20i屏幕是否锁屏状态,如果锁屏就给设备解锁(仅适用滑动解锁)1589 if self.s20i_d(resourceId="com.android.systemui:id/lock_icon").exists():1590 self.s20i_d.xpath('//android.widget.FrameLayout').click()1591 self.s20i_d(resourceId="com.android.systemui:id/lock_icon").click()1592 # '''查找并连接wifi'''1593 # for i in range(2):1594 # self.s20i_d.press('home')1595 # # 杀掉后台程序1596 # self.s20i_d(resourceId="com.android.systemui:id/recent_apps").click()1597 # if self.s20i_d(resourceId="com.android.systemui:id/clear_all_button").exists(3):1598 # self.s20i_d(resourceId="com.android.systemui:id/clear_all_button").click()1599 # log.info("cleared background app success.")1600 # else:1601 # log.info('no background app running.')1602 # '''进入wifi设置界面查找wifi并连接wifi'''1603 # self.s20i_d.press('home')1604 # self.s20i_d(text="设置").click()1605 # self.s20i_d(resourceId="android:id/title", text="网络和互联网").click()1606 # self.s20i_d(resourceId="android:id/title", text="WLAN").click()1607 # if self.s20i_d(resourceId="com.android.settings:id/switch_widget").get_text() == "关闭": # 判断wifi是否开启1608 # self.s20i_d(resourceId="com.android.settings:id/switch_widget").click()1609 # time.sleep(3)1610 # cur = time.time()1611 # expire = cur + 1801612 # while cur < expire:1613 # if not self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).exists(2): # 判断当前界面是否存在名称为“GlocalMe_OHQPJE”的wifi1614 # while not self.s20i_d(resourceId="android:id/title", text="添加网络").exists(1):1615 # if self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).exists(1):1616 # break1617 # else:1618 # self.s20i_d.swipe(0.5, 0.8, 0.5, 0.3)1619 # else:1620 # while not self.s20i_d(resourceId="android:id/title", text="WLAN 偏好设置").exists(1):1621 # if self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).exists(1622 # 1):1623 # break1624 # else:1625 # self.s20i_d.swipe(0.5, 0.3, 0.5, 0.8)1626 # cur = time.time()1627 # else:1628 # break1629 # else:1630 # raise TimeoutError("wifi connect timeout.")1631 # if self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).sibling(resourceId="android:id/summary", text="登录到网络").exists(3):1632 # log.info("auxiliary device connect test device wifi successfully, text:登录到网络")1633 # return1634 # elif self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).sibling(resourceId="android:id/summary", text="已连接").exists(3):1635 # log.info("auxiliary device connect test device wifi successfully, text:已连接")1636 # return1637 # elif self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).sibling(resourceId="android:id/summary", text="已连接,但无法访问互联网").exists(3):1638 # log.info("auxiliary device connect test device wifi successfully, text:已连接,但无法访问互联网")1639 # return1640 # self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).click() # 点击名称为“GlocalMe”的wifi1641 # if self.s20i_d(resourceId="com.android.settings:id/password").exists(3): # 判断是否弹出输入password的弹窗1642 # self.s20i_d.send_keys(U3_settings.test_device_info['password'], clear=True) # 输入password1643 # self.s20i_d(resourceId="android:id/button1").click()1644 # elif self.s20i_d(text="取消保存").exists(3):1645 # log.info("auxiliary device connect test device wifi successfully")1646 # return1647 # if self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).sibling(resourceId="android:id/summary", text="登录到网络").exists(3):1648 # log.info("auxiliary device connect test device wifi successfully, text:登录到网络")1649 # elif self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).sibling(resourceId="android:id/summary", text="已连接").exists(3):1650 # log.info("auxiliary device connect test device wifi successfully, text:已连接")1651 # elif self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).sibling(resourceId="android:id/summary", text="已连接,但无法访问互联网").exists(3):1652 # log.info("auxiliary device connect test device wifi successfully, text:已连接,但无法访问互联网")1653 # else:1654 # log.error("auxiliary device connect test device wifi failed.")1655 # screenShot(self.s20i_d, title="wifi_connect_fail")1656 # raise ConnectionError("wifi connect error.")1657 # '''进入webui首页'''1658 # self.s20i_d(resourceId="com.android.systemui:id/center_group").click() # 返回主界面1659 # self.s20i_d(text="Chrome").click() # 点击打开浏览器1660 # # 判断浏览器是否第一次打开,如果第一次打开就点击设置欢迎页弹窗1661 # if self.s20i_d(resourceId="com.android.chrome:id/terms_accept").exists(5):1662 # try:1663 # self.s20i_d(resourceId="com.android.chrome:id/terms_accept").click()1664 # self.s20i_d(resourceId="com.android.chrome:id/negative_button").click()1665 # self.s20i_d(resourceId="com.android.chrome:id/button_secondary").click()1666 # except Exception as e:1667 # log.error(e)1668 # # log.info('浏览器不是第一次启动,不需要设置欢迎页')1669 # # self.s20i_d(resourceId="com.android.chrome:id/home_button").click() # 点击浏览器主页按钮进入主页1670 # try:1671 # self.s20i_d(resourceId="com.android.chrome:id/url_bar").click() # 点击浏览器搜索框1672 # except:1673 # self.s20i_d(resourceId="com.android.chrome:id/search_box").click() # 点击浏览器搜索框1674 # self.s20i_d.send_keys("192.168.43.1", clear=True) # 在搜索框中输入192.168.43.11675 # self.s20i_d.xpath('//android.widget.ListView/android.view.ViewGroup[1]').click() # 点击进入webui界面1676 # time.sleep(3)1677 def test01(self):1678 '''测试用例:卡状态'''1679 log.info("start %s" % sys._getframe().f_code.co_name)1680 card_info_list = [1681 "In Use: Cloud SIM",1682 "In Use: Cloud SIM(Manual)",1683 "In Use: SIM 1",1684 "In Use: SIM 1(Manual)",1685 ]1686 status_info_list = [1687 "Status: Connecting...",1688 "Status: Connected",1689 "Status: Disconnect",1690 ]1691 self.open_webui()1692 time.sleep(3)1693 card_info = self.s20i_d(resourceId="div_manage_my_device").child().child()[0].child().get_text() # 获取In Use 信息1694 log.info("card_info:%s" % card_info)1695 status_info = self.s20i_d(resourceId="div_manage_my_device").child().child()[1].child().get_text() # 获取Status 信息1696 log.info("status_info:%s" % status_info)1697 test_result_01 = pytest.assume(card_info in card_info_list)1698 test_result_02 = pytest.assume(status_info in status_info_list)1699 test_result_03 = pytest.assume(self.s20i_d(text="Manage My Device").exists(3))1700 if all([test_result_01, test_result_02, test_result_03]):1701 self.ws1['G8'] = "PASS"1702 else:1703 self.ws1['G8'] = "FAIL"1704 FailScreenShot_file = screenShot(d=self.s20i_d, title='test01_CardStatus_fail')1705 file = open(FailScreenShot_file, 'rb').read()1706 allure.attach(file, 'test01_CardStatus failed ScreenShot', allure.attachment_type.PNG)1707 def test02(self):1708 '''测试用例:WiFi信息及版本'''1709 log.info("start %s" % sys._getframe().f_code.co_name)1710 display_name = [1711 "Wi-Fi SSID:",1712 "Client Num:",1713 "Version:",1714 ]1715 self.open_webui()1716 time.sleep(3)1717 name01 = self.s20i_d(resourceId="status_info").child()[12].get_text() # 获取ssid显示的名称1718 name02 = self.s20i_d(resourceId="status_info").child()[14].get_text() # 获取客户端数量显示的名称1719 name03 = self.s20i_d(resourceId="status_info").child()[16].get_text() # 获取版本信息显示的名称1720 log.info("ssid显示的名称:%s, 客户端数量显示的名称:%s, 版本信息显示的名称:%s" % (name01, name02, name03))1721 ssid = self.s20i_d(resourceId="status_info").child()[13].get_text() # 获取ssid1722 client_num = self.s20i_d(resourceId="status_info").child()[15].get_text() # 获取客户端连接数1723 version = self.s20i_d(resourceId="status_info").child()[17].get_text() # 获取版本号1724 log.info("ssid:%s, client_num:%s, version:%s" % (ssid, client_num, version))1725 test_result_01 = pytest.assume(name01 == display_name[0])1726 test_result_02 = pytest.assume(name02 == display_name[1])1727 test_result_03 = pytest.assume(name03 == display_name[2])1728 test_result_04 = pytest.assume(ssid == U3_settings.test_device_info['ssid'])1729 test_result_05 = pytest.assume(int(client_num) > 0)1730 test_result_06 = pytest.assume(version[0:-4] in self.version)1731 if all([test_result_01, test_result_02, test_result_03, test_result_04, test_result_05, test_result_06]):1732 self.ws1['G9'] = "PASS"1733 else:1734 self.ws1['G9'] = "FAIL"1735 FailScreenShot_file = screenShot(d=self.s20i_d, title='test02_fail')1736 file = open(FailScreenShot_file, 'rb').read()1737 allure.attach(file, 'test02 test failed ScreenShot', allure.attachment_type.PNG)1738 def test03(self):1739 '''测试用例:WiFi名称'''1740 log.info("start %s" % sys._getframe().f_code.co_name)1741 self.open_webui()1742 self.login_webui()1743 time.sleep(3)1744 ssid = self.s20i_d(resourceId="ssid").get_text()1745 log.info("Wi-Fi SSID:%s" % ssid)1746 test_result = pytest.assume(ssid = U3_settings.test_device_info['ssid'])1747 if test_result:1748 self.ws1['G10'] = "PASS"1749 else:1750 self.ws1['G10'] = "FAIL"1751 FailScreenShot_file = screenShot(d=self.s20i_d, title='test03_fail')1752 file = open(FailScreenShot_file, 'rb').read()1753 allure.attach(file, 'test03 test failed ScreenShot', allure.attachment_type.PNG)1754 def test04(self):1755 '''测试用例:WiFi密码'''1756 log.info("start %s" % sys._getframe().f_code.co_name)1757 self.open_webui()1758 self.login_webui()1759 time.sleep(3)1760 password = self.s20i_d(resourceId="password").get_text()1761 log.info("Password:%s" % password)1762 test_result = pytest.assume(password = U3_settings.test_device_info['password'])1763 if test_result:1764 self.ws1['G11'] = "PASS"1765 else:1766 self.ws1['G11'] = "FAIL"1767 FailScreenShot_file = screenShot(d=self.s20i_d, title='test04_fail')1768 file = open(FailScreenShot_file, 'rb').read()1769 allure.attach(file, 'test04 test failed ScreenShot', allure.attachment_type.PNG)1770 def test05(self):1771 '''测试用例:套餐显示以及卡状态'''1772 log.info("start %s" % sys._getframe().f_code.co_name)1773 card_info_list = [1774 "In Use: Cloud SIM",1775 "In Use: Cloud SIM(Manual)",1776 "In Use: SIM 1",1777 "In Use: SIM 1(Manual)",1778 ]1779 status_info_list = [1780 "Status: Connecting...",1781 "Status: Connected",1782 "Status: Disconnect",1783 ]1784 self.open_webui()1785 self.login_webui()1786 time.sleep(3)1787 card_info = self.s20i_d(resourceId="div_wifi_device_info").child().child()[0].child().get_text()1788 status_info = self.s20i_d(resourceId="div_wifi_device_info").child().child()[1].child().get_text()1789 log.info("card_info:%s, status_info:%s" % (card_info, status_info))1790 test_result_01 = pytest.assume(card_info in card_info_list)1791 test_result_02 = pytest.assume(status_info in status_info_list)1792 if all([test_result_01, test_result_02]):1793 self.ws1['G12'] = "PASS"1794 else:1795 self.ws1['G12'] = "FAIL"1796 FailScreenShot_file = screenShot(d=self.s20i_d, title='test05_fail')1797 file = open(FailScreenShot_file, 'rb').read()1798 allure.attach(file, 'test05 test failed ScreenShot', allure.attachment_type.PNG)1799 def test06(self):1800 '''测试用例:显示连接设备数'''1801 log.info("start %s" % sys._getframe().f_code.co_name)1802 self.open_webui()1803 self.login_webui()1804 self.s20i_d(text="Wi-Fi clients").click()1805 time.sleep(3)1806 client_connect_info = self.s20i_d(resourceId="div_list_info").child().get_text() # 获取UI界面显示的客户端连接信息1807 client_num = self.s20i_d(resourceId="ul_list").info['childCount'] # 获取连接的设备数量1808 expire_connect_info = ' '.join([str(client_num), 'devices are securely connected to Internet...']) # 预期UI界面显示的客户端连接信息1809 test_result = pytest.assume(client_connect_info == expire_connect_info)1810 if test_result:1811 self.ws1['G13'] = "PASS"1812 else:1813 self.ws1['G13'] = "FAIL"1814 FailScreenShot_file = screenShot(d=self.s20i_d, title='test06_fail')1815 file = open(FailScreenShot_file, 'rb').read()1816 allure.attach(file, 'test06 test failed ScreenShot', allure.attachment_type.PNG)1817 def test07(self):1818 '''测试用例:显示连接设备品牌'''1819 log.info("start %s" % sys._getframe().f_code.co_name)1820 self.open_webui()1821 self.login_webui()1822 self.s20i_d(text="Wi-Fi clients").click()1823 time.sleep(3)1824 brand_list = [1825 "Other Devices",1826 "Apple Devices",1827 ]1828 test_result_list = [] # 创建一个测试结果集1829 acquired_brand_list = [] # 创建一个获取到的品牌集1830 child_object = self.s20i_d(resourceId="ul_list").child() # 获取resourceId="ul_list"的对象的所有子对象1831 # print(len(child_object))1832 client_num = int(len(child_object) / 6) # 根据获取到的子对象来计算连接的客户端数量1833 for i in range(client_num):1834 brand = self.s20i_d(resourceId="ul_list").child()[2 + 6 * i].get_text() # 获取每个客户端的设备品牌1835 acquired_brand_list.append(brand) # 将获取到的每个客户端的设备品牌加入到acquired_brand_list1836 test_result = pytest.assume(brand in brand_list) # 判断获取的每个客户端的设备品牌是否在品牌集中1837 test_result_list.append(test_result) # 将测试结果加入测试结果集1838 log.info("acquired_brand_list:%s" % str(acquired_brand_list))1839 log.info("test_result_list:%s" % str(test_result_list))1840 if all(test_result_list):1841 self.ws1['G14'] = "PASS"1842 else:1843 self.ws1['G14'] = "FAIL"1844 FailScreenShot_file = screenShot(d=self.s20i_d, title='test07_fail')1845 file = open(FailScreenShot_file, 'rb').read()1846 allure.attach(file, 'test07 test failed ScreenShot', allure.attachment_type.PNG)1847 def test08(self):1848 '''测试用例:显示黑名单设备'''1849 log.info("start %s" % sys._getframe().f_code.co_name)1850 self.open_webui()1851 self.login_webui()1852 self.s20i_d(text="Wi-Fi clients").click()1853 time.sleep(3)1854 if self.s20i_d(resourceId="div_wifi_black_lists").exists(3):1855 self.s20i_d(resourceId="div_wifi_black_lists").click()1856 test_result = pytest.assume(self.s20i_d(resourceId="ul_list").exists(3))1857 if test_result:1858 self.ws1['G15'] = "PASS"1859 else:1860 self.ws1['G15'] = "FAIL"1861 FailScreenShot_file = screenShot(d=self.s20i_d, title='test08_fail')1862 file = open(FailScreenShot_file, 'rb').read()1863 allure.attach(file, 'test08 test failed ScreenShot', allure.attachment_type.PNG)1864 else:1865 self.ws1['G15'] = "NA"1866 self.ws1['H15'] = "UI界面没有显示黑名单列表"1867 assert False1868 def test09(self):1869 '''测试用例:设备加入黑名单开关'''1870 log.info("start %s" % sys._getframe().f_code.co_name)1871 self.open_webui()1872 self.login_webui()1873 self.s20i_d(text="Wi-Fi clients").click()1874 time.sleep(3)1875 test_result_list = [] # 创建一个测试结果集1876 client_num = self.s20i_d(resourceId="ul_list").info['childCount'] # 获取连接的设备数量1877 for i in range(client_num):1878 resourceId = '_'.join(['wifi_client_lists', str(i)]) # 每个客户端加入黑名单开关的resourceId1879 test_result = pytest.assume(self.s20i_d(resourceId=resourceId).exists(3)) # 判断每个客户端加入黑名单的开关是否存在1880 test_result_list.append(test_result)1881 log.info("test_result_list:%s" % str(test_result_list))1882 if all(test_result_list):1883 self.ws1['G16'] = "PASS"1884 else:1885 self.ws1['G16'] = "FAIL"1886 FailScreenShot_file = screenShot(d=self.s20i_d, title='test09_fail')1887 file = open(FailScreenShot_file, 'rb').read()1888 allure.attach(file, 'test09 test failed ScreenShot', allure.attachment_type.PNG)1889 def test10(self):1890 '''测试用例:连接设备的MAC地址'''1891 log.info("start %s" % sys._getframe().f_code.co_name)1892 self.open_webui()1893 self.login_webui()1894 self.s20i_d(text="Wi-Fi clients").click()1895 time.sleep(3)1896 test_result_list = [] # 创建一个测试结果集1897 acquired_mac_list = [] # 创建一个获取到的品牌集1898 child_object = self.s20i_d(resourceId="ul_list").child() # 获取resourceId="ul_list"的对象的所有子对象1899 # print(len(child_object))1900 client_num = int(len(child_object) / 6) # 根据获取到的子对象来计算连接的客户端数量1901 for i in range(client_num):1902 mac = self.s20i_d(resourceId="ul_list").child()[3 + 6 * i].get_text() # 获取每个客户端的设备MAC地址1903 acquired_mac_list.append(mac) # 将获取到的每个客户端的设备MAC地址加入到acquired_mac_list1904 test_result = pytest.assume(len(mac) == 17) # 判断获取的每个客户端的MAC地址字符串长度是否为171905 test_result_list.append(test_result) # 将测试结果加入测试结果集1906 log.info("acquired_mac_list:%s" % str(acquired_mac_list))1907 log.info("test_result_list:%s" % str(test_result_list))1908 if all(test_result_list):1909 self.ws1['G17'] = "PASS"1910 else:1911 self.ws1['G17'] = "FAIL"1912 FailScreenShot_file = screenShot(d=self.s20i_d, title='test10_fail')1913 file = open(FailScreenShot_file, 'rb').read()1914 allure.attach(file, 'test10 test failed ScreenShot', allure.attachment_type.PNG)1915 def test11(self):1916 '''测试用例:设置界面UI显示'''1917 log.info("start %s" % sys._getframe().f_code.co_name)1918 self.open_webui()1919 self.login_webui()1920 self.s20i_d(text="Settings").click()1921 time.sleep(3)1922 test_result_list = []1923 test_result_01 = pytest.assume(self.s20i_d(text="Web administrator").exists(3)) # 判断设置界面是否显示UI “Web administrator”1924 test_result_list.append(test_result_01)1925 if test_result_01:1926 self.ws1['G18'] = "PASS"1927 else:1928 self.ws1['G18'] = "FAIL"1929 test_result_02 = pytest.assume(self.s20i_d(text="SIM card management").exists(3)) # 判断设置界面是否显示UI “SIM card management”1930 test_result_list.append(test_result_02)1931 if test_result_02:1932 self.ws1['G19'] = "PASS"1933 else:1934 self.ws1['G19'] = "FAIL"1935 test_result_03 = pytest.assume(self.s20i_d(text="Data management").exists(3)) # 判断设置界面是否显示UI “Data management”1936 test_result_list.append(test_result_03)1937 if test_result_03:1938 self.ws1['G20'] = "PASS"1939 else:1940 self.ws1['G20'] = "FAIL"1941 test_result_04 = pytest.assume(self.s20i_d(text="Language settings").exists(3) and self.s20i_d(text="English").exists(3)) # 判断设置界面是否显示UI “Language settings”和“English”1942 test_result_list.append(test_result_04)1943 if test_result_04:1944 self.ws1['G21'] = "PASS"1945 else:1946 self.ws1['G21'] = "FAIL"1947 test_result_05 = pytest.assume(self.s20i_d(text="Restore to factory defaults").exists(3)) # 判断设置界面是否显示UI “Restore to factory defaults”1948 test_result_list.append(test_result_05)1949 if test_result_05:1950 self.ws1['G22'] = "PASS"1951 else:1952 self.ws1['G22'] = "FAIL"1953 test_result_06 = pytest.assume(self.s20i_d(text="Logout").exists(3)) # 判断设置界面是否显示UI “Logout”1954 test_result_list.append(test_result_06)1955 if test_result_06:1956 self.ws1['G23'] = "PASS"1957 else:1958 self.ws1['G23'] = "FAIL"1959 test_result_07 = pytest.assume(self.s20i_d(text="About").exists(3)) # 判断设置界面是否显示UI “About”1960 test_result_list.append(test_result_07)1961 if test_result_07:1962 self.ws1['G24'] = "PASS"1963 else:1964 self.ws1['G24'] = "FAIL"1965 log.info("test_result_list:%s" % str(test_result_list))1966 if not all(test_result_list):1967 FailScreenShot_file = screenShot(d=self.s20i_d, title='test11_fail')1968 file = open(FailScreenShot_file, 'rb').read()1969 allure.attach(file, 'test11 test failed ScreenShot', allure.attachment_type.PNG)1970 def teardown(self):1971 # 每条case执行结束保存一下测试结果表1972 self.wb.save(self.test_result_file_path)1973 def teardown_class(self):1974 log.info("-" * 20 + "End Test_Display" + "-" * 20)1975 def search_wifi(self, timeout=180):1976 cur = time.time()1977 expire = cur + timeout1978 while cur < expire:1979 if not self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).exists(2): # 判断当前界面是否存在名称为“GlocalMe_OHQPJE”的wifi1980 while not self.s20i_d(resourceId="android:id/title", text="添加网络").exists(1):1981 if self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).exists(1):1982 break1983 else:1984 self.s20i_d.swipe(0.5, 0.8, 0.5, 0.3)1985 else:1986 while not self.s20i_d(resourceId="android:id/title", text="WLAN 偏好设置").exists(1):1987 if self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).exists(1):1988 break1989 else:1990 self.s20i_d.swipe(0.5, 0.3, 0.5, 0.8)1991 cur = time.time()1992 else:1993 break1994 else:1995 raise TimeoutError("wifi connect timeout.")1996 def connect_wifi(self):1997 for i in range(2):1998 self.s20i_d.press('home')1999 self.s20i_d(resourceId="com.android.systemui:id/recent_apps").click()2000 if self.s20i_d(resourceId="com.android.systemui:id/clear_all_button").exists(3):2001 self.s20i_d(resourceId="com.android.systemui:id/clear_all_button").click()2002 log.info("cleared background app success.")2003 else:2004 log.info('no background app running.')2005 self.s20i_d.press('home')2006 self.s20i_d(text="设置").click()2007 self.s20i_d(resourceId="android:id/title", text="网络和互联网").click()2008 self.s20i_d(resourceId="android:id/title", text="WLAN").click()2009 if self.s20i_d(resourceId="com.android.settings:id/switch_widget").get_text() == "关闭": # 判断wifi是否开启2010 self.s20i_d(resourceId="com.android.settings:id/switch_widget").click()2011 time.sleep(3)2012 self.search_wifi()2013 if self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).sibling(resourceId="android:id/summary", text="登录到网络").exists(3):2014 log.info("auxiliary device connect test device wifi successfully, text:登录到网络")2015 return2016 elif self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).sibling(resourceId="android:id/summary", text="已连接").exists(3):2017 log.info("auxiliary device connect test device wifi successfully, text:已连接")2018 return2019 elif self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).sibling(resourceId="android:id/summary", text="已连接,但无法访问互联网").exists(3):2020 log.info("auxiliary device connect test device wifi successfully, text:已连接,但无法访问互联网")2021 return2022 self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).click() # 点击名称为“GlocalMe”的wifi2023 if self.s20i_d(resourceId="com.android.settings:id/password").exists(3): # 判断是否弹出输入password的弹窗2024 self.s20i_d.send_keys(U3_settings.test_device_info['password'], clear=True) # 输入password2025 self.s20i_d(resourceId="android:id/button1").click()2026 elif self.s20i_d(text="取消保存").exists(3):2027 log.info("auxiliary device connect test device wifi successfully")2028 return2029 if self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).sibling(resourceId="android:id/summary", text="登录到网络").exists(3):2030 log.info("auxiliary device connect test device wifi successfully, text:登录到网络")2031 elif self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).sibling(resourceId="android:id/summary", text="已连接").exists(3):2032 log.info("auxiliary device connect test device wifi successfully, text:已连接")2033 elif self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).sibling(resourceId="android:id/summary", text="已连接,但无法访问互联网").exists(3):2034 log.info("auxiliary device connect test device wifi successfully, text:已连接,但无法访问互联网")2035 else:2036 log.error("auxiliary device connect test device wifi failed.")2037 screenShot(self.s20i_d, title="wifi_connect_fail")2038 raise ConnectionError("wifi connect error.")2039 def open_webui(self):2040 self.connect_wifi()2041 self.s20i_d(resourceId="com.android.systemui:id/center_group").click() # 返回主界面2042 self.s20i_d(text="Chrome").click() # 点击打开浏览器2043 # 判断浏览器是否第一次打开,如果第一次打开就点击设置欢迎页弹窗2044 if self.s20i_d(resourceId="com.android.chrome:id/terms_accept").exists(5):2045 try:2046 self.s20i_d(resourceId="com.android.chrome:id/terms_accept").click()2047 self.s20i_d(resourceId="com.android.chrome:id/negative_button").click()2048 self.s20i_d(resourceId="com.android.chrome:id/button_secondary").click()2049 except Exception as e:2050 log.error(e)2051 # log.info('浏览器不是第一次启动,不需要设置欢迎页')2052 # self.s20i_d(resourceId="com.android.chrome:id/home_button").click() # 点击浏览器主页按钮进入主页2053 try:2054 self.s20i_d(resourceId="com.android.chrome:id/url_bar").click() # 点击浏览器搜索框2055 except:2056 self.s20i_d(resourceId="com.android.chrome:id/search_box").click() # 点击浏览器搜索框2057 self.s20i_d.send_keys("192.168.43.1", clear=True) # 在搜索框中输入192.168.43.12058 self.s20i_d.xpath('//android.widget.ListView/android.view.ViewGroup[1]').click() # 点击进入webui界面2059 def login_webui(self):2060 if self.s20i_d(resourceId="tr_manage_my_device").exists(5):2061 self.s20i_d(resourceId="tr_manage_my_device").click() # 点击管理我的设备2062 elif self.s20i_d(text="Manage My Device").exists(5):2063 self.s20i_d(text="Manage My Device").click()2064 # 输入账号密码登陆管理界面2065 self.s20i_d(resourceId="username").click()2066 time.sleep(2)2067 self.s20i_d.click(0.342, 0.303)2068 self.s20i_d.send_keys("admin", clear=True)2069 for i in range(2):2070 self.s20i_d(resourceId="passWord").click()2071 self.s20i_d.send_keys("admin", clear=True)2072 self.s20i_d(text="Login").click()2073@allure.feature("加入云卡后的稳定性")2074class Test_SystemStability:2075 def setup_class(self):2076 log.info("-" * 20 + "Start Test_SystemStability" + "-" * 20)2077 self.u3 = models.U3(device_id=U3_settings.test_device_info['id'], log_project=log)2078 self.s20i = models.Glocalme(device_id=U3_settings.auxiliary_device_info['id'], log_project=log)2079 self.u3.wait_device_connect()2080 self.s20i.wait_device_connect()2081 self.version = self.u3.get_current_version() # 获取测试设备的版本2082 self.test_result_path = os.path.join(BASEDIR, 'TestCaseAndResult', 'TestResult', project_name)2083 if not os.path.exists(self.test_result_path):2084 os.makedirs(self.test_result_path) # 创建测试结果文件夹,并以测试版本命名2085 self.test_result_file_path = os.path.join(self.test_result_path,'.'.join([self.version, 'xlsx'])) # 创建一个以测试版本号命名的Excel表2086 if os.path.exists(self.test_result_file_path):2087 self.wb = load_workbook(self.test_result_file_path)2088 else:2089 # 打开测试用例表2090 self.wb = load_workbook(os.path.join(BASEDIR, 'TestCaseAndResult', 'TestCase', '整机测试内容_无屏MIFI.xlsx'))2091 self.ws = self.wb.active # 激活表2092 self.ws1 = self.wb["加入云卡后的稳定性"] # 选择表2093 # 执行uiautomator2的init操作,在测试设备端安装uiautomator app,minicap和minitouch,atx-agent2094 uiautomator2_init = subprocess.getoutput("python -m uiautomator2 init")2095 self.s20i_d = u2.connect('c58790e3')2096 self.s20i.wakey() # 设置辅助机屏幕常亮2097 # 判断S20i屏幕是否锁屏状态,如果锁屏就给设备解锁(仅适用滑动解锁)2098 if self.s20i_d(resourceId="com.android.systemui:id/lock_icon").exists():2099 self.s20i_d.xpath('//android.widget.FrameLayout').click()2100 self.s20i_d(resourceId="com.android.systemui:id/lock_icon").click()2101 @pytest.mark.skip2102 def test01(self):2103 '''测试用例:开关机(云卡)100次'''2104 log.info("start %s" % sys._getframe().f_code.co_name)2105 login_type = self.u3.login_type()2106 if login_type != 1:2107 self.open_webui()2108 self.login_webui()2109 self.s20i_d(text="Settings").click()2110 self.s20i_d(text="SIM card management").click()2111 self.s20i_d(resourceId="sim_select").click()2112 self.s20i_d(resourceId="text_sim_0").click() # 选择云卡2113 self.s20i_d(text="Apply").click()2114 self.u3.wait_network_connect()2115 time.sleep(3)2116 assert self.u3.login_type()==12117 test_success_times = 02118 for i in range(100):2119 log.info("-" * 20 + "第%d次重启测试" % (i + 1) + "-" * 20)2120 self.u3.reboot()2121 time.sleep(5)2122 self.u3.wait_device_connect()2123 self.u3.wait_network_connect()2124 time.sleep(3)2125 login_type_01 = self.u3.login_type()2126 test_result = pytest.assume(login_type_01==1)2127 if test_result:2128 test_success_times += 12129 else:2130 self.ws1['K2'] = "FAIL"2131 self.ws1['L2'] = "重启测试成功次数:%d" % test_success_times2132 log.error("test_result:%s, u3 login type:%s, test success times:%d" % (test_result, login_type_01, test_success_times))2133 assert False2134 self.ws1['K2'] = "PASS"2135 def test09(self):2136 '''测试用例:关闭云卡后实体卡上网'''2137 log.info("start %s" % sys._getframe().f_code.co_name)2138 login_type = self.u3.login_type()2139 if login_type != 1:2140 self.open_webui()2141 self.login_webui()2142 self.s20i_d(text="Settings").click()2143 self.s20i_d(text="SIM card management").click()2144 self.s20i_d(resourceId="sim_select").click()2145 self.s20i_d(resourceId="text_sim_0").click() # 选择云卡2146 self.s20i_d(text="Apply").click()2147 time.sleep(5)2148 self.u3.wait_network_connect()2149 time.sleep(3)2150 assert self.u3.login_type() == 12151 time.sleep(30)2152 self.open_webui()2153 self.login_webui()2154 self.s20i_d(text="Settings").click()2155 self.s20i_d(text="SIM card management").click()2156 self.s20i_d(resourceId="sim_select").click()2157 self.s20i_d(resourceId="text_sim_1").click() # 选择实体卡卡2158 self.s20i_d(text="Apply").click()2159 time.sleep(5)2160 self.u3.wait_network_connect()2161 time.sleep(3)2162 login_type_01 = self.u3.login_type()2163 test_result = pytest.assume(login_type_01 == 0)2164 if test_result:2165 self.ws1['K10'] = "PASS"2166 else:2167 self.ws1['k10'] = "FAIL"2168 log.error('U3 login type:%s' % login_type_01)2169 @pytest.mark.skip2170 def test11(self):2171 '''测试用例:启动云卡过程关机再开机'''2172 log.info("start %s" % sys._getframe().f_code.co_name)2173 self.u3.wait_network_connect()2174 login_type = self.u3.login_type()2175 if login_type != 1:2176 self.open_webui()2177 self.login_webui()2178 self.s20i_d(text="Settings").click()2179 self.s20i_d(text="SIM card management").click()2180 self.s20i_d(resourceId="sim_select").click()2181 self.s20i_d(resourceId="text_sim_0").click() # 选择云卡2182 self.s20i_d(text="Apply").click()2183 time.sleep(5)2184 self.u3.wait_network_connect()2185 time.sleep(3)2186 assert self.u3.login_type() == 12187 test_success_times = 02188 for i in range(100):2189 log.info("-" * 20 + "第%d次启动云卡过程中重启测试" % (i + 1) + "-" * 20)2190 self.u3.reboot()2191 time.sleep(5)2192 self.u3.wait_device_connect()2193 sleep_duration = random.randint(10,40) # 生成一个10-40之间的随机数,将其设置为设备重启后等待时长(比拨号成功时间短)2194 log.info("sleep duration:%d" % sleep_duration)2195 time.sleep(sleep_duration)2196 if self.u3.connect_network():2197 self.ws1['K12'] = "FAIL"2198 self.ws1['L12'] = "启动云卡过程中重启测试成功次数:%d" % test_success_times2199 assert False2200 test_success_times += 12201 self.ws1['K12'] = "PASS"2202 @pytest.mark.skip2203 def test14(self):2204 '''测试用例:云卡ping包2小时'''2205 log.info("start %s" % sys._getframe().f_code.co_name)2206 self.u3.wait_network_connect()2207 login_type = self.u3.login_type()2208 if login_type != 1:2209 self.open_webui()2210 self.login_webui()2211 self.s20i_d(text="Settings").click()2212 self.s20i_d(text="SIM card management").click()2213 self.s20i_d(resourceId="sim_select").click()2214 self.s20i_d(resourceId="text_sim_0").click() # 选择云卡2215 self.s20i_d(text="Apply").click()2216 time.sleep(5)2217 self.u3.wait_network_connect()2218 time.sleep(3)2219 assert self.u3.login_type() == 12220 ping_result = self.u3.ping(duration=7200, target="www.baidu.com") # ping "www.baidu.com" 7200秒2221 packet_loss = ping_result[2] # 丢包率2222 if packet_loss > 5:2223 self.ws1['K15'] = "FAIL"2224 self.ws1['L15'] = "%d packets transmitted, %d received, %.2f%% packet loss" % ping_result2225 assert False2226 else:2227 self.ws1['K15'] = "PASS"2228 def test16(self):2229 '''测试用例:云卡网络设置'''2230 log.info("start %s" % sys._getframe().f_code.co_name)2231 self.u3.wait_network_connect()2232 login_type = self.u3.login_type()2233 if login_type != 0:2234 self.open_webui()2235 self.login_webui()2236 self.s20i_d(text="Settings").click()2237 self.s20i_d(text="SIM card management").click()2238 self.s20i_d(resourceId="sim_select").click()2239 self.s20i_d(resourceId="text_sim_1").click() # 选择实体卡2240 self.s20i_d(text="Apply").click()2241 time.sleep(5)2242 self.u3.wait_network_connect()2243 time.sleep(3)2244 assert self.u3.login_type() == 02245 self.open_webui()2246 self.login_webui()2247 self.s20i_d(text="Settings").click()2248 self.s20i_d(text="SIM card management").click()2249 # sim_roam_dict = self.s20i_d(resourceId="sim_roam").info2250 data_roaming = self.s20i_d(resourceId="sim_roam").info['checked'] # 获取漫游开关是否打开,打开为True,没打开为False2251 # 打开漫游开关2252 if not data_roaming:2253 self.s20i_d(resourceId="sim_roam").click()2254 if self.s20i_d(text="Are you sure to enable data roaming for this physical SIM card?").exists(10):2255 self.s20i_d(resourceId="confirm_btn_ok").click()2256 time.sleep(3)2257 # data_roaming_on = self.s20i_d(resourceId="sim_roam").info['checked']2258 # assert data_roaming_on == True2259 try:2260 self.s20i_d(resourceId="com.android.chrome:id/url_bar").click() # 点击浏览器搜索框2261 except:2262 self.s20i_d(resourceId="com.android.chrome:id/search_box").click() # 点击浏览器搜索框2263 self.s20i_d.send_keys("192.168.43.1", clear=True) # 在搜索框中输入192.168.43.12264 self.s20i_d.xpath('//android.widget.ListView/android.view.ViewGroup[1]').click() # 点击进入webui界面2265 self.login_webui()2266 self.s20i_d(text="Settings").click()2267 self.s20i_d(text="SIM card management").click()2268 self.s20i_d(resourceId="sim_select").click()2269 self.s20i_d(resourceId="text_sim_0").click() # 选择云卡2270 self.s20i_d(text="Apply").click()2271 time.sleep(5)2272 self.u3.wait_network_connect()2273 time.sleep(3)2274 assert self.u3.login_type() == 12275 time.sleep(30)2276 try:2277 self.s20i_d(resourceId="com.android.chrome:id/url_bar").click() # 点击浏览器搜索框2278 except:2279 self.s20i_d(resourceId="com.android.chrome:id/search_box").click() # 点击浏览器搜索框2280 self.s20i_d.send_keys("192.168.43.1", clear=True) # 在搜索框中输入192.168.43.12281 self.s20i_d.xpath('//android.widget.ListView/android.view.ViewGroup[1]').click() # 点击进入webui界面2282 self.login_webui()2283 self.s20i_d(text="Settings").click()2284 self.s20i_d(text="SIM card management").click()2285 self.s20i_d(resourceId="sim_select").click()2286 self.s20i_d(resourceId="text_sim_1").click() # 选择实体卡2287 self.s20i_d(text="Apply").click()2288 time.sleep(5)2289 self.u3.wait_network_connect()2290 time.sleep(3)2291 assert self.u3.login_type() == 02292 try:2293 self.s20i_d(resourceId="com.android.chrome:id/url_bar").click() # 点击浏览器搜索框2294 except:2295 self.s20i_d(resourceId="com.android.chrome:id/search_box").click() # 点击浏览器搜索框2296 self.s20i_d.send_keys("192.168.43.1", clear=True) # 在搜索框中输入192.168.43.12297 self.s20i_d.xpath('//android.widget.ListView/android.view.ViewGroup[1]').click() # 点击进入webui界面2298 self.login_webui()2299 self.s20i_d(text="Settings").click()2300 self.s20i_d(text="SIM card management").click()2301 # sim_roam_dict = self.s20i_d(resourceId="sim_roam").info2302 data_roaming_on = self.s20i_d(resourceId="sim_roam").info['checked'] # 获取漫游开关是否打开,打开为True,没打开为False2303 test_result = pytest.assume(data_roaming_on == True)2304 if test_result:2305 self.ws1['K17'] = "PASS"2306 else:2307 self.ws1['K17'] = "FAIL"2308 FailScreenShot_file = screenShot(d=self.s20i_d, title='test16_fail')2309 file = open(FailScreenShot_file, 'rb').read()2310 allure.attach(file, 'test16 test failed ScreenShot', allure.attachment_type.PNG)2311 def teardown(self):2312 # 每条case执行结束保存一下测试结果表2313 self.wb.save(self.test_result_file_path)2314 def teardown_class(self):2315 log.info("-" * 20 + "End Test_SystemStability" + "-" * 20)2316 def search_wifi(self, timeout=180):2317 cur = time.time()2318 expire = cur + timeout2319 while cur < expire:2320 if not self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).exists(2): # 判断当前界面是否存在名称为“GlocalMe_OHQPJE”的wifi2321 while not self.s20i_d(resourceId="android:id/title", text="添加网络").exists(1):2322 if self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).exists(1):2323 break2324 else:2325 self.s20i_d.swipe(0.5, 0.8, 0.5, 0.3)2326 else:2327 while not self.s20i_d(resourceId="android:id/title", text="WLAN 偏好设置").exists(1):2328 if self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).exists(1):2329 break2330 else:2331 self.s20i_d.swipe(0.5, 0.3, 0.5, 0.8)2332 cur = time.time()2333 else:2334 break2335 else:2336 raise TimeoutError("wifi connect timeout.")2337 def connect_wifi(self):2338 for i in range(2):2339 self.s20i_d.press('home')2340 self.s20i_d(resourceId="com.android.systemui:id/recent_apps").click()2341 if self.s20i_d(resourceId="com.android.systemui:id/clear_all_button").exists(3):2342 self.s20i_d(resourceId="com.android.systemui:id/clear_all_button").click()2343 log.info("cleared background app success.")2344 else:2345 log.info('no background app running.')2346 self.s20i_d.press('home')2347 self.s20i_d(text="设置").click()2348 self.s20i_d(resourceId="android:id/title", text="网络和互联网").click()2349 self.s20i_d(resourceId="android:id/title", text="WLAN").click()2350 if self.s20i_d(resourceId="com.android.settings:id/switch_widget").get_text() == "关闭": # 判断wifi是否开启2351 self.s20i_d(resourceId="com.android.settings:id/switch_widget").click()2352 time.sleep(3)2353 self.search_wifi()2354 if self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).sibling(resourceId="android:id/summary", text="登录到网络").exists(3):2355 log.info("auxiliary device connect test device wifi successfully, text:登录到网络")2356 return2357 elif self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).sibling(resourceId="android:id/summary", text="已连接").exists(3):2358 log.info("auxiliary device connect test device wifi successfully, text:已连接")2359 return2360 elif self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).sibling(resourceId="android:id/summary", text="已连接,但无法访问互联网").exists(3):2361 log.info("auxiliary device connect test device wifi successfully, text:已连接,但无法访问互联网")2362 return2363 self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).click() # 点击名称为“GlocalMe”的wifi2364 if self.s20i_d(resourceId="com.android.settings:id/password").exists(3): # 判断是否弹出输入password的弹窗2365 self.s20i_d.send_keys(U3_settings.test_device_info['password'], clear=True) # 输入password2366 self.s20i_d(resourceId="android:id/button1").click()2367 elif self.s20i_d(text="取消保存").exists(3):2368 log.info("auxiliary device connect test device wifi successfully")2369 return2370 if self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).sibling(resourceId="android:id/summary", text="登录到网络").exists(3):2371 log.info("auxiliary device connect test device wifi successfully, text:登录到网络")2372 elif self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).sibling(resourceId="android:id/summary", text="已连接").exists(3):2373 log.info("auxiliary device connect test device wifi successfully, text:已连接")2374 elif self.s20i_d(resourceId="android:id/title", text=U3_settings.test_device_info['ssid']).sibling(resourceId="android:id/summary", text="已连接,但无法访问互联网").exists(3):2375 log.info("auxiliary device connect test device wifi successfully, text:已连接,但无法访问互联网")2376 else:2377 log.error("auxiliary device connect test device wifi failed.")2378 screenShot(self.s20i_d, title="wifi_connect_fail")2379 raise ConnectionError("wifi connect error.")2380 def open_webui(self):2381 self.connect_wifi()2382 self.s20i_d(resourceId="com.android.systemui:id/center_group").click() # 返回主界面2383 self.s20i_d(text="Chrome").click() # 点击打开浏览器2384 # 判断浏览器是否第一次打开,如果第一次打开就点击设置欢迎页弹窗2385 if self.s20i_d(resourceId="com.android.chrome:id/terms_accept").exists(5):2386 try:2387 self.s20i_d(resourceId="com.android.chrome:id/terms_accept").click()2388 self.s20i_d(resourceId="com.android.chrome:id/negative_button").click()2389 self.s20i_d(resourceId="com.android.chrome:id/button_secondary").click()2390 except Exception as e:2391 log.error(e)2392 # log.info('浏览器不是第一次启动,不需要设置欢迎页')2393 # self.s20i_d(resourceId="com.android.chrome:id/home_button").click() # 点击浏览器主页按钮进入主页2394 try:2395 self.s20i_d(resourceId="com.android.chrome:id/url_bar").click() # 点击浏览器搜索框2396 except:2397 self.s20i_d(resourceId="com.android.chrome:id/search_box").click() # 点击浏览器搜索框2398 self.s20i_d.send_keys("192.168.43.1", clear=True) # 在搜索框中输入192.168.43.12399 self.s20i_d.xpath('//android.widget.ListView/android.view.ViewGroup[1]').click() # 点击进入webui界面2400 def login_webui(self):2401 if self.s20i_d(resourceId="tr_manage_my_device").exists(5):2402 self.s20i_d(resourceId="tr_manage_my_device").click() # 点击管理我的设备2403 elif self.s20i_d(text="Manage My Device").exists(5):2404 self.s20i_d(text="Manage My Device").click()2405 # 输入账号密码登陆管理界面2406 self.s20i_d(resourceId="username").click()2407 time.sleep(2)2408 self.s20i_d.click(0.342, 0.303)2409 self.s20i_d.send_keys("admin", clear=True)2410 for i in range(2):2411 self.s20i_d(resourceId="passWord").click()2412 self.s20i_d.send_keys("admin", clear=True)2413 self.s20i_d(text="Login").click()2414if __name__ == '__main__':2415 # os.environ.update({"__COMPAT_LAYER": "RUnAsInvoker"})2416 current_time = time.strftime('%Y-%m-%d_%H-%M-%S', time.localtime(time.time()))2417 # 创建测试记录保存路径2418 test_record_path = '/'.join([BASEDIR, 'TestRecord', project_name, current_time])2419 if not os.path.exists(test_record_path):2420 os.makedirs(test_record_path)2421 # 报告保存路径2422 report_path = '/'.join([BASEDIR, 'reports', project_name])2423 if not os.path.exists(report_path):2424 make_report_path = os.makedirs(report_path)2425 report_name = '/'.join([report_path, '.'.join([current_time, 'html'])])2426 report = ''.join(['--html=', report_name])2427 '''生成html报告的运行方式'''2428 pytest.main(['-s', report, 'test_project_U3.py::Test_CloudSimAndPhysicalSimSwitch::test08'])2429 '''生成定制测试报告的运行方式'''2430 # result_file = '/'.join([report_path, time.strftime('%Y-%m-%d_%H-%M-%S', time.localtime(time.time()))])2431 # report_file = '/'.join([result_file, 'report'])2432 # os.makedirs(report_file)2433 # pytest.main(['-s', '-q', '--alluredir', result_file, 'test_project_S20i_RedLineCase.py::Test_Camera'])2434 # cmd = ' '.join(['allure generate', result_file, '-o', report_file])...

Full Screen

Full Screen

test_database.py

Source:test_database.py Github

copy

Full Screen

1import copy 2from datetime import datetime, timedelta3import logging4from pprint import pformat5import sys 6sys.path.append("../")7import uuid8import pytest9from werkzeug.security import check_password_hash10import database as asdb11from db.models import State, Device, Place, User, Token12logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s', datefmt='%Y-%m-%d/%H:%M:%S')13logger = logging.getLogger(__name__)14def test_get_last_states(timescaleDB):15 _ = timescaleDB.query(State). \16 order_by(State.device_id, State.timestamp.desc()). \17 all()18 # to store expected rows 19 right_states = []20 for right_state in _:21 right_states.append(right_state)22 test_query = asdb.get_last_states(23 start_ts=datetime.now() - timedelta(minutes=5),24 place_id=1, 25 db_session=timescaleDB26 )27 db_last_states = []28 for test_state in test_query:29 db_last_states.append(test_state)30 assert right_states == db_last_states, "Last states are wrong" 31def test_get_places(timescaleDB):32 places = asdb.get_places(timescaleDB)[0]33 assert places.id == 1, "Place ID is invalid"34 assert places.name == 'KEMZ', "Place name is invalid"35 assert places.num == '8201', "Place number is invalid" 36def test_create_place(timescaleDB):37 test_place_info = {38 'name': 'ELESI', 39 'num': '8203-1',40 'attr_os': ['Windows'],41 'attr_software': ['Matlab'],42 'attr_people': 20,43 'attr_computers': 8,44 'attr_board': False,45 'attr_projector': True46 }47 new_place = asdb.create_place(test_place_info, timescaleDB)48 places_num = timescaleDB.query(Place).count()49 # remove new place to keep temp DB sustainable 50 timescaleDB.delete(new_place)51 assert new_place.name == test_place_info['name'], "Name of new place is wrong"52 assert new_place.num == test_place_info['num'], "Number of new place is wrong"53 assert new_place.attr_os == test_place_info['attr_os'], "OS for new place is wrong" 54 assert new_place.attr_software == test_place_info['attr_software'], "Software for new place is wrong"55 assert new_place.attr_people == test_place_info['attr_people'], "Number of people for new place is wrong"56 assert new_place.attr_computers == test_place_info['attr_computers'], "Number of computers for new place is wrong"57 assert new_place.attr_blackboard == test_place_info['attr_board'], "Status of blackboard existance is wrong"58 assert new_place.attr_projector == test_place_info['attr_projector'], "Status of projector existance is wrong"59 assert places_num == 2, "Number of places is wrong"60def test_update_place(timescaleDB):61 test_place_info = {62 'id': 1,63 'name': 'KEMZ', 64 'num': '8201',65 'attr_os': ['Windows'],66 'attr_software': ['Matlab'],67 'attr_people': 20,68 'attr_computers': 8,69 'attr_board': True,70 'attr_projector': True71 }72 asdb.update_place(test_place_info, timescaleDB)73 test_place = timescaleDB.query(Place).get(test_place_info['id'])74 75 check_data = {76 'attr_os': test_place.attr_os,77 'attr_software': test_place.attr_software,78 'attr_people': test_place.attr_people,79 'attr_computers': test_place.attr_computers,80 'attr_board': test_place.attr_blackboard,81 'attr_projector': test_place.attr_projector82 }83 # reset updated data to keep temp DB sustainable 84 test_place.attr_os = [] 85 test_place.attr_software = []86 test_place.attr_people = 10 87 test_place.attr_computers = 25 88 test_place.attr_blackboard = False 89 test_place.attr_projector = False 90 timescaleDB.commit() 91 92 assert check_data['attr_os'] == test_place_info['attr_os'], "OS array is wrong"93 assert check_data['attr_software'] == test_place_info['attr_software'], "Software array is wrong"94 assert check_data['attr_people'] == test_place_info['attr_people'], "People number is wrong"95 assert check_data['attr_computers'] == test_place_info['attr_computers'], "Computer number is wrong"96 assert check_data['attr_board'] == test_place_info['attr_board'], "Blackboard status is wrong"97 assert check_data['attr_projector'] == test_place_info['attr_projector'], "Projector status is wrong"98def test_delete_place(timescaleDB):99 new_place = Place(100 name='Test', 101 num='111', 102 attr_os=['Windows'],103 attr_software=['Matlab'],104 attr_people=20,105 attr_computers=8,106 attr_blackboard=False,107 attr_projector=True108 )109 timescaleDB.add(new_place)110 timescaleDB.commit()111 test_place_info = {112 'id': timescaleDB.query(Place.id).filter(Place.name == 'Test').first(),113 'name': new_place.name, 114 'num': new_place.num,115 'attr_os': new_place.attr_os,116 'attr_software': new_place.attr_software,117 'attr_people': new_place.attr_people,118 'attr_computers': new_place.attr_computers,119 'attr_board': new_place.attr_blackboard,120 'attr_projector': new_place.attr_projector121 }122 asdb.delete_place(test_place_info, timescaleDB)123 test_place = timescaleDB.query(Place).get(new_place.id)124 assert test_place == None, "Place wasn't removed" 125def test_update_device(timescaleDB):126 test_device_info = {127 'id': timescaleDB.query(Device.id).first(),128 'name': 'Test Device', 129 'icon_name': 'Test Icon', 130 'type': 'env', 131 'place_id': 1, 132 'config': {}133 }134 asdb.update_device(test_device_info, timescaleDB)135 logger.debug(136 f"ALL DEVICES:\n" \137 f"{pformat(timescaleDB.query(Device).all())}"138 )139 device = timescaleDB.query(Device).get(test_device_info['id'])140 test_device = copy.deepcopy(device)141 # reset updated data to keep temp DB sustainable 142 device.name = None 143 device.icon_name = None 144 timescaleDB.commit()145 assert test_device.place_id == test_device_info['place_id'], "Place ID for device wasn't updated"146 assert test_device.type == test_device_info['type'], "Type of device wasn't updated"147 assert test_device.name == test_device_info['name'], "Name of device wasn't updated"148def test_reset_device(timescaleDB):149 device_info = {150 'id': uuid.uuid4(),151 'place_id': 1, 152 'is_installed': True, 153 'name': 'New Test Device',154 'icon_name': 'New Test Icon'155 }156 157 new_device = Device(158 id=device_info['id'],159 place_id=device_info['place_id'],160 register_date=datetime.now(), 161 is_installed=device_info['is_installed'], 162 name=device_info['name'],163 icon_name=device_info['icon_name']164 )165 timescaleDB.add(new_device)166 timescaleDB.commit()167 asdb.reset_device(device_info, timescaleDB)168 reseted_device = timescaleDB.query(Device).get(device_info['id'])169 170 # remove new device for test to keep temp DB sustainable 171 timescaleDB.delete(new_device)172 assert reseted_device.place_id == None, "Place ID for devices wasn't reseted" 173 assert reseted_device.is_installed == False, "Device is installed, expected NOT" 174def test_delete_device(timescaleDB):175 device_info = {176 'id': uuid.uuid4(),177 'place_id': 1, 178 'is_installed': True, 179 'name': 'Device 4 Delete',180 }181 182 new_device = Device(183 id=device_info['id'],184 place_id=device_info['place_id'],185 register_date=datetime.now(), 186 is_installed=device_info['is_installed'], 187 name=device_info['name'],188 )189 timescaleDB.add(new_device)190 timescaleDB.commit()191 asdb.delete_device(device_info, timescaleDB)192 check_device = timescaleDB.query(Device).get(device_info['id'])193 194 assert check_device == None, "Device wasn't removed" 195def test_get_devices(timescaleDB):196 assert len(asdb.get_devices(1, timescaleDB)) == 3, "Number of devices is wrong, expected 3" 197def test_get_new_devices(timescaleDB):198 device_info = {199 'id': uuid.uuid4(),200 'place_id': 1, 201 'is_installed': False, 202 'name': 'New Device',203 }204 205 new_device = Device(206 id=device_info['id'],207 place_id=device_info['place_id'],208 register_date=datetime.now(), 209 is_installed=device_info['is_installed'], 210 name=device_info['name'],211 )212 timescaleDB.add(new_device)213 timescaleDB.commit()214 devices = asdb.get_new_devices(timescaleDB)215 # remove new device for test to keep temp DB sustainable 216 timescaleDB.delete(devices[0])217 assert len(devices) == 1, "Number of new devices is wrong" 218 assert devices[0].place_id == device_info['place_id'], "Place ID is invalid"219 assert devices[0].is_installed == device_info['is_installed'], "Device is installed, expected NOT"220 assert devices[0].name == device_info['name'], "Device Name is wrong" 221def test_get_user_data(timescaleDB):222 test_query = asdb.get_user_data("test_user", db_session=timescaleDB)223 assert test_query.username == 'test_user', "No valid username"224 assert check_password_hash(test_query.password_hash, 'test_password'), "No valid password"225def test_create_user(timescaleDB):226 new_user = asdb.create_user(227 username='new_test_user', 228 password='new_test_password',229 db_session=timescaleDB230 )231 num_of_users = timescaleDB.query(User).count()232 # remove new user for test to keep temp DB sustainable 233 timescaleDB.delete(timescaleDB.query(User).get(2))234 235 assert num_of_users == 2, "New user wasn't added to DB"236 assert new_user.username == 'new_test_user', "Username is wrong"237 assert new_user.id == 2, "USER ID is wrong"238def test_save_token(timescaleDB, flask_app):239 test_token = asdb.save_token(240 user_id=1, 241 secret=flask_app.config['SECRET_KEY'],242 db_session=timescaleDB243 )244 check_token = [str(tkn) for tkn in timescaleDB.query(Token.token).first()][0]245 246 assert test_token.token == check_token, "Token is invalid" 247def test_delete_token(timescaleDB, flask_app):248 if timescaleDB.query(Token).count() == 0:249 new_token = asdb.save_token(250 user_id=1, 251 secret=flask_app.config['SECRET_KEY'],252 db_session=timescaleDB253 )254 check_token = new_token.token 255 parent_id = new_token.parent_id256 created_on = new_token.created_on257 else:258 test_token = timescaleDB.query(Token).first()259 260 check_token = test_token.token 261 parent_id = test_token.parent_id 262 created_on = test_token.created_on263 asdb.delete_token(264 user_id=parent_id, 265 created_on=created_on,266 db_session=timescaleDB267 )268 check = timescaleDB.query(Token). \269 filter(Token.token == check_token).first()...

Full Screen

Full Screen

test_device_info.py

Source:test_device_info.py Github

copy

Full Screen

...9@IHmark.MF187810@IHmark.CF435211#@pytest.mark.level212@pytest.mark.MF1878_K_CF4352_device_info13def test_device_info():14 ve_test = VeTestApi("test_device_info")15 ve_test.begin()16 ve_test.wait(1)17 ve_test.screens.settings.device_info(verify=True)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Airtest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful