当前位置:网站首页>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

边栏推荐
猜你喜欢

逆向理论知识1

The gospel of small and medium-sized enterprises is coming! Jnpf is becoming popular, helping business digital upgrading

leetcode 1074. Number of Submatrices That Sum to Target(和为target的子矩阵个数)

解密 Redis 助力双 11 背后电商秒杀系统

Interviewer: explain the core principle of ThreadLocal

面试官:解释一下ThreadLocal 核心原理

数学向量基本知识

1.赋值语句

适合短视频分享的Fireshare

Comprehensive summary of software quality management practice
随机推荐
CMake入门教程
在Unity中使用Tessellation
Tsinghua, air, Tencent | 3D isovariant molecular map pre training
拓扑排序 & 关键路径
hdu-7141 Ball (bitset)
Is CITIC futures a regular futures company and is it safe to open an account?
spark中saveAsTextFile如何最终生成一个文件
亿级流量下的分布式锁优化方案!太好用了~
凌晨两点,你们都在卷什么?
C——位运算
kali下安装go环境
PHP RSA generates public key and private key PSA2 encryption and decryption
范式及反范式
软件质量管理实践全面总结
中信期货是正规的期货公司吗,开户是否安全?
MySQL数据库提权学习
Comprehensive summary of software quality management practice
网络通信原理与IP地址的分配原理,网络七层由下往上分别为物理层、数据链路层、网络层、传输层、会话层、表示层和应用层
电脑一直按键如何处理
华泰证券开户安全吗是真的吗,是正规的吧
