Automation--APP UI Automation--Airtest Learning

I saw other colleagues using airtest, so I learned

 

 

AirtestIDE provides a relatively complete official document, the explanation and operation are quite detailed

http://airtest.netease.com/docs/docs_AirtestIDE-zh_CN/index.html

 

To use airtest to perform ui automation, first of all:

1. Android AirtestIDE

Official installation   http://airtest.netease.com/

or

Network disk installation:  

Link: https://pan.baidu.com/s/1IaTR_ZPxy81mCPwGsyRKhA
extraction code: f7pk

2.IDE connected to the phone

The mobile phone needs to open the developer mode (settings-system-developer options-USB debugging)

If you can't connect, the official document at the top of the article has a corresponding problem solution

3. Simple script

1) Use image positioning

1  # -*-encoding = utf8-*- 
2  __author__ = " whyCai " 
3  
4  from airtest.core.api import *
 5  
6 auto_setup ( __file__ )
 7  
8  
9 touch (Template (r " tpl1586696803061.png " , record_pos = ( 0.122, 0.872), Resolution = (1080, 2280)))   # click calculator 
10  
11 Touch (Template (r " tpl1586696831912.png " , record_pos = (- 0.369, 0.643), Resolution = (1080, 2280)))   # Click 1 
12  
13 touch(Template(r"tpl1586696857748.png", record_pos=(0.371, 0.373), resolution=(1080, 2280)))  #点击 +
14 
15 
16 touch(Template(r"tpl1586696879899.png", record_pos=(0.125, 0.641), resolution=(1080, 2280)))  #点击 3
17 
18 touch(Template(r"tpl1586696905934.png", record_pos=(0.375, 0.781), resolution=(1080, 2280)))  #点击 =

As shown:

 

 

run:

 

 

2) Use location positioning

 1 # -*- encoding=utf8 -*-
 2 __author__ = "whyCai"
 3 
 4 from airtest.core.api import *
 5 from airtest.cli.parser import cli_setup
 6 
 7 if not cli_setup():
 8     auto_setup(__file__, logdir=True, devices=[
 9             "Android://127.0.0.1:5037/VBJDU18712006906",
10     ])
11 
12     
13     
14 
15 # script content
16  Print ( " Start ... " )
 . 17  
18 is  from poco.drivers.android.uiautomation Import AndroidUiautomationPoco
 . 19 POCO = AndroidUiautomationPoco (use_airtest_input = True, screenshot_each_action = False)
 20 is  
21 is  
22 is  # click calculator 
23 is POCO (text = ' Calculator ' ) .click ()
 24  
25  # click. 1 
26 is POCO (text = ' . 1 ' ) .click ()
 27  
28  # click + 
29 POCO (name = 'com.android.calculator2:id/op_add').click()
30 
31 #点击 3
32 poco(text='3').click()
33 
34 #点击 =
35 poco(name='com.android.calculator2:id/eq').click()
36 
37 
38 # generate html report
39 # from airtest.report.report import simple_report
40 # simple_report(__file__, logpath=True)

carried out:

Guess you like

Origin www.cnblogs.com/whycai/p/12687871.html