This article comes from the official official account of the project: “AirtestProject” copyright statement: reprint is allowed, but reprint must retain the original link; Do not use for commercial or illegal purposes

preface

We’ve compiled a list of the 26 most likely questions to be asked by students in our q&A group, and we’ll be compiling more frequently asked questions to help you avoid pitfalls

1. How to enter text?

Use airtest’s text() interface:

Touch (input box) text(" text ")Copy the code

Use poco’s set_text() interface:

Poco (" input ").click() poco(" input ").set_text(" text ")Copy the code

In addition, airtest and POCO scripts can be mixed, so if the input box does not support text(), use poCO’s set_text() interface instead. Similarly, if poCO is not supported, use Airtest’s text() interface instead.

2.minicap serve setup time out

Screen initialization fails, usually on MIUI devices of higher versions or emulators. First check whether the current IDE is the latest version, if not, please update the IDE to the latest version; Then try using the use Javacap drop-down box before connecting the device.

3.minitouch serve setup timeout

Click to initialize failed, common in Android 10 or above devices, the solution, check whether the current environment airTest version is the latest (IDE update to the latest version, use the local Python environment to update the local environment airtest to the latest version).

4.Javacap server setup timeout

The device does not apply to Javacap. Do not select use javacap before connecting the IDE to the device. Do not include the string of script connecting to the device. Cap_method = JAVACAP. Finally, make sure you are using the latest version of AirTest.

5. How to display coordinates

Top menu bar, options – Settings, only select real-time coordinate display, then display absolute coordinates; Select real-time coordinates and relative coordinates at the same time to display the relative coordinates. (Airtest uses absolute coordinates, POCO uses relative coordinates)

# click on the coordinates of the location of the [100100] touch ([100100]) # click screen center [0.5, 0.5] poco. Click ([0.5, 0.5])Copy the code

6. Image recognition is not accurate

Please refer to the tutorial tweet of the official official account “AirtestProject” :

  • Understanding image recognition principles and algorithms: 3 minutes to choose the right image recognition algorithm
  • Improve the compatibility of image recognition ① : write 10000 Airtest screenshots script summed up the screenshot experience, quickly collect!
  • Improve the compatibility of image recognition ② : screenshot recognition success rate is too low, how to remedy it

7. The device cannot be connected

Refer to the official documentation of the AirtestIDE using the AirtestIDE – Device Connection -Android Connection FAQ, and then view section 1 and section 2 according to your phone model.

The names of the Settings of different brands are for reference only. Not all brands and models have the same names and locations. Therefore, the Settings mentioned in the tutorial are for students’ reference only.

8. The simulator cannot be connected

  • 1) Check whether Yosemite is installed or not
  • 2) Black screen or blurred picture after connection, drop down and check before connectuse javacapConnect again
  • For more details and answers, please refer to the article on the official account: After testing 5 of the most common simulators, the one that works best with Airtest automation is…

9. Poco location error: Cannot be found

  • 1) Sometimes the POCO location script automatically generated by the IDE is very long and the hierarchy is very deep. When playing back, the control may not be found; At this time, it is not recommended that students directly use the automatically generated positioning script, according to the DETAILS of the UI tree, in addition to write a more concise positioning script, it is recommended to use regular match to locate the script will be better.

  • 2) If the location script is written by students themselves, please check the corresponding attribute or hierarchical relationship to see if the script error causes that the element cannot be found.

  • 3) If the debugging script is selected separately, the control can be found, but the actual running of the script is easy to find the control, it is recommended to add enough sleep() before the positioning script, to ensure that the screen jump is stable, and then find the control.

No module named ‘airtest’, ‘poco’, ‘airtest-Selenium’, etc

In the current Python environment, install the missing corresponding module:

PIP install airtest PIP install pocoui # PIP uninstall pocoCopy the code

Poco can not get the control, poCO support

At present, only native applications can directly use POCO (without access to pocoSDK), non-native applications, such as various game applications, H5 small programs, mixed development applications, etc., can not directly use POCO to take the control, the vast majority of games support access to the corresponding engine pocoSDK, can obtain control information.

12. The helper window does not spawn UI trees

  • 1) Except native apps, all engines need to access THE SDK to view the UI tree;
  • 2) Check whether the phone has been automatically installed on the POCO initialization related to the two APK (pocoservice-debug.apk,pocoservice-debug-androidTest.apk), if not installed, manually install it;
  • 3) Install the input methodYosemiteAnd set as the default input method
  • Some vendor phones require additional Settings. For details, refer to the official document “AirtestIDE Usage Documentation – Device Connection -Android Connection FAQ”.

13. Poco refresh time

The default refresh time of the UI tree is 2 seconds, which can be set in options — Settings — POco. Click OK to save the Settings.

14.invalid syntax

Typical Python syntax errors, such as unwrapped script lines, indentation errors, missing side “or (etc.

15. Multiple IDE ICONS appear on the MAC

Try unchecking the autocomplete setting in the Settings option on the top menu bar of the IDE.

16. What does record_pos, resolution mean

A parameter in the Template class, record_pos, calculates the midpoint offset of the coordinates as a percentage of the resolution. Resolution keeps track of the phone’s resolution at the time of the screenshot.

Template(r"tpl1611559272215.png", record_pos=(-0.106, -0.035), resolution=(1080, 1920))
Copy the code

If students are using their own pictures, do not fill the record_pos parameter will not have a great impact on the identification effect, such as want to calculate, can refer to the following source code:

17. How to click search on the soft keyboard? Type and press Enter?

If you need to click the Search button on the soft keyboard, then:

The text (" text ", enter = False, search = True)Copy the code

Similarly, if enter is required, then text(” text “, Enter =True), if no enter is required, then text(” text “,enter=False).

18. Batch run? Multitasking? Multiple machine running?

The official documentation of the AirtestIDE provides examples of multi-machine collaboration and using BAT scripts to perform multi-machine operation, which are under the section of using the AirtestIDE documentation — Running scripts. In addition, you can refer to the online tutorial of using multithreaded methods to perform batch operation:

  • Practical case of multi-machine collaboration: “Multi-machine collaboration” — Case analysis of Wechat Mutual Adding friends
  • An example of using BAT scripts to implement batch execution: Using BAT files to “batch run” Airtest scripts

19. Determine that the element/screenshot exists

  • Airtest, determine whether the target in the screenshot exists in the current screen:The exists (screenshot)
  • Poco, to determine whether an element exists:poco("xxx").exists()

20. Wait for elements/screenshots to appear

  • Airtest, waiting for a screenshot target to appear on the current screen:Wait (screenshot)
  • Poco, waiting for a control element to appear:poco("xxx").wait_for_appearance()

21. Assert

  • To declare whether a screenshot target exists on the current screen:Assert_exists (screenshot)
  • To assert whether a POCO element exists:Assert_equal (POco (XXX).exists(),"True"," XXX control exists ")

22. How to continue execution after an error is reported

Use try-except to catch the error and let the program continue.

23. Can’t enter password? The password screen is black?

The login page or password interface of the application will not allow screenshots. You can check the Settings of your test device to see if there is a secure keyboard, prevent malicious screenshots, and so on. Just turn it off.

24. How to call another script?

Airtest provides a using interface that can be used to call other.air scripts. For details and examples, see the official official account’s tutorial tweets: a method to add a “subscript” to the main script to run.

If the program cannot find the script after using the using call, it is recommended to check whether the script path in the using interface is correct. You can also try adding the script path to sys.path at the beginning of the script:

Append (r"D:\test\user\project\test1.air")Copy the code

25. How to write the POCO location script?

Poco supports positioning scripts with basic, relative, and spatial selectors, as well as regular expressions to match controls. Detailed tutorials and examples can be viewed in the official public account tutorial tweets:

  • Can’t get poCO elements located? So let’s look at these three selectors; What a delicious series!
  • Use regular expressions to match POCO controls, learned to kill a variety of location selectors

26. Local screenshots and local pictures

Partial screenshot:

Local = aircv.crop_image(screen,(0,160,1067,551))Copy the code

Local map finding:

Local_screen = aircv.crop_image(screen,(0,949,1067,1500)) # set our target screen to a Template object Pos = tempalte.match_in(local_screen)Copy the code

Detailed tutorials and examples can view the official public account of the tutorial tweet: using Airtest most often encountered several requirements, have helped you achieve a good.


Airtest website: airtest.netease.com/ Airtest tutorial website: airtest.doc.io.netease.com/ build enterprise private cloud service: airlab.163.com/b2b

Official Q group: 654700783

Ah, so serious all see here, help in the left side of the article click like and collection, give me a support, ash often thanks ~