当前位置:网站首页>Click position and click offset of airtest script
Click position and click offset of airtest script
2022-07-23 10:05:00 【The elegance of testing】
1. Preface
We often hear students mention : This picture script has no click effect ? Why is the script a little biased ? I want to point to other positions of the picture, ok ? Questions like that .
Today, let's have a detailed chat with our classmates ,Airtest Click position and click offset of this content , After watching the , Encounter problems similar to the above , We can all solve it easily .
2. Airtest Click location
Take the simplest image click script as an example :

Execute this image script , Where is the meeting place ? be familiar with Airtest My classmates will know , Is the center of the picture . How can we know the actual click effect of this script ? Teach you a few tips .
One is to open it in the settings of the mobile phone “ Display touch operation ”, So we are IDE When running the image script , You can clearly see the click position on the mobile screen :


So when students meet , The script executed , But when there is no click effect , You might as well open the phone settings , Enable “ Display touch operation ”, Let's see whether the script is executing without response ? Or does the script really not execute this click action .
Another way is , stay IDE Of log In the view window , Check the recognition results given by the image algorithm ( Find a keyword match result Of debug Information ):
[15:17:32][DEBUG]<airtest.core.api> match result: {'result': (439, 348), 'rectangle': ((370.76, 265.76), (370.76, 431.76), (508.76, 431.76), (508.76, 265.76)), 'confidence': 0.975566565990448, 'time': 0.3353738784790039}
You can see , The recognition result of image algorithm is (439, 348), We can use IDE Gadget for viewing mobile device coordinates , To check whether this result is in line with our expectations :

The advantage of this method is , Sometimes we find out , The actual click location of the script , Deviated from our expectations , We can get to log In the view window , Find the result recognized by the algorithm , Use coordinate tools to check whether the algorithm results meet our expectations on the device screen , Is it really wrong .
There is also a very intuitive way , It's generation Airtest Report to view , You can intuitively see the execution of the click step , The specific click position on the screen :

3. Airtest Click offset
By default ,Airtest Click on the center of the image , That is to say target_pos=5 The location of . If you want to do click offset , For example, I will click on the top left corner of the image , Then we must first understand this target_pos What parameter is it :

As shown in the figure ,target_pos Used to set the operation position on the matching result image , The value is 1-9 The integer of , The default is 5( That is, the center of the image ). If we want to click on the position in the upper left corner of the image , Then we must specify it manually target_pos=1:
touch(Template(r"tpl1658387780768.png", target_pos=1, record_pos=(0.108, -0.517), resolution=(720, 1440)))
Image click offset , Commonly used in the following scenarios :
One is , When our page , There are many identical icons , We want to specify the icon to click on a certain position , It's possible to use target_pos Parameters of , for instance , In the following pages , Yes 3 The same play button :

If we want to click the first play button , But only screenshots , There is no guarantee that you can click the first play button .
But if we expand the scope of the screenshot , And by specifying target_pos , It can ensure that we can click the first target button :

Another common scenario is , When there are too few feature points in our click image , You can appropriately increase the scope of screenshots , And then by setting target_pos , Come to our target location .

Suppose we want to click on button, If we just take a screenshot of the target image , You can expect , The background color of the target image is consistent , Basically no change , There are only simple lines inside , Such an image script , It is easy to be judged by the algorithm that there are too few feature points , Or recognize the wrong target .
When we expand the scope of the screenshot , Add more feature points to the screenshot , And set it appropriately target_pos , You can get an image script with better compatibility :

4. expand :Airtest Other click parameters
# Click absolute coordinates
touch([100,100])
# Click on the bottom right corner of the picture
touch(Template(r"tpl1606730579419.png", target_pos=9))
# Click on 2 Time 【 Double click effect may not be achieved 】
touch([100, 100], times=2)
# stay Android and Windows Next , You can set the click duration
touch([100, 100], duration=2)
# Right click on the (Windows)
touch([100, 100], right_click=True)
# double-click
double_click([100, 100])
double_click(Template(r"tpl1606730579419.png"))
5. Summary
Today we talked about Airtest Click position and click offset of image script , Actually ,Poco Control scripts have a similar situation , We'll continue our discussion next time .
Last : It can be in the official account : Sad spicy bar ! Get one by yourself 216 Page software testing engineer interview guide document information 【 Free of charge 】. And the corresponding video learning tutorial is free to share !, It includes basic knowledge 、Linux necessary 、Shell、 The principles of the Internet 、Mysql database 、 Special topic of bag capturing tools 、 Interface testing tool 、 Test advanced -Python Programming 、Web automated testing 、APP automated testing 、 Interface automation testing 、 Testing advanced continuous integration 、 Test architecture development test framework 、 Performance testing 、 Safety test, etc. .
Now I invite you to join our software testing learning exchange group :【746506216】, remarks “ The group of ”, We can discuss communication software testing together , Learn software testing together 、 Interview and other aspects of software testing , There will also be free live classes , Gain more testing skills , Let's advance together Python automated testing / Test Development , On the road to high pay .
Friends who like software testing , If my blog helps you 、 If you like my blog content , please “ give the thumbs-up ” “ Comment on ” “ Collection ” One Key triple connection !
Software Test Engineer self-study tutorial :
Interface performance test — Software testers will 618 Analysis of actual combat scenes
Jmeter Explain the case in practice — Software testers will

边栏推荐
猜你喜欢

网络通信原理与IP地址的分配原理,网络七层由下往上分别为物理层、数据链路层、网络层、传输层、会话层、表示层和应用层

想放弃软件测试了,4年经验去面试10分钟结束,测试现在这么难了?
![[learning notes] node -- from 0 foundation to actual enterprise official website](/img/5e/c20e0aa0ad3f71fa5064ec9aca4ce7.jpg)
[learning notes] node -- from 0 foundation to actual enterprise official website

实现多层级条件查询(类似京东多层级添加查询)

笔记——记录一个dynamic-datasource please check the setting of primary 问题解决

转行软件测试薪资10K | 手中有粮心中有底,在任何时候都是真理

数学向量基本知识

CANopen通信----PDO与SDO

nchar字符引起的ora-12899错误

567. 字符串的排列
随机推荐
数学向量基本知识
How to deal with the computer pressing keys all the time
nchar字符引起的ora-12899错误
J.Serval and Essay(tarjan求拓扑序)
ES6 related interview question 3
MySQL数据库UDF提权学习
检测Windows安全缺陷工具wesng的学习与使用
Baidu map eagle eye track service
9.2章MATLAB的程序控制
three文档使用
广发期货是什么级别?开户安全可靠吗?
CAD如何绘制带有弧形的箭头
组合数。。。。
专题训练-链表
PHP RSA 生成公钥私钥 PSA2 加密解密
args参数解析
Hide the PHP version information in the response header of the website server
[learning notes] node -- from 0 foundation to actual enterprise official website
Use modern development methods and thinking to get rid of the "stumbling block" of legacy systems
Reverse pairs in an array
