天天看點

對于谷歌認證測試(xTS),分享一下自己在工作中編寫的一些腳本。

算上實習,我在安卓測試工作崗位上已經做了近4年了,而在xTS子產品測試中有差不多2年多時間。如今我已經換工作崗位,我想這輩子或許再也不會接觸xTS、GTS、VTS、STS、Verififer等等測試了吧,曾經很努力很努力的學習相關知識,想想過程中付出的所有,對于我來說都是一種收獲!現在我已經重新啟航,進入了一個新的工作崗位。加油!

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)

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"
           

更多文章、小工具請通路我的個人部落格:https://www.zztdd.cn/