python实现VTS和CTS-ON-GSI自动flash system.img脚本
2022-07-20 14:24:05 265
Python 软件测试 xTS(谷歌认证测试)
```python import os import time import sys import re from colorama import init init(autoreset=True) a = sys.argv[1] try: boot = sys.argv[2] except: boot = " " system = "system.img" def flashGsi(a, boot, sn, s): os.system("adb -s {} reboot bootloader".format(sn)) time.sleep(1) if a == "vts": os.system("fastboot flash boot {}".format(boot)) time.sleep(1) os.system("fastboot -w") else: os.system("fastboot -w") time.sleep(1) os.system("fastboot reboot fastboot") time.sleep(2) os.system("fastboot flash system {}".format(system)) time.sleep(5) os.system("fastboot reboot") print("\n") #output = '*'*int((s/2-37)) + "\033[0;32;40m\t{}:此设备刷GSI成功,正在重启中\033[0m".format(sn) + '*'*int((s/2-37)) print("#####\033[0;32;40m{}:此设备刷GSI成功,正在重启中\033[0m#####".format(sn).center(s, '*')) def getDevicesSn(): SN_list = [] device_info = os.popen('adb devices').read() for line in device_info.splitlines(): if line == 'List of devices attached': continue else: com = re.compile('(.*?)\tde.*?') SN = re.findall(com, line) for i in SN: SN_list.append(i) return SN_list if __name__ == '__main__': width = os.get_terminal_size().columns sn = getDevicesSn() for i in sn: print("\n"+ "#####\033[0;32;40m{}:此设备正在刷GSI,请稍等!\033[0m#####".format(i).center(width, '*')) flashGsi(a, boot, i, width) time.sleep(10) print("\n"+ "#####\033[0;32;40m共{}台手机刷GSI完成!\033[0m#####".format(len(sn)).center(width, '*')) time.sleep(2) if a == 'gsi': print("\n"+ "#####\033[0;31;40m请手动点击Allow USB debugging弹框\033[0m#####".center(width)) time.sleep(75) os.system("python3 setting.py") time.sleep(1) os.system("python3 auto_media_push.py") else: time.sleep(75) os.system("python3 setting.py") ``` ``` 想了解,flash system.img开机后,VTS和CTS-on-GSI手机前期设置的小伙伴们,请关注我。
对于谷歌认证测试(xTS),分享一下自己在工作中编写的一些脚本。
2022-07-20 14:20:55 328
Python xTS(谷歌认证测试) 自动化脚本
算上实习,我在安卓测试工作岗位上已经做了近4年了,而在xTS模块测试中有差不多2年多时间。如今我已经换工作岗位,我想这辈子或许再也不会接触xTS、GTS、VTS、STS、Verififer等等测试了吧,曾经很努力很努力的学习相关知识,想想过程中付出的所有,对于我来说都是一种收获!现在我已经重新启航,进入了一个新的工作岗位。加油! 推荐一个在线工具网站:[在线工具大全](https://www.zztdd.cn) **xTS自动化执行:** 1.配置文件: ``` [config] test_item = GTS executed_file = ../tools/gts-tradefed executed_command = run gts -m GtsSimAppDialogTestCases -t com.google.android.simappdialog.gts.InstallCarrierAppActivityTest#testNotificationOnlyDuringSetupWizard -s BH950020JN executed_command_1 = gts full_run_number = 1 device_number = 3 device1 = device2 = device3_uicc = 设备SN号 device4_se = 设备SN号 device5_sim = 设备SN号 device_set_all = 设备SN号 ``` 2.python 部分代码(全部代码请访问:[all code](https://github.com/zztroot/xtsTest)) ```python import os import time import re try: from bs4 import BeautifulSoup import configparser from prettytable import PrettyTable except: os.system("pip3 install bs4") os.system("pip3 install configparser") os.system("pip3 install prettytable") time.sleep(1) from bs4 import BeautifulSoup import configparser from prettytable import PrettyTable def executed_xts(runfile, command, seconds): time.sleep(2) run = 'gnome-terminal -- ' + runfile + ' ' + command width = os.get_terminal_size().columns print("*".center(width, '*')) os.system(run) time.sleep(seconds) files = os.listdir("../results/") files = sorted(files) if len(files) % 2 == 0: if len(files) >= 2: return files[-2] else: return files[0] elif len(files) % 2 == 1: return files[-1] def if_result_done(resul_file): files_zip = "../results/" + resul_file + ".zip" if os.path.exists(files_zip): return resul_file else: return "not done" def check_results(file_name): filepath = os.getcwd() path = re.findall("(.*?).autoXts", filepath) new_path = path[0] url = os.path.join(new_path + "/results/" + file_name + "/test_result_failures_suite.html") with open(url, 'r') as f: soup = BeautifulSoup(f.read(), 'lxml').html result_pass = re.findall('.*?<td class="rowtitle">Tests Passed</td>.*?>(.*?)</.*?', str(soup)) result_fail = re.findall('.*?<td class="rowtitle">Tests Failed</td>.*?>(.*?)</.*?', str(soup)) result_module_done = re.findall('.*?<td class="rowtitle">Modules Done</td>.*?>(.*?)</.*?', str(soup)) result_module_total = re.findall('.*?<td class="rowtitle">Modules Total</td>.*?>(.*?)</.*?', str(soup)) results_list = [result_pass[0], result_fail[0], result_module_done[0], result_module_total[0]] if result_fail[0] == "0": return results_list, "done" fail_module_name = re.findall('.*?<td class="module" colspan="3"><a.*?>.*?(C.*?)</a>.*?', str(soup)) se_cases = "CtsSecureElementAccessControlTestCases1" or \ "CtsSecureElementAccessControlTestCases2" or \ "CtsSecureElementAccessControlTestCases3" or \ "CtsSecureElementAccessControlTestCases1[instant]" or \ "CtsSecureElementAccessControlTestCases2[instant]" or \ "CtsSecureElementAccessControlTestCases3[instant]" or \ "VtsHalSecureElementV1_0Target" if se_cases in fail_module_name: return results_list, "se" sim_cases = "CtsTelecomTestCases" or \ "CtsTelecomTestCases2" or \ "CtsTelecomTestCases3" or \ "CtsTelephony2TestCases" or \ "CtsTelephony2TestCases[instant]" or \ "CtsTelephony3TestCases" or \ "CtsTelephonyProviderTestCases" or \ "CtsTelephonySdk28TestCases" or \ "CtsTelephonyTestCases" or \ "CtsPermissionTestCasesTelephony" or \ "CtsPermissionTestCasesTelephony[instant]" or \ "GtsTelephonyTestCases" or \ "GtsTelecomManagerTests" or \ "VtsHalAudioEffectV5_0Target" or \ "VtsHalAudioV2_0Target" or \ "VtsHalAudioV5_0Target" or \ "VtsHalRadioConfigV1_0Target" if sim_cases in fail_module_name: return results_list, "sim" uicc_cases = "CtsCarrierApiTestCases" or "GtsSimAppDialogTestCases" if uicc_cases in fail_module_name: return results_list, "uicc" return results_list, "all" ```