init: 初始化项目
- 创建了基本的项目结构 - 添加了 .gitignore 文件 - 配置了基本的开发环境 - 添加清华镜像源 - 设置了基础的文件夹和文件(如 commons, utils, POM, pytest.ini) 项目说明: - [项目名称]:Web自动化测试 - [项目描述]:基于pytest,selenium的自动化测试工具 - [开发环境]:Python
This commit is contained in:
84
commons/assert_functions.py
Normal file
84
commons/assert_functions.py
Normal file
@@ -0,0 +1,84 @@
|
||||
#!/usr/bin/env python
|
||||
# coding=utf-8
|
||||
|
||||
"""
|
||||
@author: CNWei
|
||||
@Software: PyCharm
|
||||
@contact: t6i888@163.com
|
||||
@file: assert_functions
|
||||
@date: 2025/4/13 21:06
|
||||
@desc:
|
||||
"""
|
||||
|
||||
import logging
|
||||
from dataclasses import dataclass
|
||||
from typing import Dict, Callable, TypeVar, Tuple
|
||||
from typing import Literal
|
||||
from typing import Optional
|
||||
from typing import Union
|
||||
|
||||
from selenium.webdriver.remote.webdriver import WebDriver
|
||||
from selenium.webdriver.remote.webdriver import WebElement
|
||||
|
||||
# from commons.driver import KeyWordDriver
|
||||
|
||||
# from selenium.webdriver.support import expected_conditions as EC
|
||||
|
||||
# __all__ = ["EC","custom_ec"]
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
T = TypeVar("T")
|
||||
WebDriverOrWebElement = Union[WebDriver, WebElement]
|
||||
|
||||
custom_asserts = {
|
||||
|
||||
}
|
||||
|
||||
|
||||
def register(name: str | None = None):
|
||||
def decorator(func):
|
||||
if name is not None:
|
||||
custom_asserts[name] = func
|
||||
|
||||
custom_asserts[func.__name__] = func
|
||||
return func
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
@register()
|
||||
def get_text_(driver,*args) -> T:
|
||||
"""
|
||||
无参预期条件函数
|
||||
driver
|
||||
- WebDriver的实例(Ie、Firefox、Chrome或远程)或 一个WebElement
|
||||
- driver形参不可省略,即使不使用
|
||||
:return:
|
||||
"""
|
||||
_ = driver
|
||||
logger.warning(f"{args=}")
|
||||
list_ = [1, 2, 3, 4, 5, 6]
|
||||
for item in list_:
|
||||
logger.info(item)
|
||||
if item == 5:
|
||||
# logger.info(item)
|
||||
return item
|
||||
|
||||
|
||||
# @register()
|
||||
# def get_value(locator: Tuple[str, str]) -> Callable[
|
||||
# [KeyWordDriver], Union[Literal[False], WebElement]]:
|
||||
# """
|
||||
# 有参预期条件函数
|
||||
# :param locator:
|
||||
# :return:
|
||||
# """
|
||||
#
|
||||
# def _predicate(driver: KeyWordDriver):
|
||||
# try:
|
||||
# return driver.find_element(*locator)
|
||||
# except Exception as e:
|
||||
# return False
|
||||
#
|
||||
# return _predicate
|
||||
Reference in New Issue
Block a user