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

pytest生成测试用例,allure生成测试报告

测试代码

import time
import pytest
import allure
from selenium import webdriver
from selenium.webdriver.edge.service import Service
from webdriver_manager.microsoft import EdgeChromiumDriverManager
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC# edge的webdriver下载地址:
# https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/?form=MA13LH#downloads@allure.epic("用户管理")
@allure.feature("用户登录")
class TestLogin:# 这两个方法是固定的写法,它们是pytest的测试固件(fixture)约定def setup_method(self):"""测试前置条件"""service = Service(executable_path="C:/Users/Yoga7/my_allure/pythonProject/edgedriver_win64/msedgedriver.exe")self.driver = webdriver.Edge(service=service)# 窗口最大化self.driver.maximize_window()self.wait = WebDriverWait(self.driver, 5)# 打开测试网站self.driver.get("https://mayanan.cn/login.html")print("每个测试方法执行之前执行...")def teardown_method(self):"""测试后置清理"""if self.driver:self.driver.quit()print("每个测试方法执行之后执行...")@allure.story("成功登录")@allure.title("验证用户使用正确用户名和密码能够成功登录")@allure.severity(allure.severity_level.CRITICAL)def test_successful_login_with_phone(self):print("测试方法开始执行了...")with allure.step("准备测试数据"):username = input("请输入用户名")# password = input("请输入密码")password = input("请输入密码:")allure.attach(f"用户名:{username}\n密码:{password}", name="测试数据")with allure.step("输入用户名"):username_input = self.driver.find_element(By.NAME, "username")username_input.clear()username_input.send_keys(username)allure.attach(f"输入用户名:{username}", name="操作日志")time.sleep(0.5)with allure.step("输入密码"):password_input = self.driver.find_element(By.ID, "password")password_input.clear()password_input.send_keys(password)allure.attach(f"请输入密码完成", name="操作日志")time.sleep(0.5)with allure.step("点击登录按钮"):login_btn = self.driver.find_element(By.XPATH, "//button[text()='登录']")login_btn.click()allure.attach("点击登录按钮完成", name="操作日志")time.sleep(0.5)with allure.step("点击确定按钮"):# 只判断是否存在,返回alert对象或者False,不执行切换self.wait.until(EC.alert_is_present())# 切换到alert弹窗alert = self.driver.switch_to.alertalert.accept()time.sleep(5)with allure.step("验证登录成功"):try:h1 = self.wait.until(EC.presence_of_element_located((By.XPATH, "//h1[text()='DeepSeek AI大模型搜索']")))assert h1.is_displayed()login_success = Trueallure.attach("登录成功", name="验证结果")except Exception as err:login_success = Falseallure.attach("登录失败", name="验证结果")# 添加截图allure.attach(self.driver.get_screenshot_as_png(),name="登录结果页面",attachment_type=allure.attachment_type.PNG)assert login_success, "未检测到成功登录的标识"

1. pytest生成测试用例

pytest .\test_login02.py --alluredir=allure_results -v -s

2. allure生成测试报告

allure serve allure_results

3. 生成静态报告

allure generate .\allure_results -o .\allure_report --clean

http://www.dtcms.com/a/418777.html

相关文章:

  • 3ds Max to Unity_Ue桥接工具
  • LeetCode算法日记 - Day 56: 全排列II、话号码的字母组合
  • 天津住房城乡建设厅官方网站常州网站优化
  • 超易用前端使用Canvas海报图片生成器
  • 网站开发配置管理计划wordpress怎安装
  • --group-start/--group-end 能不能解决 OpenSSL 1.0 vs 1.1 的优先级问题?
  • 中国品牌网官方网站甘肃网络推广公司
  • 使用Trae配置MySQL MCP智能体进行数据库
  • RPA:开启数字化办公的新时代
  • 打工人日报#20250928
  • 怎么用html做移动网站吗wordpress网页设定
  • 门户网站做等保需要备案哪些php 家政网站
  • 扩散模型-上下文学习第一篇【In-Context Learning Unlocked for Diffusion Models】
  • 信息系统项目的成本管理(智能园区)
  • LeetCode:82.杨辉三角
  • 快速交付与弹性扩展,轻量化5GC融合边缘云与专网方案
  • maptalks-根据后端返回的坐标(WKT格式)在地图上绘制图斑
  • BERT 总结
  • java设计模式五、适配器模式
  • 语音识别的评价指标
  • 成都建设企业网站果麦传媒的网站怎么做的
  • python:Django 和 Vue.js 技术栈解析
  • (二十六)、Kuboard 部署网络问题 k8s 使用本地镜像 k8s使用 register本地镜像站 综合应用
  • 腾讯云上TKE集群中通过clb-ingress公网访问到后端服务
  • 信阳做网站公司编程培训机构加盟怎样
  • vps空间如何做网站备份如何提高网站的搜索
  • 广州免费自助建站开发建设工程什么意思
  • Apache Doris 4.0 AI 能力揭秘(二):为企业级应用而生的 AI 函数设计与实践
  • 用deepseek部署全自动的机器人--bytebot
  • 网站开发者模式下怎么保存图片建设网站空间