智能体测开Day31

发布时间:2026/9/29 15:32:43

智能体测开Day31
test_skipimport pytest version V1R2 pytest.fixture def login(): print(前置) yield print(后置) def test_001(login): print(测试用例添加成员) pytest.mark.skip def test_002(login): print(测试用例修改成员) pytest.mark.skip(reason功能有缺陷未处理) def test_003(login): print(测试用例修改成员) pytest.mark.skipif(version V1R1,reason 功能有缺陷未处理) def test_004(login): print(测试用例修改成员)UI自动化测试环境搭建 seleniumpytest数据驱动去实现一个UI自动化测试框架 UI自动化测试是投入产出比ROI最低的测试类型。它脆弱UI易变、昂贵编写和维护耗时、运行慢。 实现功能 1代码分层管理 2数据的分层管理数据驱动 3支持生成测试报告 4支持日志的记录和打印方便定位问题 5将测试报告发送给其他测试人员 POM模型去实现page object model 将页面元素的定位和基本操作封装为一个类基础类 通过其他类去继承该基础类提高代码的复用率并且方便维护代码 代码分层 测试层整个框架的入口是测试的总入口 data层数据层可以存储测试数据文件配置数据文件 pageobject层核心层业务逻辑层类里面实现了对某些功能的逻辑处理 base层基础层 定位元素操作元素的基础类 文件进行读取解析类 日志管理器 报告层生成的报告数据和报告文件 日志层存储日志文件 自动化测试代码分层管理basepage基础层元素定位点击发送等 获取驱动的函数 基础类 关闭浏览器 打开某个页面 定位元素 点击 发送信息 切换iframe 切换到默认层 切换到上一层 选中 根据文本 根据下拉框选中 根据value选中 截图 import time from selenium import webdriver from selenium.webdriver.support import expected_conditions from selenium.webdriver.support.select import Select from selenium.webdriver.support.wait import WebDriverWait def get_Driver(browserEdge): if browserChrome: driver webdriver.Chrome() elif browserFirefox: driver webdriver.Firefox() elif browserSafari: driver webdriver.Safari() else: driver webdriver.Edge() return driver class BasePage: def __init__(self,driver): self.driver driver # 打开网页 def open(self,url): self.driver.get(url) # 窗口最大化 self.driver.maximize_window() # 隐式等待 self.driver.implicitly_wait(3) # 关闭 def close(self): self.driver.close() # 退出 def quit(self): self.driver.quit() # 定位元素 def locator_element(self,locatorstr): 定位元素 :param locatorstr: 定位元素的字符串格式类似于 id xxx class name xxx tag namexxx :return: try: # 处理字符串 s locatorstr.split() locator (s[0].strip(),s[1].strip()) a WebDriverWait(self.driver, 3, 0.3).until(expected_conditions.presence_of_element_located(locatorlocator)) print(f定元素【{locatorstr}】成功) return a except Exception as e: print(f定元素【{locatorstr}】出错{e}) # 点击 def click(self,locatorstr): try: self.locator_element(locatorstr).click() print(f点击元素【{locatorstr}】成功) except Exception as e: print(f点击元素【{locatorstr}】出错{e}) # 发送信息 def send(self,locatorstr,text): try: self.locator_element(locatorstr).send_keys(text) print(f给元素【{locatorstr}】发送【{text}】成功) except Exception as e: print(f给元素【{locatorstr}】发送【{text}】出错{e}) # 切入iframe def enter_Iframe(self,locatorstr): try: # 切换到iframe中 self.driver.switch_to.frame(self.locator_element(locatorstr)) print(f切入iframe【{locatorstr}】成功) except Exception as e: print(f切入iframe【{locatorstr}】出错{e}) # 切换到默认层 def switch_To_Default_Content(self): try: self.driver.switch_to.default_content() print(f切换到最外层成功) except Exception as e: print(f切换到最外层出错{e}) # 切换到上一层 def switch_To_Parent_Frame(self): try: self.driver.switch_to.parent_frame() print(f切换到上一层成功) except Exception as e: print(f切换到上一层出错{e}) # 根据下拉框选中 def select_By(self,locatorstr): try: select Select(self.locator_element(locatorstr)) print(f选择下拉框【{locatorstr}】成功) return select except Exception as e: print(f选择下拉框【{locatorstr}】出错{e}) # 下拉框根据文本选中内容 def select_By_Text(self,locatorstr,visible_text): try: self.select_By(locatorstr).select_by_visible_text(visible_text) print(f选择下拉框文本选中内容【{locatorstr}】成功) except Exception as e: print(f选择下拉框文本选中内容【{locatorstr}】出错{e}) # 下拉框根据value选中 def select_By_Value(self,locatorstr,value): try: self.select_By(locatorstr).select_by_value(value) print(f选择下拉框value选中内容【{locatorstr}】成功) except Exception as e: print(f选择下拉框value选中内容【{locatorstr}】出错{e}) # 截图 def takeScreenshot(self): try: filename time.strftime(%Y%m%d%H%M%S, time.localtime()) self.driver.save_screenshot(fxinqidian_ranzhi_index_{filename}.png) print(f截图成功) except Exception as e: print(f截图出错{e}) if __name__ __main__: driver get_Driver() # 打开网页 bp BasePage(driver) bp.open(http://127.0.0.1/ranzhi/www) # 发送信息 bp.send(id account,admin) bp.send(id password,123456) bp.click(id submit) # 点击后台管理 bp.click(id s-menu-superadmin) time.sleep(1) # 切换到iframe中 bp.enter_Iframe(id iframe-superadmin) # 点击添加成员 bp.click(link text 添加成员) time.sleep(2) # 添加用户名 bp.send(id account,lucy) # 添加真实姓名 bp.send(id realname,伍二宝) # 选择性别 bp.click(id genderm) # 选择部门 # 下拉框创建select对象 # 根据文本选中 bp.select_By_Text(id dept,/市场部) # 选择角色 # 下拉框创建select对象 # 根据value选中 bp.select_By_Value(id role,pm) # 添加密码 bp.send(id password1,123456) # 重复密码 bp.send(id password2,123456) # 添加邮箱 bp.send(id email,1584561163.com) # 点击保存 bp.click(id submit) time.sleep(10) # 截图 bp.takeScreenshot() # iframe切换默认层 bp.switch_To_Default_Content() # 签退 bp.click(link text 签退)read_file(解析文件方法) 获取项目路径 解析csv 解析ini 解析excel import configparser import os.path def get_project_path(): # 获取父路径 path os.path.dirname(__file__) path os.path.dirname(path) return path # 解析ini文件 def read_ini(filename,section,key): 解析ini文件返回一个字符串类型 :param filename: 文件名称 :param section: 节点名 :param key: 关键词 :return: value值 # 获取完整的文件路径 filepath get_project_path()\\data\\filename cp configparser.ConfigParser() cp.read(filepath,encodingutf-8) value cp.get(section,key) return value if __name__ __main__: url read_ini(evn.ini,evn,url) print(url) dbinfo read_ini(evn.ini,mysql,dbinfo) print(dbinfo) d eval(dbinfo) print(type(d)) #class dictevn.ini数据ini文件[evn] ;节点起分类作用 urlhttp://127.0.0.1/ranzhi/www useradmin pwd123456 [mysql] dbinfo{user:root,pwd:123456,host:127.0.0.1,port:3306,database:ranzhi,charset:utf8}

相关新闻

洁净设备空间革命:超薄FFU如何突破层高极限?本刊深度探访艾立工业全产业链制造现场——设计制造能力展示

洁净设备空间革命:超薄FFU如何突破层高极限?本刊深度探访艾立工业全产业链制造现场——设计制造能力展示

2026/9/29 15:31:58

在老旧洁净厂房升级、实验室改造以及高端精密制造的特定场景中,层高限制始终是工程师们无法回避的痛点。传统FFU(风机过滤单元)的箱体厚度通常在280mm至350mm之间,当建筑夹层有限或需要密集排布公用设施时,每一厘米的压…

SerDes芯片BIST与BER测试:原理、配置与信号完整性实战

SerDes芯片BIST与BER测试:原理、配置与信号完整性实战

2026/9/29 16:28:15

1. 项目概述与核心价值在高速数字系统设计中,比如高清视频传输、工业相机数据采集或者车载显示屏驱动,我们常常面临一个头疼的问题:如何把几十根并行的数据线,稳定可靠地传输到几米甚至十几米外的接收端?传统的并行总线…

AI产品经理都在偷用的流程图速建法:1个Prompt+2个插件+5分钟出图,今日限时开源

AI产品经理都在偷用的流程图速建法:1个Prompt+2个插件+5分钟出图,今日限时开源

2026/8/23 4:17:29

更多请点击: https://codechina.net 第一章:AI流程图制作教程 AI流程图是梳理机器学习项目逻辑、可视化模型训练与推理链路的关键工具。现代AI开发中,流程图不再仅用于静态展示,更需支持可执行语义、版本协同与自动代码生成。本章…

CANN/GE ACL数据集缓冲区添加函数

CANN/GE ACL数据集缓冲区添加函数

2026/9/28 4:08:17

aclmdlAddDatasetBuffer 【免费下载链接】ge GE(Graph Engine)是面向昇腾的图编译器和执行器,提供了计算图优化、多流并行、内存复用和模型下沉等技术手段,加速模型执行效率,减少模型内存占用。 GE 提供对 PyTorch、Te…

用ffmpeg高效批量调整图片尺寸的实战指南

用ffmpeg高效批量调整图片尺寸的实战指南

2026/9/28 16:01:49

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

Transformers 音频特征提取工具库 audio_utils 全解析:从 Mel 刻度换算到对数 Mel 频谱

Transformers 音频特征提取工具库 audio_utils 全解析:从 Mel 刻度换算到对数 Mel 频谱

2026/9/28 2:15:29

Transformers 音频特征提取工具库 audio_utils 全解析:从 Mel 刻度换算到对数 Mel 频谱 【免费下载链接】transformers 🤗 Transformers: the model-definition framework for state-of-the-art machine learning models in text, vision, audio, and mu…

RustFS 多节点集群重启与滚动升级实战:Readiness、Quorum 与 Degraded 模式完全指南

RustFS 多节点集群重启与滚动升级实战:Readiness、Quorum 与 Degraded 模式完全指南

2026/9/28 3:14:54

RustFS 多节点集群重启与滚动升级实战:Readiness、Quorum 与 Degraded 模式完全指南 【免费下载链接】rustfs 🚀2.3x faster than MinIO for 4KB object payloads. RustFS is an open-source, S3-compatible high-performance object storage system sup…

Java Integer缓存揭秘:128陷阱原理、避坑与面试全解

Java Integer缓存揭秘:128陷阱原理、避坑与面试全解

2026/9/28 3:58:00

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

RustFS Scanner 数据用量发布权威性决策:配额准入如何获得可用的权威依据

RustFS Scanner 数据用量发布权威性决策:配额准入如何获得可用的权威依据

2026/9/28 3:47:14

RustFS Scanner 数据用量发布权威性决策:配额准入如何获得可用的权威依据 【免费下载链接】rustfs 🚀2.3x faster than MinIO for 4KB object payloads. RustFS is an open-source, S3-compatible high-performance object storage system supporting mi…

远程协作的工作台整理

远程协作的工作台整理

2026/9/28 16:01:48

远程协作的工作台整理远程协作的核心不是再加一个工具,而是让交接信息足够完整。异步任务要写明目标、输入位置、完成标准和需要决策的人。 工作台的最小配置 将日程、待办、代码和沟通入口收拢到少数固定位置;通知按紧急程度分层。工作台不需要模仿办公…

持续集成 流水线自动化与 声明式交付 实践:原型怎样变成可用功能

持续集成 流水线自动化与 声明式交付 实践:原型怎样变成可用功能

2026/9/28 5:05:21

持续集成 流水线自动化与 声明式交付 实践:原型怎样变成可用功能分类:[AI/大模型]细分主题:AI 增强型 CI/CD 流水线自动化与 GitOps 实践:Agent 工作流、工具调用与任务拆解:从原型到生产的验收清单很多团队在尝试用大…

容器编排 生产环境运维与排障实战:复盘记录怎样真正派上用场

容器编排 生产环境运维与排障实战:复盘记录怎样真正派上用场

2026/9/28 16:01:48

容器编排 生产环境运维与排障实战:复盘记录怎样真正派上用场分类:[工程技术]细分主题:Kubernetes 生产环境运维与排障实战:可复制的项目复盘模板与决策记录大部分团队的事故复盘报告,最后都变成了躺在 Confluence 或钉…