import re,os,time
time_start=time.time() #计算时间
time.sleep(5)
time_end=time.time()
run_time=time_end-time_start
QMI_QFE_WTR_PA_0 = i.split("QMI_QFE_WTR_PA_0: ")[1].split("C Normal")[0] #截取字符
import pyautogui,pyperclip
pyperclip.copy(Update_IMG) #复制/粘贴
pyperclip.paste()
pyautogui.press('enter') #模拟键盘输入
pyautogui.hotkey("ctrl","v")
pyautogui.press('f5')
import xlwt
file = xlwt.Workbook(encoding=" uft-8") # 创建表格
package_1 = "Results"
table = file.add_sheet(package_1,cell_overwrite_ok=True)
table.write(0, 0, 'Test Time')
table.write(0, 1, 'ping_result')
for r in range(1,100000):
table.write(r, 0, current_time)
table.write(r, 1, ping_result)
try:
file.save('1300_Ping_Result.xls')
except PermissionError:
pass
def ping_test(): #ping测试
content = os.popen('ping www.baidu.com -4 -n 10').read()
if "往返行程的估计时间(以毫秒为单位):
" in content:
ping_result = "PASS"
else:
ping_result = "NG"
return ping_result
#找对应的文件
path = "D:/611_613_1201/202101/SDX55_EJ_V1.7.0_210127.1_a_user-app_master_1_2-nonhlos_master_1_2"
Fota_path = path +"/FOTA/"
Fota_a = ""
Fota_m = ""
Fota_p = ""
Fota_f = ""
for dir,folder,file in os.walk(Fota_path):
for i in file:
if "_a.zip" in i:
Fota_a = i
elif "_m.zip" in i:
Fota_m = i
elif "_p.zip" in i:
Fota_p = i
elif "_f.zip" in i:
Fota_f = i
else:
pass
print(Fota_a,Fota_m,Fota_p,Fota_f )
times = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())
time_str = re.sub(r"-|:| ", "", times) #将时间转化为纯字符格式
print(time_str)
def Modify_fastboot_bat(): # 修改fastboot bat文件
f = open(Firmware_Fastboot_bat, 'r+')
flist = f.readlines()
flist[1] = 'adb reboot bootloader
'
flist[43] = '
'
f = open(Firmware_Fastboot_bat, 'w+')
f.writelines(flist)
f.close()
def ipconfig_iddress(): #找到电脑IP地址
ip_iddress = os.popen("ipconfig").readlines()
a = 0
for line in ip_iddress:
a += 1
if "默认网关. . . . . . . . . . . . . :" in line:
ip1 = "http://" + str(ip_iddress[a].replace(" ",""))
ip = str(ip1.replace("
",""))
return ip
else:
pass
IP = ipconfig_iddress()
from selenium import webdriver
chrome_driver = r"C:Usersolin_zhangDesktopTest_ScriptSeleniumchromedriver.exe"
driver = webdriver.Chrome(executable_path=chrome_driver) #使用selenium进行web测试
driver.maximize_window()
driver.get("http://192.168.43.1")
time.sleep(5)
driver.find_element_by_id("btn_index_connect").click() #鼠标点击命令
driver.find_element_by_class_name("btn-expert").click()
driver.find_element_by_id("field_lte_pdn_type").send_keys(Keys.DOWN) #键盘输入命令
driver.find_element_by_id("field_lte_pdn_type").send_keys(Keys.ENTER)
driver.find_element_by_xpath('//button[text()="Apply"]').click() #按照标签和文本来定位
driver.quit() #关闭窗口
import logging
logging.basicConfig(filename='test.log', #logging记录相关信息
level=logging.INFO,
# 定义输出log的格式
format='%(asctime)s %(filename)s : %(levelname)s %(message)s',
# 时间
datefmt='%Y-%m-%d %A %H:%M:%S')
logging.info("Test times: " +" *********************************************")
import unittest #unittest测试框架
import HTMLTestRunner
from Upgrade import Upgrade_test
from Network import Network_test
def suite():
Upgrade_tests = unittest.TestLoader().loadTestsFromTestCase(Upgrade_test)
Network_tests = unittest.TestLoader().loadTestsFromTestCase(Network_test)
smoke_tests = unittest.TestSuite([Upgrade_tests,Network_tests])
return smoke_tests
if __name__ == "__main__":
fp = open("1300_test_result.html","wb")
runner = HTMLTestRunner.HTMLTestRunner(stream=fp,title="测试报告",description="详情")
runner.run(suite())
import unittest #Network.py内容
import os,time
import HTMLTestRunner
import warnings
class Network_test(unittest.TestCase):
def setUp(self):
warnings.simplefilter('ignore', ResourceWarning)
def test_01_ping(self):
content = os.popen('ping www.baidu.com -4 -n 10').read()
if "往返行程的估计时间(以毫秒为单位):
" in content:
at_cmd_result = "Ping OK"
elif "Ping 请求找不到主机 www.baidu.com。请检查该名称,然后重试。
" in content:
at_cmd_result = "Ping NG"
else:
at_cmd_result = content
self.assertEqual(at_cmd_result, "Ping OK")
def suite():
Network_testcase = unittest.makeSuite(Network_test,"test")
return Network_testcase
if __name__ == "__main__":
fp = open("Network_test_result.html","wb")
runner = HTMLTestRunner.HTMLTestRunner(stream=fp,title="测试报告",description="详情")
runner.run(suite())
import serial
import os
import subprocess
import time
class AT_port(object): #调制解析器口发送at命令
def __init__(self, port=""):
self.ser = serial.Serial(port=port, baudrate=115200, bytesize=8, parity='N',
stopbits=1, timeout=1, xonxoff=False, rtscts=False, dsrdtr=False)
def send(self, msg):
msg += "
"
self.ser.write(msg.encode())
ret = self.ser.read(1024)
ret = str(ret, encoding="utf-8")
ret = ret.replace(msg, "").strip()
return ret
class ADB(object): #adb控制
def __init__(self, devices="devices_number"):
self.devices = devices
def reboot_bootloader(self):
os.system("adb -s %s reboot bootloader" % self.devices)
def reboot(self):
os.system("adb -s %s reboot" % self.devices)
def wait_for_device(self):
os.system("adb -s %s wait-for-usb-device" % self.devices)
pass
at = AT_port("COM29")
ret = at.send("ati")
print(ret)
adb = ADB("a3b474d6")
adb.reboot()