Airtest的Api介绍和应用(全)
"""
@author: 九九的金金子
@file: test_airtest.py
@time: 2021/3/4 17:19
"""
from airtest.core.api import *
from poco.drivers.android.uiautomation import AndroidUiautomationPoco
import pytest
class TestAirtest:
"""
airtest.core.api介绍
"""
def setup(self):
auto_setup(__file__)
poco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False)
def test_init_device(self):
init_device(platform="Android", uuid="12344321", cap_method="JAVACAP")
def test_connect_device(self):
connect_device("Android:///12344321?cap_method=javacap&touch_method=adb")
def test_device(self):
dev = device()
dev.touch((100, 100))
def test_set_current(self):
set_current(0)
def test_shell(self):
print(shell("ls"))
def test_start_app(self):
start_app("com.xxx.xxxx")
def test_stop_app(self):
stop_app("com.xxx.xxxx")
def test_clear_app(self):
clear_app("com.xxx.xxxx")
def test_install_app(self):
install(r"E:\\sit_debug_2022847.apk")
def test_uninstall_app(self):
uninstall("com.xxxt")
def test_snapshot(self):
snapshot(filename="test.png", msg="test")
def test_wake(self):
wake()
def test_home(self):
home()
def test_touch(self):
touch((100, 100))
touch((100, 100), times=2)
touch(Template(r"E:\测试\airtest\untitled.air\tpl1614843297836.png", record_pos=(-0.003, 0.309),
resolution=(1080, 1920)))
def test_double_click(self):
double_click((100, 100))
double_click(Template(r"E:\测试\airtest\untitled.air\tpl1614843297836.png"))
def test_swipe(self):
swipe((100, 100), (200, 200))
swipe(Template(r"E:\测试\airtest\untitled.air\tpl1614844771023.png", record_pos=(0.473, -0.035),
resolution=(1080.0, 1920.0)),
vector=[-0.933, -0.2038])
def test_keyevent(self):
keyevent("HOME")
keyevent("BACK")
def test_test(self):
text("test")
text("test", search=True)
def test_sleep(self):
sleep(2)
def test_wait(self):
def notfound():
print("No target found")
wait(Template(r"E:\测试\airtest\untitled.air\tpl1614843297836.png"), intervalfunc=notfound)
def test_wait(self):
pos = exists(Template(r"E:\测试\airtest\untitled.air\tpl1614843297836.png"))
if pos:
touch(pos)
def test_find_all(self):
result = find_all(Template(r"E:\测试\airtest\untitled.air\tpl1614843297836.png"))
print(result)
def test_assert_exists(self):
assert_exists(Template(r"E:\测试\airtest\untitled.air\tpl1614843297836.png"), "assert exists")
def test_assert_not_exists(self):
assert_not_exists(Template(r"E:\测试\airtest\untitled.air\tpl1614843297836.png"), "assert not exists")
def test_assert_equal(self):
assert_equal(1, 1, msg="assert 1==1")
def test_assert_not_equal(self):
assert_not_equal(1, 2, msg="assert 1!=2")