当前位置:网站首页>There are several APIs of airtest and poco that are easy to use wrong in "super". See if you have encountered them
There are several APIs of airtest and poco that are easy to use wrong in "super". See if you have encountered them
2022-07-03 16:26:00 【Programming simplicity】
Preface
Recently in our Q & a group , This kind of situation is often encountered :
- mistake Airtest Of API Force to use in Poco Control
- mistake Poco Of API Impose on Airtest The screenshot script above
- No matter API What's the actual usage of , Just write your own script , Finally, there are various errors when running the script
So today we've sorted out these API Common cases of misuse , Hope that students can write scripts less step on the pit .
Easy to use API Summary of the situation
1. A mixture of Airtest and Poco Framework of the exists()
Using a method with super high error probability !!! Let's start with the last mistake demonstration :

A very typical one Airtest Of API Force on Poco Control . This student's expectation , I want to judge , If this control exists , Just do something .
But his problem is exists Method is not used correctly .
The first thing is clear ,Airtest and Poco This is the frame API Check if there is something on the current page , But the difference is ,Airtest Of exists Used to check whether there is a screenshot target in the current screen , Usage is as follows :

exists(Template(r"tpl1622704594490.png", record_pos=(-0.185, -0.211), resolution=(810, 1440)))
Copy code Poco Framework of the exists Used to detect whether a control exists in the current page , Usage is as follows :
poco(text="poco").exists()
Copy code So the student's correct writing should be :
if poco(text="poco").exists():
pass
Copy code Second, we need to pay attention to , These two API The return value of is a little different :
# Control exists and returns True, There is no return False
poco(text="poco").exists()
# The picture target has return coordinates , There is no return False
exists(Template(r"tpl1622704594490.png", record_pos=(-0.185, -0.211), resolution=(810, 1440)))
Copy code Airtest Of exists With conditional sentences if When you use it , Also need to pay attention to the following situation :

You can see , Does not exist on the current page “ Set up ” This screenshot target , But the script did run to if Inside , This shows that if Yes. . Why is that ?
Let's take a close look at log, After the script runs to exists Method time , among 1 An image recognition algorithm has been found 1 The first credibility is 0.7039xx Result , Greater than the default image threshold 0.7, So this one exists The result of is to return the coordinates of the result , Lead to if Statement passing .
It's also very common , Students often wonder why I wrote if The statement doesn't work ? It's not , The solution , It's very simple , Raise the threshold of the image , Filter out the results that may be misjudged :
if exists(Template(r"tpl1622705519946.png", threshold=0.8, record_pos=(0.143, -0.342), resolution=(810, 1440))):
print(" eureka ")
Copy code Raise the threshold to 0.8, Filter out the larger than 0.7 The miscalculation result of , The script will meet our expectations :

2. Write your own script
The same as usual , Let's look at the error demonstration first :

This student's expectation should be , Click this control if it exists , But as we said above ,Poco Framework of the exists Method , The return is True and False , Boolean values have no click Methodical , Only UI Control click Method .
This situation is typical of not following the syntax to write a script , It's about writing scripts based on your own assumptions . So the right way to write it , It's also very simple. :
# Just write separately !!!
poco(text="poco").exists()
poco(text="poco").click()
# perhaps
if poco(text="poco").exists():
poco(text="poco").click()
Copy code There are also the following similar situations , The student's expectation should be to wait for this control to appear , And then click on it :

But there's an empty object error , Let's flip through wait_for_appearance Of API file :

You can see , wait_for_appearance There is no return value , So it's impossible to follow click Method , The correct way is as follows :
# It's so simple again , Write separately , In fact, the reason is that both methods are UI Control method
poco(text="poco").wait_for_appearance()
poco(text="poco").click()
Copy code 3. hold Poco Of API Force to use in Airtest The screenshot of the script
Take a look at the error demonstration :

In fact, this student's original intention , I want to wait until a screenshot target appears , But the problem is , wait_for_appearance() yes UI Control method (Poco frame ), Wait for the screenshot to appear , Need to use Airtest Framework of the wait() Method :
# Wait for the screenshot target to appear
wait(imgTemplate(r"tpl1622713460444.png", record_pos=(0.148, -0.346), resolution=(810, 1440)))
# wait for UI Control appears
poco(text="poco").wait_for_appearance()
Copy code 
Summary
Today's API So much for misuse , I hope that before you write the script , You can do more Airtest and Poco Of API file , Look at the inside API Details and sample scripts , Step on less holes .
Finally, I attach the API Document links , Students in need will take it by themselves :
- Airtest Of API file :airtest.readthedocs.io/zh_CN/lates…
- Poco Of API file :poco.readthedocs.io/zh_CN/lates…
边栏推荐
- Batch files: list all files in a directory with relative paths - batch files: list all files in a directory with relative paths
- 在ntpdate同步时间的时候出现“the NTP socket is in use, exiting”
- pycharm错Error updating package list: connect timed out
- Interviewer: how does the JVM allocate and recycle off heap memory
- Effect of ARP package on FTP dump under vxworks-6.6 system
- PHP secondary domain name session sharing scheme
- Myopia: take off or match glasses? These problems must be understood clearly first
- 2022 love analysis · panoramic report of digital manufacturers of state-owned enterprises
- 为抵制 7-Zip,列出 “三宗罪” ?网友:“第3个才是重点吧?”
- 【Proteus仿真】8×8LED点阵屏仿电梯数字滚动显示
猜你喜欢
![[web security] - [SQL injection] - error detection injection](/img/18/5c511871dab0e5c684b6b4c081c061.jpg)
[web security] - [SQL injection] - error detection injection

Basis of target detection (IOU)

Explore Cassandra's decentralized distributed architecture

关于视觉SLAM的最先进技术的调查-A survey of state-of-the-art on visual SLAM
![SDNU_ ACM_ ICPC_ 2022_ Winter_ Practice_ 4th [individual]](/img/3b/7523eca5bbcdbba29d9b7f6e4791a5.jpg)
SDNU_ ACM_ ICPC_ 2022_ Winter_ Practice_ 4th [individual]

2022爱分析· 国央企数字化厂商全景报告

Initial test of scikit learn Library

Rk3399 platform development series explanation (WiFi) 5.54. What is WiFi wireless LAN

远程文件包含实操

【Proteus仿真】8×8LED点阵屏仿电梯数字滚动显示
随机推荐
利用MySQL中的乐观锁和悲观锁实现分布式锁
PHP CI(CodeIgniter)log级别设置
Q2 encryption market investment and financing report in 2022: gamefi becomes an investment keyword
nifi从入门到实战(保姆级教程)——flow
Why does the std:: string operation perform poorly- Why do std::string operations perform poorly?
How to thicken the brush in the graphical interface
手机注册股票开户安全吗 开户需要钱吗
SDNU_ ACM_ ICPC_ 2022_ Winter_ Practice_ 4th [individual]
PHP二级域名session共享方案
跟我学企业级flutter项目:简化框架demo参考
为抵制 7-Zip,列出 “三宗罪” ?网友:“第3个才是重点吧?”
Leetcode binary search tree
Unreal_DataTable 实现Id自增与设置RowName
《天天数学》连载56:二月二十五日
近视:摘镜or配镜?这些问题必须先了解清楚
在ntpdate同步时间的时候出现“the NTP socket is in use, exiting”
【声明】关于检索SogK1997而找到诸多网页爬虫结果这件事
TCP拥塞控制详解 | 3. 设计空间
Record windows10 installation tensorflow-gpu2.4.0
A survey of state of the art on visual slam