尧图网络 高端网站定制 · 原创设计
免费咨询热线
400-888-6620
免费获取方案
智能体测开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}
RELATED

相关推荐

一次监管整改,全部门加班2个月,就因为没做超自动化巡检

一次监管整改,全部门加班2个月,就因为没做超自动化巡检

“通知下来了,下周三,监管现场检查。”这条消息让运维总监老张手里的咖啡杯差点没拿稳。距离上一次等保测评过去还不到一年,本以为可以安稳到年底,没想到监管的“回头看”抽查说来就来。更让老张心里发虚的是——他知道&#xff0…

📅 2026/9/14 1:08:09
VirtualBox虚拟机安装与优化全指南

VirtualBox虚拟机安装与优化全指南

1. VirtualBox虚拟机入门:为什么选择它? VirtualBox作为Oracle旗下的开源虚拟化解决方案,已经成为个人开发者和小型团队的首选工具。我最初接触VirtualBox是在2013年,当时需要在一台Windows笔记本上测试Linux环境,经过…

📅 2026/9/13 12:24:26
ARM Cortex-M4F内核架构深度解析:从FPU、NVIC到调试系统实战

ARM Cortex-M4F内核架构深度解析:从FPU、NVIC到调试系统实战

1. 项目概述在嵌入式开发的世界里,选对一颗“心脏”——微控制器(MCU)的处理器内核,往往决定了整个项目的性能上限和开发体验的下限。对于需要兼顾实时控制、信号处理甚至简单算法运算的应用,比如智能家居的网关、工业…

📅 2026/8/22 18:41:26
MORE NEWS

更多资讯

📰

离散粒子群算法在航天器在轨服务任务分配中的应用

简介:针对多航天器协同在轨服务中的任务分配问题,这份PDF论文提出了基于离散粒子群优化(DPSO)算法的求解策略。资源面向航天工程、智能优化算法研究者及相关专业学生,适合作为算法设计、数学建模与任务分配流程学习的参…

📰

书霸AI科研绘图怎么选:基础版还是专业版

www.shubaai.com写论文时,图表往往不是“最后顺手做一下”的装饰,而是帮助读者理解研究过程、实验结果和逻辑关系的重要证据。面对不同绘图工具,很多人真正纠结的并不是能不能生成图片,而是:自己的论文到底适合哪一种工…

📰

书霸AI:论文图表正从绘制走向表达

www.shubaai.com过去谈科研绘图,大家关注的是“图怎么画”;未来真正拉开论文质量差距的,却是“为什么画这张图,以及它能否支撑结论”。从书霸AI科研绘图工作台可以看到,AI写作工具正在由文字生成向数据表达延伸&#x…

📰

基于Spring Boot与Vue的土地资源管理子系统设计与实现

1. 从农村土地管理的真实痛点出发:这个子系统到底要做什么这两年我在后台收到不少私信,都在问同一个问题:毕设到底选什么题目才能既好过审、又好实现、还不容易烂大街?说句实在话,Spring Boot Vue 这类前后端分离的管…

📰

Maven多模块打包成一个可执行胖JAR实战指南

多模块项目在本地跑得好好的,一到打包环节就犯愁——mvn package一下,target目录里躺着七八个 JAR,common.jar、dao.jar、service.jar、web.jar各占一个坑。部署的时候你得挨个往服务器上拷,启动脚本里拼一长串classpath&#xff…

📰

研究论文调用智能体,TaoToken 消耗从哪看

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

TODAY

今日更新

THIS WEEK

本周精选

THIS MONTH

本月热门

读完文章,想聊聊您的网站?

告诉我们您的行业与需求,资深顾问一对一梳理方案与报价,全程免费。

📞 💬