Monkeyrunner Night God simulator Installation and use (2) _android

Source: Internet
Author: User

In an article on the Android development environment, we created and launched the Eclipse's own Android simulator, which is not only slow to start, but also a surprisingly poor response in the process of using, and often occurs in the card machine. In order to solve this phenomenon, we have also found a more appropriate simulator-night God Simulator. The simulator is a little larger than the installation package, its speed is particularly fast, basic and real machine speed is not bad, even faster, such a speed can be comparable to the real machine simulator, more conducive to our later Android Automation test. The following is the choice of the night God Simulator and the use of Night God simulator two aspects.

First, the night God simulator choice Reason

As we all know, the Android Studio Simulator runs fast and can match the real machine. Although it runs very fast, it can meet the requirements of our testing. However, the following problems still exist:

(1) Android Studio Simulator can not connect WiFi, modify DNS, can not use the version of the test environment to run and test the Monkeyrunner script;

(2) If you choose the real machine, modify DNS, you can use the test version, but cannot take hierarchyviewer get control ID, run Monkeyrunner will error.

Someone will say (2), the use of the real machine can choose to get control coordinates, do not use the control ID, here to use the reason of the control ID, see the end of the article explained. Attached below a real machine using Hierarchyviewer error screenshot.

Run Result: failed

Reason: The hierarchyviewer is called in the script, but the view server is not open in the real machine.

For both of these reasons, we chose the night God Simulator as the simulator to be used in the test. Night God simulator for us, the advantage is that you can connect WiFi, modify DNS, fast, but the memory is relatively large.

The setting and connection of night God Simulator

1. Simulator Download and Setup

Night God simulator occupies large memory, you can go to the official website download: http://www.yeshen.com/. When the download is complete, follow the installation prompts by default or custom installation.

After the installation is successful, turn on the simulator, you can set it to display as a mobile version, and it will take effect after reboot. After each startup, the simulator is the size of the phone you set up. Similarly, you can set other options, which are set according to your needs.

2. Simulator connection

After the emulator is set up, in the cmd window, see if the simulator is connected to the computer, enter ADB devices, and the result shows no device connection.

Next, is how to connect the emulator to the computer. Open the Night God Simulator, then cmd into the ANDROIDSDK under the Platform-tools directory, and then execute the command: ADB connect 127.0.0.1:62001. (if Android_home is already configured in the environment variable, open cmd directly and execute the command: ADB connect 127.0.0.1:62001). Or with the non_adb.exe of the night God, into the night God installation directory in the bin directory, execute the command: ADB connect 127.0.0.1:62001.

In the last CMD window, enter the command: ADB devices, view the night God Simulator has been connected.

Third, the use of night God Simulator

Like any previous Android simulator, install the app we need, we install XXX's app, and at this point, we're connected to the online environment because we haven't modified the WiFi DNS.

1.dns modification

Below, we modify DNS for xx.x.x.x and switch to the test environment.

Set the page, select the WLAN, you can see already connected WiFi, long press the left mouse button, the frame to modify the network.

Click to modify the network, in the Network Details page, check "Show advanced Options", modify the domain name 1 for xx.x.x.x.

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

2. Simple use of simulator

Night God simulator directly double-click to open the start on the line. We can now open the hierarchy Viewer to get the control ID of the Personal app login page installed in the night God simulator and see if the speed is up to our needs.

Open the android-sdk\tools below Hierarchyviewer.bat, run, you can quickly get the login page account input box, password input box, login button ID.

Then, cut the app to the login page and run the Monkeyrunner script for the login page on the night God Simulator. The script, which can be executed step-by-step, can also be written directly to the Py file to run.

The specific script is as follows (the script is written in a later article):

From Com.android.monkeyrunner import monkeyrunner,monkeydevice from
com.android.monkeyrunner.easy Import Easymonkeydevice #提供了根据ID进行访问 from
com.android.monkeyrunner.easy import by #根据ID返回PyObject的方法
device= Monkeyrunner.waitforconnection (5, ' 127.0.0.1:62001 ') #连接夜神模拟器
monkeyrunner.sleep (3.0)
packagename= ' xxxxxxxx '
activity= ' xxxxxx '
componentname=packagename+ '/' +activity
device.startactivity (component= componentname)
Easy_device=easymonkeydevice (device) #必须在activity启动之后
Easy_device.touch (by.id (' Id/input _login_phone '), monkeydevice.down_and_up) #获取输入账号的控件ID
device.type (' 18511111111 ') #在账号输入框中输入账号

See if there is input in the emulator. Note that when Monkeyrunner runs the above py file, the error will fail.

Reason:python coding problem, the default encoding format in Python is in ASCII format, so no Chinese can be displayed without modifying the encoding format.

Workaround: in every Python file that needs to be displayed in Chinese, join #coding:utf-8, #-*-coding:utf-8-*-or #vim:set fileencoding:utf-8, we choose Coding:utf-8.

That is, at the top of the above py file, after you join #coding:utf-8, you can run it successfully.

Four, the use of the control ID reason

Monkeyrunner needs to write a script run by getting control coordinates or control IDs. However, getting the coordinates of the control causes the script to not be reused due to different resolutions, requiring that the coordinates be retrieved so that the Monkeyrunner script is less usable.

So we take the hierarchy viewer to get the control ID script (the following article tells about getting the ID or coordinate method). But hierarchy Viewer can only connect to the Android development version of the phone or simulator, although there are some how to put the cell phone root and open the View service article, it is recommended not to try, mobile phone easy to change bricks or constantly restart.

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.