Best Python code snippet using Airtest
test_project_U3__bac.py
Source:test_project_U3__bac.py
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])...
test_database.py
Source:test_database.py
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()...
test_device_info.py
Source:test_device_info.py
...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)...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!