This article is from the official account of the project: “AirtestProject” Copyright notice: It is allowed to be reproduced, but the original link must be retained. Do not use it for commercial or illegal purposes

1. Introduction

Airtest and Poco automation frameworks provide text interfaces and SET_TEXT interfaces respectively to help us implement text input operations.

However, some special characters, such as Spaces that students often ask about, don’t always meet our expectations when using these two interfaces, so we’ll take a closer look at these two interfaces for text input and how we can simulate typing Spaces on various platforms.

2. Interface description of input text

1) Text interface of Airtest

Check out our Text interface in the Airtest API documentation to get the following information:

The Text interface is a cross-platform interface that supports Android, Windows and iOS platforms.

① Activate the text input box before entering

Before the text box uses text for input operations, we must activate the text box, that is, before we input operations, we usually click the text box to activate the input cursor in the text box:

Click () # Enter text(" netease Cloud Music ", Enter =False)Copy the code
② Enter the enter operation

Text Interface By default, an ENTER operation is performed after the input is complete. On Android, a carriage return might represent a search operation; On iOS, a carriage return might look like a newline operation……

If you do not want to enter after typing, you can set Enter =False:

text("message",enter=False)
Copy the code
③ Search operation after input

In some Android search input boxes, after text input, you need to click the search button on the keyboard to trigger the search action. Therefore, under Android platform, we added a parameter search to our text interface to support this situation:

text("test", search=True)
Copy the code
2) Poco’s set_text interface

Looking at the SET_text interface in the Poco API documentation, we can see that it can be used to set the text properties of the control.

For example, if we use the set_text interface to set a text attribute to a text input field, the purpose of input text is achieved. Another benefit of using this input text is that we can quickly empty the text box using poco(” text box “).set_text(” “).

3) Select text or set_text for input

The only thing we need to remember is that whichever input the text box supports, we choose the interface. Because of the variety of platforms and text fields, it is difficult to guarantee that the text interface will fully support all input fields, and the same is true for set_text.

When we can’t type in a text field using the text interface, we can see if we can use the Poco set_text interface. If we can, we can try to use the set_text interface to perform text input.

However, if the text box supports Poco set_text, and we need to perform the empty text box, then we use set_text empty, very convenient and quick:

Poco (" textbox ").set_text(" ")Copy the code

3. On the Android platform, enter a space

Both the Airtest and Poco frameworks support Android native apps, so we support using the text or set_text interface to enter text and Spaces:

Sleep (1.0) # delete for I in range(10): Poco keyevent (" 67 ") # set_text input (" com.net help ease. Cloudmusic: id/search_src_text "). The set_text (" let you go Days foreign substance ") sleep # (1.0) Set_text empty poco (" com.net help ease. Cloudmusic: id/search_src_text "). The set_text (" ")Copy the code

4. On the iOS platform, enter a space

Theoretically, both Airtest and Poco support native iOS apps, and we can use text and set_text interfaces for input operations. However, most iOS input fields do not support setting the text attribute directly, so in iOS platform, we still use the Airtest text interface to enter text and Spaces:

Sleep (1.0) # delete for I in range(10): text("\b", Enter =False)Copy the code

5. On the Windows platform, enter Spaces

Text is a cross-platform API that supports Windows. But Poco doesn’t support Windows for now (except for the game Windows that are already plugged into the POco-SDK).

So we prefer to use Airtest’s text interface to enter Spaces on Windows. Try the following:

# 英文 input text("Love Story") for I in range(10): keyevent("{BACK}") # 英文 input text("Love Story")Copy the code

We found that this did not input the Spaces we wanted as expected, so we needed to try something else, such as using the Keyevent keycode on Windows:

Keyevent ("{VK_SPACE}") text(" VK_SPACE ") sleep(1.0) for I in range(10): Keyevent ("{BACK}") # text("Love{VK_SPACE}Story")Copy the code

Can see the effect in line with our expectations, the more Windows platform keyevent key code, we can refer to the pywinauto. The rid_device_info_keyboard module content: pywinauto. Readthedocs. IO/en/latest/c… .

6. Summary

Just to recap, on Android and iOS, we pass a string with a space to the text or set_text interface, and the interface will type that space for us as expected; On Windows, we need to use the keyevent key code “{VK_SPACE}” to help us type Spaces.

If you have other questions, students can direct feedback to the issue of our project to collect web pages on: airtest.netease.com/issue_creat… .


AirtestIDE download: airtest.netease.com/ Airtest tutorial website: airtest.doc.io.netease.com/ build enterprise private cloud service: airlab.163.com/b2b

Official Q group: 654700783