Installation and use of the night God simulator of monkeyrunner (2)

In the previous article - Android development environment construction, we created and started the Android simulator built in eclipse. The simulator not only starts slowly, but also has a surprisingly poor response speed in the process of use, and often gets stuck. In order to solve this phenomenon, we have found a more suitable simulator - night God simulator. In addition to the large installation package, the speed of the simulator is very fast. It is basically the same as the real machine, or even faster. Such a simulator can be comparable to the real machine, which is more conducive to our later Android automatic test. The reasons for the selection of nocturnal simulator and the use of nocturnal simulator are described below.

1、 Reasons for the selection of nocturnal simulator

As we all know, the simulator of Android studio runs very fast, which is comparable to the real machine. Although it runs very fast, it can meet our testing needs. However, the following problems still exist:

(1) The simulator of Android studio cannot connect to WiFi, modify DNS, and run and test monkeyrunner script with the version of the test environment;

(2) If the real machine is selected, the test version can be used after DNS is modified, but the control ID cannot be obtained by hierarchyviewer, and an error will be reported when running monkeyrunner.

Some people will say that in (2), you can choose to obtain the control coordinates using the real machine instead of the control ID. see the explanation at the end of the article for the reasons for using the control ID. The following is a screenshot of an error reported by a real machine using hierarchyviewer.

Run result: failed

Reason: the script was invoked to HierarchyViewer, but the view server was not opened in the real machine.

Based on the above two reasons, we choose nocturnal simulator as the simulator to be used in the test. For us, the advantage of night God simulator is that we can connect WiFi and modify DNS. It is fast, but the memory is relatively large.

2、 Setup and connection of nocturnal simulator

1. Simulator download and setting

The nocturnal simulator occupies a large memory. You can download it from the official website: http://www.yeshen.com/ 。 After downloading, follow the installation tips to install by default or custom.

After the installation is successful, open the simulator, which can be set to display as mobile version in the setting, and it will take effect after restarting. Later, after each startup, the simulator is the size of the phone you set. Similarly, you can set other options, which can be set according to your needs.

2. Connection of simulator

After setting the simulator, in the CMD window, check whether the simulator is connected to the computer, enter ADB devices, and the result shows that there is no device connected.

Next, how to connect the simulator to the computer. Open the nocturnal simulator, enter the platform tools directory under the androidsdk in CMD, and then execute the command: ADB connect 127.0.0.1:62001. (if android_home is configured in the environment variable, open CMD directly and execute the command: ADB connect 127.0.0.1:62001). Or use the non brought by night God_ Adb.exe, enter the bin directory under the night God installation directory, and execute the command: ADB connect 127.0.0.1:62001.

Finally, in the CMD window, enter the command: ADB devices to view that the night God simulator has been connected.

3、 Use of nocturnal simulator

Like any previous Android simulator, install the app we need. We install XXX app here. At this time, because the DNS of WiFi is not modified, the online environment is connected.

1. Modification of DNS

Next, we modify DNS to XX. X.x.x and switch to the test environment.

On the settings page, select WLAN, you can see the connected WiFi, long press the left mouse button, and pop up the box to modify the network.

Click Modify network, check "show advanced options" on the network details page, and modify domain name 1 to XX. X.x.x.

Now you can open the app and enter the test account to log in.

2. Simple use of simulator

Double click the night God simulator to open it and start it. We can now open the hierarchy viewer, get the control ID of the personal app login page installed in the night God simulator, and check whether the speed meets our needs.

Open hierarchyviewer.bat under Android SDK \ tools and run it to quickly obtain the ID of the account input box, password input box and login button on the login page.

After that, switch the app to the login page and run the monkeyrunner script of the login page on the night God simulator. The script is as follows, which can be executed step by step or written directly to the PY file.

The specific script is as follows (the script will be described in the following article):

See if there is input in the simulator. Note that monkeyrunner will fail and report an error when running the above py file.

Cause: there is a problem with Python encoding. The default encoding format in Python is ASCII format. Therefore, Chinese cannot be displayed without modifying the encoding format.

Solution: add #coding: UTF-8, #- * - Coding: UTF-8 - * - or #vim: set fileencoding: UTF-8 to each Python file that needs to display Chinese. Let's choose #coding: UTF-8.

That is, at the top of the above py file, add #coding: UTF-8 and run it again. Then it can run successfully.

4、 Reason for using control ID

Monkeyrunner needs to write a script to run by obtaining the control coordinates or control ID. However, the script cannot be reused due to different resolutions when obtaining the control coordinates. It is necessary to obtain the coordinates again, so the usability of monkeyrunner script is poor.

Therefore, we use the hierarchy viewer to obtain the control ID and write a script (the method of obtaining ID or coordinates will be described later). However, the hierarchy viewer can only be connected to the Android development version mobile phone or simulator. Although there are some articles on how to root the mobile phone and open the view service on the Internet, it is recommended not to try. The mobile phone is easy to brick or restart.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>