当前位置:网站首页>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…
边栏推荐
- Basis of target detection (IOU)
- Uploads labs range (with source code analysis) (under update)
- TCP擁塞控制詳解 | 3. 設計空間
- First!! Is lancet hungry? Official documents
- Golang 匿名函数使用
- Mongodb installation and basic operation
- Leetcode binary search tree
- Mb10m-asemi rectifier bridge mb10m
- Stm32f103c8t6 firmware library lighting
- 深入理解 SQL 中的 Grouping Sets 语句
猜你喜欢

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

关于视觉SLAM的最先进技术的调查-A survey of state-of-the-art on visual SLAM

跟我学企业级flutter项目:简化框架demo参考

8个酷炫可视化图表,快速写出老板爱看的可视化分析报告

From the 18th line to the first line, the new story of the network security industry

QT串口ui设计和解决显示中文乱码

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

Visual SLAM algorithms: a survey from 2010 to 2016

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

Deep understanding of grouping sets statements in SQL
随机推荐
QT串口ui设计和解决显示中文乱码
PHP二级域名session共享方案
Effect of ARP package on FTP dump under vxworks-6.6 system
[redis foundation] understand redis master-slave architecture, sentinel mode and cluster together (Demo detailed explanation)
How to set up SVN server on this machine
Is it safe to open an account with flush?
June to - -------
A survey of state of the art on visual slam
Explore Cassandra's decentralized distributed architecture
Nifi from introduction to practice (nanny level tutorial) - flow
[combinatorics] combinatorial identity (sum of variable upper terms 1 combinatorial identity | summary of three combinatorial identity proof methods | proof of sum of variable upper terms 1 combinator
手机注册股票开户安全吗 开户需要钱吗
MB10M-ASEMI整流桥MB10M
From the 18th line to the first line, the new story of the network security industry
[combinatorics] summary of combinatorial identities (eleven combinatorial identities | proof methods of combinatorial identities | summation methods)*
[solved] access denied for user 'root' @ 'localhost' (using password: yes)
Thinking about telecommuting under the background of normalization of epidemic | community essay solicitation
8 cool visual charts to quickly write the visual analysis report that the boss likes to see
Low level version of drawing interface (explain each step in detail)
Q2 encryption market investment and financing report in 2022: gamefi becomes an investment keyword