Airtest: Windows desktop application automation testing (1)

1. Why do I choose Airtest?

1. Because it integrates pywinauto

pywinauto: Windows desktop application automation testing (1)_Lion King's blog-CSDN blog 1. Why do I use pywinauto module 1. Because of the problems I encountered with the previous solution, I had to change the solution Appium: Windows system desktop application automation Test (2)_Lion King's blog-CSDN blog 1. The problem of not being able to obtain the operation handle 1. The following figure is a different application connected through a python script 2. Application 1: There is a sessionId, indicating that the session is normal, and the application can be operated through the handle 3 , Application 2: report 500 error https://blog.csdn.net/weixin_43431593/article/details/1242998512, because Dachang is also based on pywi https://blog.csdn.net/weixin_43431593/article/details/124378355

2. I believe he should be something more powerful than pywinauto

3. I want to use it to automate Windows desktop applications

2. Official documents

1. Chinese

Welcome - Airtest Project Docs Airtest Project Docs https://airtest.doc.io.netease.com/ 2、github

Airtest — airtest documentation https://airtest.readthedocs.io/zh_CN/latest/README_MORE.html

3. Environment construction

1. Use the officially recommended Airtest IDE

Installation and Startup - Airtest Project Docs Airtest Project Docs https://airtest.doc.io.netease.com/IDEdocs/3.1getting_started/AirtestIDE_install/

4. Easy operation

1. Simulate double-clicking the desktop application

(1) Use the IDE to connect to the desktop (2 ways)

(2) Click touch to select the icon, and double-click

(3) Precautions

If you are not connected to the desktop, you may not be able to select by clicking the touch, or the touch will be grayed out directly, and an error will be reported when running

(4) Verification result

Double-clicking the desktop application icon did not successfully open the application

2. Connect application window

(1) Embedded connection (2 ways to connect to the application window)

It is not recommended to connect to the desktop application in an embedded way, because the interface of the desktop application is too large and not as friendly as the mobile application. Of course, it can be separated as a separate window, but there will be some incompatibility or unusable situations, such as window changes will be automatically separated from the IDE. However, this function has a very tasteless (at least 1.2.13 win application) script recording function , which can be used in the code writing stage and needs to be recorded in an embedded manner .

 (2) Non-embedded connection

After setting, follow the operation steps of the embedded connection window to realize the connection

 

 (3) Use scripts to connect to applications

① Use window handle

This way is not recommended , because the handle will change.

auto_setup(__file__,devices=["Windows:///133194"])

② Use regular expressions to match window TITLE

It is recommended to use this method, and the window TITLE generally remains unchanged.

# 例如匹配“吹梦到西洲”后面跟着换行符以外的任意字符的窗口title
auto_setup(__file__,devices=["Windows:///?title_re=吹梦到西洲.*"])

③ Connect to WINDOWS desktop

If the specific parameters of devices are not specified, the desktop is connected.

auto_setup(__file__,devices=["Windows:///"])

If the devices parameter is not specified, an error message will be given if there is no connected object, or the connection to the object that the IDE has already connected is successful (successful when there is such a target in the object, and an error will be reported if there is no object)

auto_setup(__file__)

 

 

(4) Precautions

① When running the code, it is best not to connect to the window through the IDE, but to connect through the code

②The connection object to run the code, if you want to connect through the IDE, the code should be consistent with the actual connection object

 3. When writing code, the conversion of pictures and codes

 4. When running the program, the requirements are visible

(1) When the object is not visible, an error will be reported

(2) Icons in the IDE will also be clicked

Solution : Either add a delay, and shrink the IDE to the minimum after running; or command to run the code; or specify the connection object in the script to run (note that if it is a desktop, it will be global)

5. 32-bit python is required to connect to 32-bit applications

As shown in the figure, when the application is required to connect, the number of python digits should be consistent with the application. In this case, the handle method can be used (although it is not recommended ).

 

 6. Record script

This function is not easy to use when recording win application scripts. For example, double-clicking the icon cannot record, input characters cannot be recorded, etc. Currently (1.2.13 win application recording) is very useless.

 

Guess you like

Origin blog.csdn.net/weixin_43431593/article/details/124380419