关于测试:0315-截图日志与录屏

6次阅读

共计 704 个字符,预计需要花费 2 分钟才能阅读完成。

截图

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 录屏,无奈获取局部手机的受权

GitHub 地址

https://github.com/Genymobile…

应用教程

https://blog.csdn.net/was172/…

将录屏的性能封装到 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)
正文完
 0