def screenshot(self, file):
"""封装截图方法"""
self.driver.save_screenshot(file)
### allure 获取截图
allure.attach(picture, attachment_type=allure.attachment_type.PNG)
import logging
# 添加日志
logging.info("start find : \nargs: " + str(args) + "\nkwargs: " + str(kwargs))
结合 pytest.ini 文件使用
[pytest]
addopts = -sv --log-cli-level=INFO
使用第三方工具 scrcpy,主要考虑的是,使用 appium 录屏,无法获取部分手机的授权
https://github.com/Genymobile/scrcpy
https://blog.csdn.net/was172/article/details/99705855
将录屏的功能封装到 conftest.py 中
import os
import signal
import subprocess
import pytest
@pytest.fixture(scope="function", autouse=True)
def scrcpy_record():
cmd = "scrcpy --record file.mp4"
p = subprocess.Popen(
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
print(p)
yield
os.kill(p.pid, signal.CTRL_C_EVENT)