正文
some working learning总结学习
小程序:扫一扫查出行
【扫一扫了解最新限行尾号】
复制小程序
【扫一扫了解最新限行尾号】
复制小程序
1. Python通过pypyodbc访问Access数据库
https://blog.csdn.net/jisuanjiguoba/article/details/73163721
2. java大数据学习路线图
https://blog.csdn.net/weixin_44386638/article/details/86664006
3. 使用Python对Access读写操作
https://www.cnblogs.com/mayi0312/p/6646957.html
4. python 字符串组成MySql 命令时,字符串含有单引号或者双引号导致出错解决办法
https://www.cnblogs.com/Presley-lpc/p/9152020.html
5. 纯前端利用 js-xlsx 实现 Excel 文件导入导出功能示例
https://blog.csdn.net/weixin_36185028/article/details/78685844
6.实现三个功能
1. 读取excel脚本上的测试用例,使用Automation desk执行py脚本,运行程序,将测试结果通过socket的方式(因为pyqt来实时读取测试结果,操控机器,com段通信涉及到进程、线程占用的问题,所以采用了socket)发送到pyqt做的控制器(监控网站测试需求,操作automation执行测试用例并读取返回结果)
from openpyxl import load_workbook
from time import sleep
from audxilapiconveniencelib import Write,Read
from openpyxl.comments import Comment
from openpyxl.styles import colors, Font
import socket
import json
import time #记录测试用例所耗时间
start_time = time.time() #测试进度推送
server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
address = ("localhost", ) #测试用例导入并筛选
TC=load_workbook ("C:\\03_TestCase\\BenShaw\\ATC\\VCU_TC_LvPwrOff.xlsx")
TCsheet=TC.active
TCrows=[]
Cases=[]
for row in TCsheet.iter_rows():
TCrows.append(row)
#for i in range(,):
for i in range(,):
Cases.append(TCrows[i]) #测试执行
item= sum_num =
for Case in Cases: Result=[]
#PreCondition
init_list = []
for i in range(,):
init_list.append(Case[i].value) check_pre_list = []
tag =
count =
while count<: #分4种条件,先判断是否Powcomplete,chargfed,stready,状态,
# 、全0;
# 、,,;
# 、,,; 高压上电状态
# 、,,; 充电状态
if init_list[] == and init_list[] == and init_list[] == :
print("用例%s进入初始条件一的判断"%sum_num)
Write(_AD_.MAPort, _AD_.TestVar.IN_ChrgOffButton_Value, Case[].value)
Write(_AD_.MAPort, _AD_.TestVar.IN_PowON_Value, Case[].value)
Write(_AD_.MAPort, _AD_.TestVar.IN_12Voltage_Value, Case[].value)
tag =
count =
elif init_list[] == and init_list[] == and init_list[] == :
print("用例%s进入初始条件二的判断"%sum_num)
Write(_AD_.MAPort, _AD_.TestVar.IN_ChrgOffButton_Value, Case[].value)
Write(_AD_.MAPort, _AD_.TestVar.IN_PowON_Value, Case[].value)
Write(_AD_.MAPort, _AD_.TestVar.IN_12Voltage_Value, Case[].value)
time.sleep()
Write(_AD_.MAPort, _AD_.TestVar.IN_KeyON_Value, Case[].value)
time.sleep()
count2 =
while count2<:
if Read(_AD_.MAPort, _AD_.TestVar.RX_BMS_Tx_stPowComplete) == init_list[]:
print("用例%s初始条件二再循环判断正确"%sum_num)
tag =
break
else:
Write(_AD_.MAPort, _AD_.TestVar.IN_KeyON_Value, )
time.sleep()
Write(_AD_.MAPort, _AD_.TestVar.IN_KeyON_Value, )
time.sleep()
count2 +=
count =
elif init_list[] == and init_list[] == and init_list[] == :
print("用例%s进入初始条件三的判断"%sum_num)
Write(_AD_.MAPort, _AD_.TestVar.IN_ChrgOffButton_Value, Case[].value)
Write(_AD_.MAPort, _AD_.TestVar.IN_PowON_Value, Case[].value)
Write(_AD_.MAPort, _AD_.TestVar.IN_12Voltage_Value, Case[].value)
time.sleep()
Write(_AD_.MAPort, _AD_.TestVar.IN_KeyON_Value, Case[].value)
time.sleep()
Write(_AD_.MAPort, _AD_.TestVar.IN_KeyStart_Value, Case[].value)
time.sleep()
count3 =
while count3<:
if Read(_AD_.MAPort, _AD_.TestVar.RX_BMS_Tx_stPowComplete) == init_list[]: count4 =
while count4 < :
if Read(_AD_.MAPort, _AD_.TestVar.RX_VCU_Tx_stReady) == :
print("用例%s初始条件三再循环判断正确"%sum_num)
#退出count3的循环
count3 =
tag =
break
else:
Write(_AD_.MAPort, _AD_.TestVar.IN_KeyStart_Value, )
time.sleep()
Write(_AD_.MAPort, _AD_.TestVar.IN_KeyStart_Value, )
count4 +=
count3 +=
else:
Write(_AD_.MAPort, _AD_.TestVar.IN_KeyON_Value, )
time.sleep()
Write(_AD_.MAPort, _AD_.TestVar.IN_KeyON_Value, )
time.sleep()
count3 +=
count =
elif init_list[] == and init_list[] == and init_list[] == :
print("用例%s进入初始条件四的判断"%sum_num)
Write(_AD_.MAPort, _AD_.TestVar.IN_ChrgOffButton_Value, Case[].value)
Write(_AD_.MAPort, _AD_.TestVar.IN_PowON_Value, Case[].value)
Write(_AD_.MAPort, _AD_.TestVar.IN_12Voltage_Value, Case[].value)
time.sleep()
Write(_AD_.MAPort, _AD_.TestVar.RC2Value_Value, Case[].value)
time.sleep() count5 =
while count5<:
if Read(_AD_.MAPort, _AD_.TestVar.RX_BMS_Tx_stPowComplete) == init_list[] and Read(_AD_.MAPort, _AD_.TestVar.RX_VCU_Tx_stChrgFed) == init_list[]:
print("用例%s初始条件四再循环判断正确"%sum_num)
#退出count3的循环
tag =
break
else:
Write(_AD_.MAPort, _AD_.TestVar.RC2Value_Value, )
Write(_AD_.MAPort, _AD_.TestVar.IN_KeyON_Value, )
time.sleep()
Write(_AD_.MAPort, _AD_.TestVar.IN_KeyON_Value, ) Write(_AD_.MAPort, _AD_.TestVar.RC2Value_Value, Case[].value)
time.sleep()
count5 +=
count =
print("退出条件4循环")
else:
print("用例%s属于目前未加初始条件,待扩展判断区"%sum_num)
count += check_pre_list.append(Read(_AD_.MAPort, _AD_.TestVar.RX_BMS_Tx_stPowComplete))
check_pre_list.append(Read(_AD_.MAPort, _AD_.TestVar.RX_VCU_Tx_stChrgFed))
check_pre_list.append(Read(_AD_.MAPort, _AD_.TestVar.RX_VCU_Tx_stReady))
#进行写入操作前的判断,节省资源
# if tag:
#Action
print("用例%s进入测试步骤正确"%sum_num)
Write(_AD_.MAPort, _AD_.TestVar.IN_KeyStart_Value, Case[].value)
#写入speed
Write(_AD_.MAPort, _AD_.TestVar.Active_Value, )
Write(_AD_.MAPort, _AD_.TestVar.Control_Value,Case[].value)
Write(_AD_.MAPort, _AD_.TestVar.IN_KeyON_Value, Case[].value)
Write(_AD_.MAPort, _AD_.TestVar.RC2Value_Value, Case[].value)
Write(_AD_.MAPort, _AD_.TestVar.IN_ChrgOffButton_Value, Case[].value)
Write(_AD_.MAPort, _AD_.TestVar.IN_PowON_Value, Case[].value)
time.sleep(Case[].value)
Write(_AD_.MAPort, _AD_.TestVar.IN_KeyON_Value, Case[].value)
time.sleep(Case[].value) #Result
Result.append(Read(_AD_.MAPort, _AD_.TestVar.RX_VCU_Tx_stDCDCEn))
Result.append(Read(_AD_.MAPort, _AD_.TestVar.RX_VCU_Tx_powMaxPerm))
Result.append(Read(_AD_.MAPort, _AD_.TestVar.RX_VCU_Tx_stChrgFed))
Result.append(Read(_AD_.MAPort, _AD_.TestVar.O_S_BMSPwrOn_0_1__Out))
Result.append(Read(_AD_.MAPort, _AD_.TestVar.O_S_MCUPwrOn_0_1__Out))
Result.append(Read(_AD_.MAPort, _AD_.TestVar.O_S_DCPwrOn_0_1__Out))
Result.append(Read(_AD_.MAPort, _AD_.TestVar.O_S_VCUst_0_1__Out))
Result.append(Read(_AD_.MAPort, _AD_.TestVar.O_S_OBCPwrOn_0_1__Out))
time.sleep()
Result.append(Read(_AD_.MAPort, _AD_.TestVar.O_S_ACPDURly_ON_0_1__Out)) #Result Judge
item+=
j=
for i in range(,):
if Result[i-]==Case[i].value:
pass
else:
j=j+
Case[i].comment=Comment('Actual Result:'+str(Result[i-]), 'Fail')
Case[i].font=Font(color=colors.RED)
if j==:
Case[].value='Pass'
data=json.dumps([str(item),'Pass'])
server_socket.sendto(data,address)
else:
Case[].value='Fail'
data=json.dumps([str(item),'Fail'])
server_socket.sendto(data,address)
sleep() else:
Case[].value='进入初始条件Fail'
print("初始条件进入Fail,case %s"%sum_num)
data=json.dumps([str(item),'Fail']) for j in range(,):
if check_pre_list[j-] ==Case[j].value:
pass
else:
Case[j].comment=Comment('Actual Result:'+str(check_pre_list[j-]), 'Fail')
Case[j].font=Font(color=colors.RED) #TestCleanUp
Write(_AD_.MAPort, _AD_.TestVar.IN_KeyON_Value, )
Write(_AD_.MAPort, _AD_.TestVar.IN_PowON_Value, )
Write(_AD_.MAPort, _AD_.TestVar.IN_12Voltage_Value, )
Write(_AD_.MAPort, _AD_.TestVar.RCValue_Value, )
Write(_AD_.MAPort, _AD_.TestVar.RC2Value_Value, )
Write(_AD_.MAPort, _AD_.TestVar.IN_KeyStart_Value, )
time.sleep()
sum_num += #测试报告保存
ExcuteTime=time.strftime("%Y_%m_%d_%H_%M_%S", time.localtime())
TC.save("C:\\03_TestCase\\BenShaw\\ATC\\VCU_TC_LvPwrOff_"+ExcuteTime+".xlsx") stop_time = time.time()
ctime = stop_time-start_time if ctime<:
min =
sec = int(ctime % )
else:
min = int(ctime / )
sec = int(ctime % ) print("此功能用例耗费时间 %s分钟%s秒"%(min,sec))