feat(base_page): 新增BasePage基础操作
- 优化 is_visible,支持快速状态检查。 - 新增 log_screenshot/log_screenshot_bytes 截图。 - 更新 README.md。 - 其他优化。
This commit is contained in:
@@ -8,4 +8,45 @@
|
||||
@file: conftest
|
||||
@date: 2026/1/19 14:08
|
||||
@desc:
|
||||
"""
|
||||
"""
|
||||
import pytest
|
||||
import allure
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
|
||||
def pytest_runtest_makereport(item, call):
|
||||
"""
|
||||
本钩子函数会在每个测试阶段(setup, call, teardown)执行后被调用。
|
||||
item: 测试用例对象
|
||||
call: 测试执行阶段的信息
|
||||
"""
|
||||
# 1. 先执行常规的用例报告生成逻辑
|
||||
outcome = yield
|
||||
report = outcome.get_result()
|
||||
|
||||
# 2. 我们只关注测试执行阶段 ("call")
|
||||
# 如果该阶段失败了(failed),则触发截图
|
||||
if report.when == "call" and report.failed:
|
||||
# 3. 从测试用例中获取 driver 实例
|
||||
# 假设你在 fixture 中注入的参数名为 'driver'
|
||||
driver_instance = item.funcargs.get("driver")
|
||||
|
||||
if driver_instance:
|
||||
try:
|
||||
# 4. 调用你在 CoreDriver 中实现的底层截图方法
|
||||
# 这里的 name 我们可以动态取测试用例的名字
|
||||
case_name = item.name
|
||||
file_path = driver_instance.full_screen_screenshot(name=f"CRASH_{case_name}")
|
||||
|
||||
# 5. 如果路径存在,将其关联到 Allure 报告
|
||||
if file_path:
|
||||
p = Path(file_path)
|
||||
if p.exists():
|
||||
allure.attach.file(
|
||||
source=p,
|
||||
name="【故障现场自动截图】",
|
||||
attachment_type=allure.attachment_type.PNG
|
||||
)
|
||||
except Exception as e:
|
||||
print(f"故障自动截图执行失败: {e}")
|
||||
53
test_cases/test_api_demos.py
Normal file
53
test_cases/test_api_demos.py
Normal file
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env python
|
||||
# coding=utf-8
|
||||
|
||||
"""
|
||||
@author: CNWei,ChenWei
|
||||
@Software: PyCharm
|
||||
@contact: t6g888@163.com
|
||||
@file: test_api_demos
|
||||
@date: 2026/1/30 17:42
|
||||
@desc:
|
||||
"""
|
||||
import logging
|
||||
|
||||
import allure
|
||||
import pytest
|
||||
|
||||
from page_objects.api_demod_home import HomePage
|
||||
from page_objects.api_demos_views import ViewsPage
|
||||
|
||||
# 配置日志
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@allure.epic("ApiDemos")
|
||||
@allure.feature("登录认证模块")
|
||||
class TestApiDemos:
|
||||
# @allure.story("常规登录场景")
|
||||
@allure.title("使用合法账号登录成功")
|
||||
@allure.severity(allure.severity_level.BLOCKER)
|
||||
@allure.description("""
|
||||
验证用户在正常网络环境下:
|
||||
1. 处理初始化弹窗和广告
|
||||
2. 选择证券登录类型
|
||||
3. 输入正确凭证后成功跳转至‘交易’首页
|
||||
""")
|
||||
@allure.link("https://docs.example.com/login_spec", name="登录业务说明文档")
|
||||
@allure.issue("BUG-1001", "已知偶发:部分机型广告Banner无法滑动")
|
||||
def test_api_demos_success(self, driver,user):
|
||||
"""
|
||||
测试场景:使用正确的用户名和密码登录成功
|
||||
"""
|
||||
api_demos = HomePage(driver)
|
||||
|
||||
# 执行业务逻辑
|
||||
api_demos.click_text()
|
||||
api_demos.click_unicode()
|
||||
# 断言部分使用 allure.step 包装,使其在报告中也是一个可读的步骤
|
||||
with allure.step("最终校验:检查是否进入首页并显示‘交易’标题"):
|
||||
actual_text = api_demos.get_home_text()
|
||||
assert actual_text == "Text"
|
||||
|
||||
# 页面跳转
|
||||
api_demos.go_to(ViewsPage).screenshot_views()
|
||||
api_demos.delay(5)
|
||||
Reference in New Issue
Block a user