Files
WebAutoTest/commons/assert_functions.py
CNWei 92d06dd9cf init: 初始化项目
- 创建了基本的项目结构
- 添加了 .gitignore 文件
- 配置了基本的开发环境
- 添加清华镜像源
- 设置了基础的文件夹和文件(如 commons, utils, POM, pytest.ini)

项目说明:
- [项目名称]:Web自动化测试
- [项目描述]:基于pytest,selenium的自动化测试工具
- [开发环境]:Python
2025-04-14 23:05:39 +08:00

85 lines
1.8 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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