Airtest Project

下载解压后,点击

执行文件

# -*- encoding=utf8 -*-
from airtest.core.api import *
import time
auto_setup(__file__)

# ===================== 配置参数(仅需确认这部分)=====================
APP_PACKAGE = "com.ugreen.home"  # 绿联APP包名(已确认)
TEST_TIMES = 3  # 采集3组数据取平均
LIVE_TIMEOUT = 20  # 直播画面加载超时时间(秒)
# ==================================================================

result_list = []  # 存储3组有效耗时数据

# 循环执行3次测试
for i in range(TEST_TIMES):
    print(f"\n=== 第{i+1}次首开拉流测试 ===")
    
    # 1. 冷启动APP(确保完全关闭后重启)
    stop_app(APP_PACKAGE)
    sleep(3)  # 等待APP彻底关闭
    
    # 2. 启动APP并等待首页加载
    start_time_app = time.time()
    start_ms_app = int((start_time_app - int(start_time_app)) * 1000)
    print(f"APP启动时间:{time.strftime('%Y-%m-%d %H:%M:%S')}.{start_ms_app:03d}")
    
    start_app(APP_PACKAGE)
    # 等待APP首页加载完成(需先录制首页特征图,比如“设备列表”)

    if not wait(Template(r"tpl1774524434047.png", record_pos=(-0.398, -0.774), resolution=(900, 1600)) ,timeout=10):
        print(f"第{i+1}次测试:APP首页加载超时,跳过本次")
        continue
    #3.点击触发入口按键
    touch(Template(r"tpl1774525262799.png", record_pos=(0.369, -0.537), resolution=(900, 1600)))
    # 4. 点击直播预览入口(需录制直播按钮截图)  
  # 录制的“直播预览”按钮
    # 记录拉流计时起点(点击直播按钮后开始计时)
    start_time_live = time.time()
    start_ms_live = int((start_time_live - int(start_time_live)) * 1000)
    print(f"开始拉流时间:{time.strftime('%Y-%m-%d %H:%M:%S')}.{start_ms_live:03d}")
    
    # 5. 等待直播画面加载成功(需录制直播画面特征图,比如画面中的摄像头场景)
    if wait(Template(r"tpl1774524908417.png", record_pos=(-0.406, -0.762), resolution=(900, 1600)), timeout=LIVE_TIMEOUT):
        # 计算拉流耗时(毫秒级,保留1位小数)
        end_time_live = time.time()
        end_ms_live = int((end_time_live - int(end_time_live)) * 1000)
        cost_time = round((end_time_live - start_time_live) * 1000, 1)
        result_list.append(cost_time)
        
        # 输出单次测试结果
        print(f"拉流成功时间:{time.strftime('%Y-%m-%d %H:%M:%S')}.{end_ms_live:03d}")
        print(f"第{i+1}次首开拉流时长:{cost_time} ms")
    else:
        print(f"第{i+1}次测试:直播画面加载超时({LIVE_TIMEOUT}秒),跳过本次")

# ===================== 计算并输出最终结果 =====================
print("\n" + "="*50)
if result_list:
    avg_time = round(sum(result_list) / len(result_list), 1)
    print(f"有效测试次数:{len(result_list)}/{TEST_TIMES}")
    print(f"3组有效数据:{result_list} ms")
    print(f"平均首开拉流时长:{avg_time} ms")
else:
    print(f"测试失败:{TEST_TIMES}次测试均超时,请检查:")
    print("1. 设备是否在线/局域网是否连通")
    print("2. 截图模板是否与当前界面匹配")
    print("3. APP是否正常显示直播画面")

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐