How to write UI Automation script Airtest

Foreword

  Games are not the same as the app directly to the render tree nodes exposed, which resulted in the game UI Automation inconvenience on the element positioning, but rely airtest of picture identification, we can skip elements inspection, carried out in the form of contrasting picture automation, although the efficiency may be lower, but at least is automated.

Create a script file

  First you need to create a script file, airtest provides file in two formats - air .py suffix and suffix.;

  

  Although the two are separated, but before there is actually not much difference (source code .air file ultimately replaced by a more .py file execution), the specific choice of which depends on personal preference, personally I prefer pure python files, created for .py file suffix

  

  Saved settings file path and file name

  

  After setting click on the button below ok, airtest will automatically generate the following python file

   

Connected devices

  Device connection here is not to go into detail, you can directly connect the connection, if that connection fails, try the drop-down box on the right click to select connect or other use javacap

 Scriptable

  airtest fool because of its design, so that scripting has become very simple, basically as long as understand the python while / for loop, wait, you can deal with most scripting

  Tencent animation For example, for a set of automation requirements are:

    1. Open the app

    2. log in

    3. Jump to authorize QQ interface deauthorize

    4. Then log

    5. Jump to authorize QQ interface determine authorization

    6. login successful

    7. Search comic "dead brother."

    8. sign out

    9. Log on to stop repeat operations between Exit to determine whether there is a problem

  Of course, the current mainstream automation app is appium, but also pure UI recognition airtest automation app can do, so here's a more convenient app, rather than a game

  We begin with a needs analysis, "kept repeating to log on to operate between Exit" that we need to use a while loop, and in front of the process we trying to be difficult to write simply press a sequence

  Open the app (it is best to open a package name, package name here because too lazy to look through Tencent animation, will be opened directly in the form ui identified):

    We only need to click once to open the app can be, so

    

    Click the button to the left of the touch, the effect of the screenshot will appear after clicking directly on the mobile Tencent animation icon, the icon animation shots down, airtest automatically generates code on the touch .py file

     

  Due to open app need to wait some time for the app to initialize it, about five seconds, but we want to wait for the introduction of python time.sleep (5):

    

  Go to the login tab:

    

  Then while True wrote:

    

   We manually open the app, and then the subsequent step of each step airtest sectional view of good operation corresponding to:

     "Point me Login"

    

    After jumping to login, we need to click on QQ login

    

    Subsequent shots are so step by step can be, here temporarily slightly up

Script execution

  Execute scripts only need to click on the triangle button corresponding to the above

  

 LOG

  For people who do not understand the python, log view window print things may not understand, so the reference value is only being given time (which step is being given directly in the code set out red display)

  

Guess you like

Origin www.cnblogs.com/badluckforyou/p/12446094.html