unittest 执行airtest 脚本

Posted yanhuidj

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了unittest 执行airtest 脚本相关的知识,希望对你有一定的参考价值。

参考:https://blog.csdn.net/gzh00001/article/details/93331399

 

#!/user/bin/python3
#coding=utf-8
#2019/12/14 --17:21
#author :hui
from airtest.core.api import *
import unittest
from BeautifulReport import BeautifulReport
import os
auto_setup(__file__)
class WTestcase(unittest.TestCase):
@classmethod
def setUpClass(cls):

init_device("android", "OALEP2000004751")

def setUp(self):
print(‘ui测试开始‘)

# start_app("team.opay.ride.driver.dev")

def test_1(self):
"""ui冒烟测试"""
# 热启动吊起app
touch(Template(r"tpl1576313993828.png", record_pos=(-0.336, 0.024), resolution=(720, 1440)))
sleep(6)
# 错误登录
text("12341234")
sleep(5)
touch(Template(r"tpl1576314053251.png", record_pos=(0.01, -0.051), resolution=(720, 1440)))
text("123456")
sleep(2)
touch(Template(r"tpl1576314135959.png", record_pos=(0.035, 0.181), resolution=(720, 1440)))
sleep(6)
# 切换明暗文
touch(Template(r"tpl1576314184636.png", record_pos=(0.332, -0.06), resolution=(720, 1440)))
sleep(2)
touch(Template(r"tpl1576314198162.png", record_pos=(0.332, -0.054), resolution=(720, 1440)))
sleep(2)

from poco.drivers.android.uiautomation import AndroidUiautomationPoco
poco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False)

poco("team.opay.ride.driver.dev:id/edtPhone").click()

for i in range(8):
keyevent("67")
sleep(1)
text("1234567898")
sleep(3)
touch(Template(r"tpl1576314576211.png", record_pos=(0.051, 0.186), resolution=(720, 1440)))
sleep(14)

touch(Template(r"tpl1576314618333.png", record_pos=(-0.411, -0.847), resolution=(720, 1440)))
sleep(2)
touch(Template(r"tpl1576314632672.png", record_pos=(-0.143, -0.322), resolution=(720, 1440)))
sleep(6)
touch(Template(r"tpl1576314704291.png", record_pos=(0.242, 0.156), resolution=(720, 1440)))
sleep(5)
touch(Template(r"tpl1576314720482.png", record_pos=(-0.242, 0.918), resolution=(720, 1440)))
sleep(4)

poco("android.widget.LinearLayout").offspring("team.opay.ride.driver.dev:id/container").offspring(
"team.opay.ride.driver.dev:id/recyclerView").offspring("team.opay.ride.driver.dev:id/RecyclerView").child(
"android.view.ViewGroup")[0].swipe([-0.0447, -0.3631])
poco("android.widget.LinearLayout").offspring("team.opay.ride.driver.dev:id/container").offspring(
"team.opay.ride.driver.dev:id/recyclerView").offspring("team.opay.ride.driver.dev:id/RecyclerView").child(
"android.view.ViewGroup")[3].swipe([-0.0782, -0.4777])
sleep(6)
touch(Template(r"tpl1576314762405.png", record_pos=(-0.239, 0.918), resolution=(720, 1440)))

# @classmethod
# def tearDownClass(cls):
# print(‘ui测试结束‘)
def tearDown(self):
print(‘ui测试结束‘)


if __name__ == ‘__main__‘:
unittest.main()


通过的效果如下:

技术图片

以上是关于unittest 执行airtest 脚本的主要内容,如果未能解决你的问题,请参考以下文章

airtest 多airtest脚本批量执行

Airtest 执行脚本(批量)

Airtest引用其他的 .air 脚本

PyCharm 以 Python 形式执行包含 Unittest 模块的脚本

Airtest自动化测试篇——python编写和执行用例(上)

答疑第四期 | 使用Airtest最常见的8大问题