当前位置: 首页 > news >正文

PyCharm+RobotFramework框架实现UDS自动化测试- (四)项目实战0x10

1.环境搭建

硬件环境:CANoe、待测设备(包含UDS诊断模块)
在这里插入图片描述

2.python+PyCharm环境

pip install robotframework
pip install robotframework-ride
pip install openpyxl
pip install udsoncan
pip install python-can
pip install can-isotp

3.项目目录

在这里插入图片描述

在这里插入图片描述

4. udstest.py


import can
from udsoncan.connections import PythonIsoTpConnection
import os, udsoncan, isotp, sys, binascii
import openpyxlclass udstest(object):def __init__(self):udsoncan.setup_logging()  # udslogdef get_xlsx(self, sheet):"获取指定Excel数据"excel = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'UDSTestcase.xlsx')  # 修改文件路径为.xlsxfile = openpyxl.load_workbook(excel)list = []sheet = file[sheet]  # 获得指定sheet数据row_value1 = [cell.value for cell in sheet[1]]  # 获取第1行的标题nrows = sheet.max_row  # 获取当前sheet行数ncols = sheet.max_column  # 获取当前sheet列数for i in range(2, nrows + 1):  # 从第2行遍历当前sheetrow = [cell.value for cell in sheet[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 listdef 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 = can.interface.Bus(bustype='vector',app_name='Test_Can',  # 根据实际情况修改channel=0,  # 根据实际情况修改bitrate=500000  # 根据实际情况修改)  # CAN总线初始化self.tp_addr = isotp.Address(isotp.AddressingMode.Normal_11bits, 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_commandif 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()

4. .robot

public.robot

*** Settings ***
Library           udstest.py  # 导入自定义库*** Variables ***
${txid}           0x772   # 用于传输的CANID
${rxid}           0x77A    # 用于接收的CANID*** Keywords ***
UDS_Test[Arguments]    ${test_data}set_can    ${txid}    ${rxid}    #CAN设置${respond}    Uds Request Respond    ${test_data['request']}    #UDS请求响应Should Be Equal    ${test_data['expected']}    ${respond}    #断言

eg.$10.robot

*** Settings ***
Suite Setup       获取$10服务测试数据
Test Setup
Test Teardown
Resource          Public.robot*** Test Cases ***
正响应-启动车载信息会话UDS_Test    ${test_data[0]}sleep    10负响应-不支持请求服务子功能UDS_Test    ${test_data[1]}负响应-请求报文数据长度不符合标准UDS_Test    ${test_data[2]}*** Keywords ***
获取$10服务测试数据${test_data}   Get Xlsx     $10Set Suite Variable    ${test_data}

5.导入的excel表格

在这里插入图片描述

6.结果

在这里插入图片描述
在这里插入图片描述

http://www.lryc.cn/news/524726.html

相关文章:

  • 【TCP】rfc文档
  • 【SpringCloud】黑马微服务学习笔记
  • 梯度提升决策树树(GBDT)公式推导
  • 【MySQL】表的基本操作
  • 项目中使用的是 FastJSON(com.alibaba:fastjson)JSON库
  • Flutter中PlatformView在鸿蒙中的使用
  • 音频入门(一):音频基础知识与分类的基本流程
  • 规避路由冲突
  • SQLmap 自动注入 -02
  • 4.JoranConfigurator解析logbak.xml
  • React 19 新特性总结
  • kafka学习笔记6 ACL权限 —— 筑梦之路
  • 【Java】Java抛异常到用户界面公共封装
  • 基于Redis实现短信验证码登录
  • 步入响应式编程篇(二)之Reactor API
  • Oracle SQL: TRANSLATE 和 REGEXP_LIKE 的知识点详细分析
  • RabbitMQ 在实际应用时要注意的问题
  • 算法日记8:StarryCoding60(单调栈)
  • 大象机器人发布首款穿戴式数据采集器myController S570,助力具身智能数据收集!
  • 【银河麒麟高级服务器操作系统】业务访问慢网卡丢包现象分析及处理过程
  • C语言之饭店外卖信息管理系统
  • 记一次 .NET某数字化协同管理系统 内存暴涨分析
  • 部门管理查询部门,nginx反向代理,前端如何访问到后端Tomcat 注解@RequestParam
  • JS通过ASCII码值实现随机字符串的生成(可指定长度以及解决首位不出现数值)
  • 速通Docker === 快速部署Redis主从集群
  • 论文笔记(六十三)Understanding Diffusion Models: A Unified Perspective(一)
  • stm32使用MDK5.35时遇到*** TOOLS.INI: TOOLCHAIN NOT INSTALLED
  • 在Ubuntu上安装RabbitMQ教程
  • 【算法】集合List和队列
  • uniapps使用HTML5的io模块拷贝文件目录