update
This commit is contained in:
parent
768602cf06
commit
05f06be1d9
62
conftest.py
62
conftest.py
|
@ -23,37 +23,37 @@ from case_utils.data_handle import FakerData
|
|||
|
||||
|
||||
# ------------------------------------- START: pytest钩子函数处理---------------------------------------#
|
||||
@pytest.mark.hookwrapper
|
||||
def pytest_runtest_makereport(item, call):
|
||||
"""设置列"用例描述"的值为用例的标题title"""
|
||||
outcome = yield
|
||||
# 获取调用结果的测试报告,返回一个report对象
|
||||
# report对象的属性包括when(steup, call, teardown三个值)、nodeid(测试用例的名字)、outcome(用例的执行结果,passed,failed)
|
||||
report = outcome.get_result()
|
||||
# 将测试用例的title作为测试报告"用例描述"列的值。
|
||||
# 注意参数传递时需要这样写:@pytest.mark.parametrize("case", cases, ids=["{}".format(case["title"]) for case in cases])
|
||||
report.description = re.findall('\\[(.*?)\\]', report.nodeid)[0]
|
||||
report.func = report.nodeid.split("[")[0]
|
||||
# allure-pytest的报错截图添加到报告
|
||||
if report.when == "call" or report.when == "setup":
|
||||
xfail = hasattr(report, "wasxfail")
|
||||
if (report.skipped and xfail) or (report.failed and not xfail):
|
||||
# 截图
|
||||
if RunConfig.driver:
|
||||
driver = RunConfig.driver
|
||||
logger.debug(f"{driver}: 开始进行截图操作......")
|
||||
# 创建不同浏览器驱动保存截图的目录
|
||||
driver_dir = os.path.join(IMG_DIR, str(driver).split(".")[2])
|
||||
os.makedirs(driver_dir, exist_ok=True)
|
||||
parameters = item.callspec.params["case"]
|
||||
# logger.debug(f"测试用例参数:{type(parameters)} {parameters}")
|
||||
file_name = FakerData.remove_special_characters(
|
||||
target=parameters.get("title", "")) + "_" + datetime.now().strftime(
|
||||
"%Y-%m-%d %H_%M_%S") + ".png"
|
||||
BasePage(driver=driver).screenshot(path=driver_dir, filename=file_name)
|
||||
img_path = os.path.join(driver_dir, file_name)
|
||||
if img_path:
|
||||
allure_step(step_title="点击查看失败截图......", content=report.nodeid, source=img_path)
|
||||
# @pytest.mark.hookwrapper
|
||||
# def pytest_runtest_makereport(item, call):
|
||||
# """设置列"用例描述"的值为用例的标题title"""
|
||||
# outcome = yield
|
||||
# # 获取调用结果的测试报告,返回一个report对象
|
||||
# # report对象的属性包括when(steup, call, teardown三个值)、nodeid(测试用例的名字)、outcome(用例的执行结果,passed,failed)
|
||||
# report = outcome.get_result()
|
||||
# # 将测试用例的title作为测试报告"用例描述"列的值。
|
||||
# # 注意参数传递时需要这样写:@pytest.mark.parametrize("case", cases, ids=["{}".format(case["title"]) for case in cases])
|
||||
# report.description = re.findall('\\[(.*?)\\]', report.nodeid)[0]
|
||||
# report.func = report.nodeid.split("[")[0]
|
||||
# # allure-pytest的报错截图添加到报告
|
||||
# if report.when == "call" or report.when == "setup":
|
||||
# xfail = hasattr(report, "wasxfail")
|
||||
# if (report.skipped and xfail) or (report.failed and not xfail):
|
||||
# # 截图
|
||||
# if RunConfig.driver:
|
||||
# driver = RunConfig.driver
|
||||
# logger.debug(f"{driver}: 开始进行截图操作......")
|
||||
# # 创建不同浏览器驱动保存截图的目录
|
||||
# driver_dir = os.path.join(IMG_DIR, str(driver).split(".")[2])
|
||||
# os.makedirs(driver_dir, exist_ok=True)
|
||||
# parameters = item.callspec.params["case"]
|
||||
# # logger.debug(f"测试用例参数:{type(parameters)} {parameters}")
|
||||
# file_name = FakerData.remove_special_characters(
|
||||
# target=parameters.get("title", "")) + "_" + datetime.now().strftime(
|
||||
# "%Y-%m-%d %H_%M_%S") + ".png"
|
||||
# BasePage(driver=driver).screenshot(path=driver_dir, filename=file_name)
|
||||
# img_path = os.path.join(driver_dir, file_name)
|
||||
# if img_path:
|
||||
# allure_step(step_title="点击查看失败截图......", content=report.nodeid, source=img_path)
|
||||
|
||||
|
||||
def pytest_terminal_summary(terminalreporter, config):
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
FROM ubuntu:22.04
|
||||
|
||||
|
||||
#设置时区
|
||||
RUN echo "Asia/Shanghai" > /etc/timezone
|
||||
|
||||
# 使用国内镜像源
|
||||
RUN sed -i "s@http://deb.debian.org@http://mirrors.aliyun.com@g" /etc/apt/sources.list && rm -Rf /var/lib/apt/lists/* && apt-get update
|
||||
|
||||
# 安装wget
|
||||
RUN apt-get update && apt-get install -y wget
|
||||
|
||||
# 安装python3
|
||||
|
||||
RUN apt-get update && apt-get install -y python3.10
|
||||
RUN python3 --version
|
||||
RUN python3 -V
|
||||
|
||||
RUN apt update && apt install -y python3-pip
|
||||
|
||||
# 安装jdk安装包
|
||||
RUN apt-get update && apt-get install -y openjdk-11-jdk
|
||||
|
||||
|
||||
|
||||
# 安装chrome浏览器的必要依赖
|
||||
RUN apt-get update && apt-get install -y \
|
||||
fonts-liberation \
|
||||
libcurl3-gnutls \
|
||||
libcurl3-nss \
|
||||
libcurl4 \
|
||||
libgbm1 \
|
||||
libu2f-udev \
|
||||
libvulkan1 \
|
||||
xdg-utils
|
||||
|
||||
# 安装chrome浏览器
|
||||
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
|
||||
RUN dpkg -i google-chrome-stable_current_amd64.deb
|
||||
RUN apt-get install -f -y
|
||||
RUN apt-get install -y google-chrome-stable
|
||||
RUN google-chrome-stable --version
|
||||
|
||||
# 安装git
|
||||
RUN apt-get install -y git
|
||||
|
||||
# 克隆代码
|
||||
RUN git clone https://gitlink.org.cn/floraachy/uiautotest2.git
|
||||
|
||||
|
||||
# 设置工作目录
|
||||
WORKDIR /uiautotest2
|
||||
|
||||
RUN cat test_case/conftest.py
|
||||
|
||||
# 修改测试账号密码
|
||||
RUN sed -i "s/\*\*\*\*autotest-test\*\*\*\*/实际的测试密码/g" config/settings.py
|
||||
|
||||
|
||||
# 安装pipenv
|
||||
RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pipenv
|
||||
|
||||
# 安装依赖
|
||||
RUN pipenv install --python 3.10 --skip-lock
|
||||
|
||||
|
||||
# 运行自动化测试
|
||||
CMD ["pipenv", "run", "python", "run.py"]
|
|
@ -72,6 +72,6 @@ def init_driver():
|
|||
yield driver
|
||||
logger.trace(
|
||||
"\n-----------------------------END-用例执行结束-----------------------------\n")
|
||||
driver.quit() # 关闭所有相关窗口和标签页,并且结束Webdriver进程,释放相关资源
|
||||
driver.quit() # 关闭所有相关窗口和标签页,并且结束Webdriver进程,释放相关资源
|
||||
# driver.close() # 关闭当前打开的窗口或标签页,如果当前窗口是最后一个窗口,整个WebDriver也会被关闭
|
||||
# ------------------------------------- END: 配置浏览器驱动 ---------------------------------------#
|
||||
|
|
Loading…
Reference in New Issue