feat: 移除DDT模式的支持,改用POM模式
- 删除 data_loader 数据驱动加载器。 - 删除 test_keyword_sample 测试执行代码 - 新增 base_page [DDT模式极大的限制了灵活性,增加了代码的编写难度,另外项目使用者都会编码故而转用只针对POM模式进行优化]
This commit is contained in:
45
core/base_page.py
Normal file
45
core/base_page.py
Normal file
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env python
|
||||
# coding=utf-8
|
||||
|
||||
"""
|
||||
@author: CNWei,ChenWei
|
||||
@Software: PyCharm
|
||||
@contact: t6g888@163.com
|
||||
@file: base_page
|
||||
@date: 2026/1/26 17:33
|
||||
@desc:
|
||||
"""
|
||||
import logging
|
||||
from typing import Type, TypeVar
|
||||
from core.driver import CoreDriver
|
||||
# 定义一个泛型,用于类型推断(IDE 依然会有补全提示)
|
||||
T = TypeVar('T', bound='BasePage')
|
||||
logger = logging.getLogger(__name__)
|
||||
class BasePage:
|
||||
def __init__(self, driver: CoreDriver):
|
||||
self.driver = driver
|
||||
# 这里放全局通用的 Page 属性和逻辑
|
||||
# --- 页面工厂:属性懒加载 ---
|
||||
# 这样你可以在任何页面直接通过 self.home_page 访问首页
|
||||
@property
|
||||
def home_page(self):
|
||||
from page_objects.home_page import HomePage
|
||||
return HomePage(self.driver)
|
||||
|
||||
@property
|
||||
def login_page(self):
|
||||
from page_objects.login_page import LoginPage
|
||||
return LoginPage(self.driver)
|
||||
|
||||
# 封装一些所有页面通用的元动作
|
||||
def get_toast(self, text):
|
||||
return self.driver.is_visible("text", text)
|
||||
|
||||
def to_page(self, page_class: Type[T]) -> T:
|
||||
"""
|
||||
通用的页面跳转/获取方法
|
||||
:param page_class: 目标页面类
|
||||
:return: 目标页面的实例
|
||||
"""
|
||||
logger.info(f"跳转到页面: {page_class.__name__}")
|
||||
return page_class(self.driver)
|
||||
@@ -177,8 +177,10 @@ if __name__ == "__main__":
|
||||
cond1 = get_condition("toast_visible", "保存成功")
|
||||
print(cond1)
|
||||
# 调用闭包生成的条件
|
||||
cond2 = get_condition("is_element_present", (By.ID, "submit"))
|
||||
print(cond2)
|
||||
# cond2 = get_condition("is_element_present", (By.ID, "submit"))
|
||||
# print(cond2)
|
||||
cond3 = get_condition(EC.presence_of_element_located, (By.ID, "submit"))
|
||||
print(cond3)
|
||||
cond4 = get_condition("system_ready", (By.ID, "submit"))
|
||||
print(cond4)
|
||||
# WebDriverWait(driver, 10).until(cond1)
|
||||
|
||||
@@ -16,7 +16,7 @@ from pathlib import Path
|
||||
# 项目根目录 (core 的上一级)
|
||||
# BASE_DIR = Path(__file__).parent.parent
|
||||
BASE_DIR = Path(__file__).resolve().parents[1] # 获取根路径(绝对路径)
|
||||
print(BASE_DIR)
|
||||
# print(BASE_DIR)
|
||||
# --- 目录配置 ---
|
||||
OUTPUT_DIR = BASE_DIR / "outputs"
|
||||
LOG_DIR = OUTPUT_DIR / "logs"
|
||||
|
||||
Reference in New Issue
Block a user