Python+Robot Framework实现UDS诊断自动化测试
一、环境搭建
1.概述
由于项目需要进行UDS诊断测试,所以对这方面进行了研究学习,网上很少能查询到相关资料,故记录一下UDS自动化测试开发过程,由于保密原则,案例都是Demo,希望能帮到感兴趣的朋友。
2.硬件环境
上位机:PCAN
PCAN-USB驱动:https://www.peak-system.com/fileadmin/media/files/pcan-basic.zip
下位机:ECM(发动机控制模块)
3.Python环境
下载地址:https://www.python.org/ftp/python/3.7.9/python-3.7.9-amd64.exe
pip3 install robotframework==3.2.2
pip3 install robotframework-ride==1.7.4.2
pip3 install xlrd==1.2.0
pip3 install udsoncan==1.14
pip3 install python-can==3.3.4
pip3 install can-isotp==1.7
二、项目介绍
1.文件目录
$10--$3E:L2层robot测试用例
Public.robot:L1层关键字方法
UDS_TestReport.zip:自动化测试报告
udstest.py:python封装自定义uds测试方法
UDSTestcase.xlsx:UDS诊断测试用例
2.udstest.py
# _*_ coding:utf-8 _*_ from can.interfaces.pcan.pcan import PcanBus
from udsoncan.connections import PythonIsoTpConnection
import xlrd, os, udsoncan, isotp, sys, binascii class udstest(object):
def __init__(self):
udsoncan.setup_logging() # udslog def get_xlsx(self, sheet):
"获取指定Excel数据"
excel = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'UDSTestcase.xlsx') # 获取用例文件路径
file = xlrd.open_workbook(excel)
list = []
sheet = file.sheet_by_name(sheet) # 获得指定sheet数据
row_value1 = sheet.row_values(0) # 获取第1行的标题
nrows = sheet.nrows # 获取当前sheet行数
ncols = sheet.ncols # 获取当前sheet列数
for i in range(1, nrows): # 从第2行遍历当前sheet
row = sheet.row_values(i) # 获取行数据
dict = {} # 创建空字典
for j in range(0, ncols): # 遍历sheet列,组成字典
if row_value1[j] == 'NO.':
dict[row_value1[j]] = int(row[j])
else:
dict[row_value1[j]] = row[j] # 从第一列开始,将每一列的数据与第1行的数据组成一个键值对,形成字典
list.append(dict) # 将字典添加list中
return list def set_can(self, txid, rxid):
"""can总线相关配置"""
if isinstance(txid, str) or isinstance(rxid, str):
txid = eval(txid)
rxid = eval(rxid)
isotp_params = {
'stmin': 5, # 流控帧间隔时间,0-127ms 或 100-900ns 值从 0xF1-0xF9
'blocksize': 0, # 流控帧单包大小,0表示不限制
'tx_padding': 0, # 当 notNone表示用于填充发送的消息的字节。
'rx_flowcontrol_timeout': 1000, # 在停止接收和触发之前等待流控制帧的毫秒数
'rx_consecutive_frame_timeout': 1000, # 在停止接收和触发 a 之前等待连续帧的毫秒数
}
try:
self.canbus = PcanBus(channel='PCAN_USBBUS1', bitrate=500000) # CAN总线初始化
self.tp_addr = isotp.Address(isotp.AddressingMode.Normal_29bits, txid=txid, rxid=rxid) # 网络层寻址方法
tp_stack = isotp.CanStack(bus=self.canbus, address=self.tp_addr, params=isotp_params) # 网络/传输层(IsoTP 协议)
self.conn = PythonIsoTpConnection(tp_stack) # 应用层和传输层之间建立连接 except:
print(sys.exc_info()[1])
else:
print('CAN配置成功') def uds_request_respond(self, request_command):
"""发送uds请求和接收uds响应"""
if not isinstance(request_command, str): # 判断request_command数据类型
request_command = str(int(request_command))
requestPdu = binascii.a2b_hex(request_command.replace(' ', '')) # 处理request_command
if not self.conn.is_open():
self.conn.open() # 打开连接
try:
self.conn.specific_send(requestPdu) # 发送uds请求
except:
print("发送请求失败")
else:
print('UDS发送请求:%s' % request_command) try:
respPdu = self.conn.specific_wait_frame(timeout=3) # 接收uds响应
except:
print('响应数据失败')
else:
res = respPdu.hex().upper()
respond = ''
for i in range(len(res)):
if i % 2 == 0:
respond += res[i]
else:
respond += res[i] + ' '
print('UDS响应结果:%s' % respond)
self.conn.close() # 关闭连接
self.canbus.shutdown() # 关闭总线
return respond.strip()
3.UDSTestcase.xlsx
3.UDS_TestReport
三、源码地址
git:https://github.com/xiongye105554598/UDS_AutoTest.git
Python+Robot Framework实现UDS诊断自动化测试的更多相关文章
- python+robot framework实现测报告定制化和邮件发送
前面已经介绍了python+robot framework自动化框架和基本原理的实现,详情请看 python+robot framework接口自动化测试 本章主要讲解报告已经产生那如何以自动化的方式 ...
- Linux CentOS下Python+robot framework环境搭建
Linux CentOS下Python+robot framework环境搭建 by:授客 QQ:1033553122 操作系统环境:CentOS 6.5-x86_64 下载地址:http://w ...
- python+robot framework接口自动化测试
python+requests实现接口的请求前篇已经介绍,还有不懂或者疑问的可以访问 python+request接口自动化框架 目前我们需要考虑的是如何实现关键字驱动实现接口自动化输出,通过关键字的 ...
- Linux CentOS下Python+robot framework环境搭建
转载自:http://blog.sina.com.cn/s/blog_13cc013b50102vof1.html 操作系统环境:CentOS 6.5-x86_64 下载地址:http://www.c ...
- Robot Framework与Web界面自动化测试学习笔记:简单例子
假设环境已经搭建好了.这里用RIDE( Robot Framework Test Data Editor)工具来编写用例.下面我们对Robot Framework简称rf. 我们先考虑下一个最基本的登 ...
- Python + Robot Framework 环境搭建
一.Python 安装 说明:由于RIDE是基于python2.x开发,后期未做python3.x兼容,所以这里安装python2.7. 链接: https://pan.baidu.com/s/1yf ...
- Robot Framework与Web界面自动化测试:简单例子
假设环境已经搭建好了.这里用RIDE( Robot Framework Test Data Editor)工具来编写用例.下面我们对Robot Framework简称rf. 我们先考虑下一个最基本的登 ...
- <转>准备Eclips+python+robot framework环境
关于python: path添加:C:\Python27;C:\Python27\Scripts; 新加一项: PYTHON_HOME C:\Python27 再不行的话,加一个用户变量: P ...
- Robot Framework进行web ui自动化测试,浏览器配置说明
转载请注明出处,谢谢: chrome浏览器: 1.从如下地址下载与本地浏览器版本号一致的chromedriver.exe驱动文件: http://chromedriver.storage.google ...
随机推荐
- C/C++ Qt TreeWidget 单层树形组件应用
TreeWidget 目录树组件,该组件适用于创建和管理目录树结构,在开发中我们经常会把它当作一个升级版的ListView组件使用,因为ListView每次只能显示一列数据集,而使用TableWidg ...
- springboot 配置多数据源实例代码(分包方式)
目录 1.数据库 2.pom与yml 2.1.pom中的依赖部分 2.2.yml数据库配置部分 3.数据源配置类 DataSourceConfig 3.1.DataSourceConfig1.java ...
- BZOJ 4556 [HEOI2016/TJOI2016]字符串
BZOJ 4556 [HEOI2016/TJOI2016]字符串 其实题解更多是用后缀数组+数据结构的做法,貌似也不好写. 反正才学了 sam 貌似比较简单的做法. 还是得先二分,然后倍增跳到 $ s ...
- P5896 [IOI2016]aliens
*IX. P5896 [IOI2016]aliens DP 优化方法大杂烩,详解 wqs 二分及其注意事项,斜率优化等其它 DP 优化方法. **** 团队赛 T6,没想到是 IOI 原题.当时看出来 ...
- excel--CLEAN()函数,解决为什么看着相同的字符串但是len()长度不同
CLEAN()函数能够有效解决去除字符串中隐藏的字符(这些字符是TRIM()去除不掉的)
- 进阶版的java面试
来自一名2019届应届毕业生总结的Java研发面试题汇总(2019秋招篇) 2018年Java研发工程师面试题 Java研发工程师面试题(Java基础) ...
- 网站性能调优实战-学相伴KuangStudy
面对并发我们是如何优化KuangStudy网站性能的? 每个项目都会随着用户和数据的增长调整架构,来面对未来的问题,我们也不例外,在1月5号我们平台正式公测后,引起了很多观众的热烈反响,仅仅4天,注册 ...
- 第一个基础框架 — mybatis框架 — 更新完毕
1.Mybatis是什么? 百度百科一手 提取一下重点: MyBatis 本是apache的一个开源项目iBatis.即:mybatis的原名为:ibatis 2010年迁移到google code, ...
- IT四大名著
标题耸人听闻,sorry. CPU.操作系统.编译器和数据库我都不会.我英语也不行,但我认识所有的字母.:-) 万一有人感兴趣呢?https://sqlite.org/doclist.htmlThe ...
- 大数据学习day16------第三阶段-----scala04--------1. 模式匹配和样例类 2 Akka通信框架
1. 模式匹配和样例类 Scala有一个十分强大的模式匹配机制,可以应用到很多场合:如switch语句.类型检查等.并且Scala还提供了样例类,对模式匹配进行了优化,可以快速进行匹配 1.1 模式匹 ...