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
preface
When writing test scripts, we often encounter situations where we need to enter text. Both Airtest and POCO provide interfaces for text input. Of course, many students also told us some problems in the text input process, so below, we will tell you how to text input and how to solve the common problems of text input based on the following points:
Airtest
In thetext()
The interface is introduced- 1 use
text()
Examples of interfaces - use
text()
Common problems with interfaces poco
In theset_text
The interface is introduced
Airtest
In thetext()
The interface is introduced
The Text () interface is the text input interface in Airtest. It can input text on the target device, but the text box must be active. The Text () interface is supported on Android, IOS, and Windows. It contains the following parameters:
text
– Text to be entered, for example:
text("hello")
Copy the code
enter
– Whether to run the command after the input is completeEnter
(Enter key), equivalent tokeyevent("ENTER")
The default isTrue
; If you just want to enter text, you don’t do itEnter
(Enter key), can be passedFalse
In:
text("hello",enter=False)
Copy the code
It is worth noting that the text() interface varies from platform to platform:
The Android platform
The text() interface on the Android platform has another parameter, search:
search
– Whether to press on the input keyboardsearch
Key, the default isFalse
; Part of the input box, you need to input the content, click the input keyboardsearch
Key to activate the search operation we pass inTrue
You can:
text("hello",search=True)
Copy the code
The IOS platform
The IOS text() interface, when passing text to be entered, adds a newline character \n to the text by default.
1 usetext()
Examples of interfaces
When we use the Text interface, the general flow is like this:
- Click the position you need to input, activate the input cursor;
- call
text()
Interface to enter content
text()
yosemite.apk
yosemite
Also, note that after using the Text () interface, the phone’s input method is switched to Yosemite, so you can’t see the normal keyboard (no need to panic). If manual input is required, you can switch the input method back to the system input method in the system input method Settings. We also offer android Assistant, where you can simply click the mouse to switch input methods. (You can find our official website tutorial in the menu of the official account to check the functions of Android Mobile Assistant)
usetext()
Common problems with interfaces
Processing of real machine input failure
If the text() interface fails to be entered, check to see if yosemite.apk is blocked from being installed and running. After the apk is successfully installed, the following icon appears:
text()
yosemite
text()
Yosemite (especially OPPO and Vivo) may fail to input text on certain mobile phones. If you do not need to input Chinese, try the ADB shell input command:
shell("input text 'hello world'")
Copy the code
Meanwhile, the adb shell input above can be set directly to the default input instead of the Yosemite input, such as the phone initialization in Python code like this:
from airtest.core.api import *
--device Android:///? Ime_method =ADBIME Connect to mobile phone
init_device("Android", ime_method="ADBIME")
text("hello")
Copy the code
Yosemite
Input method FAQ
Yosemite does not have a keypad. You type text through the IDE. When Yosemite is successfully installed, the following image is correct:
2. After Airtest disconnects the device, the current input method is Yosemite. You can find the phone Settings – More Settings – Language and input method (the location of the input method may vary by phone model), and then change the current input method to your normal input method.
Handling of simulator input failure
Some emulators, such as the Garth emulator, fail to type because, by default, the Yosemite input method cannot be invoked, causing the Text () interface to fail to enter text. First, check to see if the hardware-physical keyboard is enabled. Turn it off, set the default input method to Yosemite, and try again.
If it still fails (the physical keyboard option is constantly reset automatically), you can open emulator Settings in the upper right corner, check the soft keyboard option and try again:
If the input is still not available, you can consider using POCO instead, or directly using the above ADB instructions to enter the English content.
Unable to enter password in password box
Some manufacturers (such as Huawei and VIVO) restrict the input of the password box, forcing you to use the system keyboard when entering the password. If you need to enter the password, you cannot enter the content of airtest text() directly. You need to turn on the following options to enter the password:
poco
In theset_text
The interface is introduced
Poco provides a set_text interface for text input. This interface does not call the input method and can set text directly. But the specified control must be an input control, for example, in Android, an EditText widget:
poco("com.android.mms:id/recipients_editor").set_text("hello")
Copy the code
In addition, the set_text interface will only enter text, unlike the text() interface, which executes the enter key once by default.
We suggest that if the project is already connected to POCO, you can try to use SET_text of POCO to set the text content. If you cannot input (some models and some input boxes may not support set_TEXT interface), you can try using text() interface of Airtest again.