当前位置:网站首页>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…
边栏推荐
- Getting started with Message Oriented Middleware
- Record windows10 installation tensorflow-gpu2.4.0
- 2022爱分析· 国央企数字化厂商全景报告
- [combinatorics] combinatorial identities (sum of variable terms 3 combinatorial identities | sum of variable terms 4 combinatorial identities | binomial theorem + derivation to prove combinatorial ide
- TCP拥塞控制详解 | 3. 设计空间
- Chinese translation of Tagore's floating birds (1~10)
- [combinatorics] summary of combinatorial identities (eleven combinatorial identities | proof methods of combinatorial identities | summation methods)*
- Détails du contrôle de la congestion TCP | 3. Espace de conception
- [proteus simulation] 8 × 8LED dot matrix screen imitates elevator digital scrolling display
- 一台服务器最大并发 tcp 连接数多少?65535?
猜你喜欢

Project -- high concurrency memory pool

Record a jar package conflict resolution process

One article takes you to understand machine learning
![[statement] about searching sogk1997 and finding many web crawler results](/img/1a/8ed3ca0030ea227adcd95e8b306aca.png)
[statement] about searching sogk1997 and finding many web crawler results

Multithread 02 thread join

深入理解 SQL 中的 Grouping Sets 语句

uploads-labs靶场(附源码分析)(更新中)

Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (III)

探索Cassandra的去中心化分布式架构

Visual SLAM algorithms: a survey from 2010 to 2016
随机推荐
Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (4)
LeetCode1491. Average value of wages after removing the minimum wage and the maximum wage
Low level version of drawing interface (explain each step in detail)
[redis foundation] understand redis master-slave architecture, sentinel mode and cluster together (Demo detailed explanation)
App mobile terminal test [3] ADB command
Nifi from introduction to practice (nanny level tutorial) - flow
How to initialize views when loading through storyboards- How is view initialized when loaded via a storyboard?
Mysql 将逗号隔开的属性字段数据由列转行
Détails du contrôle de la congestion TCP | 3. Espace de conception
Record a jar package conflict resolution process
面试官:JVM如何分配和回收堆外内存
[web security] - [SQL injection] - error detection injection
请求头不同国家和语言的表示
跟我学企业级flutter项目:简化框架demo参考
MongoDB 的安装和基本操作
8 tips for effective performance evaluation
How to set up SVN server on this machine
Deep understanding of grouping sets statements in SQL
2022 love analysis · panoramic report of digital manufacturers of state-owned enterprises
架构实战营 - 第 6 期 毕业总结