在使用ECU TEST软件进行自动化测试的时候,由于前期测试经验不足,经常不能够把一个功能测完整。比如开关灯的功能。当开灯时,控制器返回到总线上的相关信号为1,当关灯时相关信号为2,同时控制器有硬线输出信号到板卡。前期测试工程师只关注报文交互而忽视了硬线检测,因此开发相关脚本在原有案例的特定位置添加硬线检测信号,保证每一次在读取报文值的时候也会检测硬线信号,其余功能也可沿用。 相关函数/类的解释已在之前的文章中指出,可自行翻阅。
import os
import sys
sys.path.append(r'D:\ECU_TEST 2020.4\Templates\ApiClient')
path = r'D:\ECU_TEST 2020.4\Packages'
from ApiClient import ApiClient
api = ApiClient
def get_pkg(path):
pkg_list = []
for root, dirs, files in os.walk(path):
for filename in files:
if '.pkg' in filename:
pkg_list.append(root + '\\' + filename)
return pkg_list
def add_head_light_hardline(pkg):
PKG = api.PackageApi.OpenPackage(pkg)
TEST_BLOCK = PKG.GetTestSteps()
for block in TEST_BLOCK:
if block.GetType == 'TsBlock':
i = 0
for step in block.GetTestSteps():
i = i + 1
if 'XXXXXXXX' in step.GetActionColumnText():
mapping1 = api.PackageApi.MappingApi.CreateGenericMappingItem(variable=None, referenceName='硬线信号')
add_step = api.PackageApi.TestStepApi.CreateTsRead(mapping1)
if step.GetActionColumnText() == 'value == 1':
add_step.SetExpectationExpression('value == 1')
else:
add_step.SetExpectationExpression('value == 0')
block.InsertTestStep(add_step, i)
else:
print(block.GetType())
PKG.Save()
if __name__ == '__main__':
for pkg in get_pkg(path):
add_head_light_hardline(pkg)
|