使用WeAutomator提交UDT/终端云测平台入手教程
连接安卓设备
pytest组织用例
# -*- coding: UTF-8 -*-
import pytest
from uitrace .api import *
import json
logger = get_logger ()
class TestPhone (object ):
def setup_class (self ):
"""
每个测试类运行之前执行一次,初始化类
"""
#初始化设备驱动和环境,必填
init_driver (workspace = os .path .dirname (__file__ ))
#预先处理弹窗
start_event_handler ()
#返回home页
press (DeviceButton .HOME )
def teardown_class (self ):
"""
每个测试类运行之后执行一次
"""
press (DeviceButton .HOME )
stop_driver ()
def setup_method (self , method ):
"""
每个用例开始前初始化
"""
#启动app,用户可修改包名
pkg = "com.tencent.qqpimsecure"
uninstall_app (pkg )
#安卓app,app_path填写app本地路径
install_app (app_path )
#启动app,清理上一次遗留的数据
start_app (pkg , clear_data = True )
def teardown_method (self , method ):
"""
每个用例结束后执行
"""
pass
def test_case_1 (self ):
"""
测试case 1
"""
pass
#打印日志
logger .info (res )
def test_case_2 (self ):
"""
测试case 2
"""
pass
pytest_main ([os .path .join (os .path .dirname (__file__ ), "main.py" )])
新建测试文件,命名如test_phoneguard.py
将main.py(除了pytest_main([os.path.join(os.path.dirname(file ), "main.py")]))的内容复制到test_phoneguard.py
粘贴到test_phoneguard.py文件如下:
# -*- coding: UTF-8 -*-
import pytest
from uitrace .api import *
import json
logger = get_logger ()
class TestPhone (object ):
def setup_class (self ):
"""
每个测试类运行之前执行一次,初始化类
"""
#初始化设备驱动和环境,必填
init_driver (workspace = os .path .dirname (__file__ ))
#预先处理弹窗
start_event_handler ()
#返回home页
press (DeviceButton .HOME )
def teardown_class (self ):
"""
每个测试类运行之后执行一次
"""
press (DeviceButton .HOME )
stop_driver ()
def setup_method (self , method ):
"""
每个用例开始前初始化
"""
#启动app
pkg = "com.tencent.qqpimsecure"
uninstall_app (pkg )
#安卓app,app_path填写app本地路径
install_app (app_path )
#启动app,清理上一次遗留的数据
start_app (pkg , clear_data = True )
def teardown_method (self , method ):
"""
每个用例结束后执行
"""
pass
def test_case_1 (self ):
"""
测试case 1
"""
pass
#打印日志
logger .info (res )
def test_case_2 (self ):
"""
测试case 2
"""
pass
修改入口文件main.py
main.py的内容改为:
# -*- coding: UTF-8 -*-
from uitrace .api import *
pytest_main ([os .path .join (os .path .dirname (__file__ ), "test_phoneguard.py" )])
将调试通过的脚本后导出zip包,提交到udt的用例管理模块/终端云测提测页面,选择pytest框架;脚本依赖环境,内部镜像选择WeAutomator
去掉setup_method方法中 app的安装卸载功能:(UDT自动化测试自动执行安装和卸载)
#uninstall_app(pkg)
#安卓app,app_path填写app本地路径
#install_app(app_path)
参考的demo用例:
https://github.com/WeTestQuality/WeAutomator-docs-examples/tree/main/examples/test-phone-guard