Connect the simulator of appium + Python automation and start Taobao app (super detailed explanation)

Time:2020-1-12

brief introduction

In this article, brother Hong will share with his friends how to connect the simulator (computer version of virtual mobile phone), and then install an app Taobao as an example.

1、 Appium + pycharm + connect the night God simulator and start Taobao app (recommended)

1. First, open pycharm and write the code. Here, Taobao APK is used as the test demo. Taobao APK is placed on the computer desktop (or under the same directory as the code). As shown in the figure below

Where |: Driver = webdriver. Remote (‘http://127.0.0.1:4723/wd/hub ‘, desired_caps) ා how does this address come from? , see appium settings, as shown in the figure below

2. Open appium and click the triangle symbol in the upper right corner, as shown in the figure below

3. Open the night God simulator, as shown in the figure below

4. Open the CMD, enter the installation path of the night God simulator: D: \ software \ NOx \ NOx \ bin, run the command: nox_adb.exe connect 127.0.0.1:62001 and command ADB devices to view the device name, as shown in the following figure

5. Run the pycharm code and check the results, as shown in the following figure (ignore the error for the moment, which will be explained later). However, if you see two new small robots in the simulator, it means it has been successful:

6. Reference code

# coding=utf-8
#1. Set the code first. UTF-8 can support Chinese and English. As above, it is generally placed in the first line
#2. Notes: including record creation time, creator and project name.
'''
Created on 2019-6-17
@Author: Beijing Hongge QQ exchange group: 707699217
Project: learn and use Python code appium + pycharm + connect the night God simulator
'''
#3. Import module
from appium import webdriver
import time
desired_caps = {}
Desired ﹐ caps ['platformname '] =' Android '﹐ Android's APK or IOS's IPA
Desired ﹐ caps ['platformversion '] =' 4.4.2 '﹐ version number of Android system
Desired_caps ['devicename '] =' 127.0.0.1:62001 'ා mobile device name, view through ADB devices
Desired? Caps ['apppackage '] =' com. Taobao. Taobao '? Package name of apk
Desired ﹐ caps ['appactivity '] =' com. Taobao. Tao. Welcome. Welcome '﹐ launch activity of apk
#Desired ﹐ caps ['unicode keyboard '] = true ﹐ use Unicode keyboard's encoding to send strings
#Desired Chen caps ['resetkeyboard '] = true Chen hides the keyboard
Driver = webdriver. Remote ('http://127.0.0.1:4723/wd/hub ', desired  caps)  start server address, followed by mobile phone information

2、 Appium + pychar + connect to AVD simulator (not recommended)

1. The first and second steps are the same as connecting the night God simulator.

2. Start the AVD simulator (this last article (transport gate) has been demonstrated to the kids. If you don’t know clearly, go back to review it. Quite simple)

3. When we are testing, we must check whether the device connection is successful and whether the device information can be obtained. ADB devices can be implemented. Directly enter “ADB devices” in the command line console, and we can see that the connection is successful as shown in the figure below:

4. Modify the code, and repair the information of some simulators

5. Google’s own AVD simulator before running the code

6. Run results after running code

(1) AVD simulator:

Wait a moment, Taobao app starts automatically:

Agree to the agreement, Taobao app can start up on AVD simulator and enter the homepage

(2) Code run result:

(3) Appium run result:

(7) Reference code:

# coding=utf-8
 #1. Set the code first. UTF-8 can support Chinese and English. As above, it is generally placed in the first line
 
 #2. Notes: including record creation time, creator and project name.
 '''
 Created on 2019-6-17
 @Author: Beijing Hongge QQ exchange group: 707699217
 Project: learn and use Python code appium + pycharm + connect the night God simulator
 '''
 #3. Import module
 from appium import webdriver
 import time
 desired_caps = {}
 Desired ﹐ caps ['platformname '] =' Android '﹐ Android's APK or IOS's IPA
 Desired ﹐ caps ['platformversion '] =' 8.0 '﹐ version number of Android system
 Desired_caps ['devicename '] =' emulator-5554 'ා mobile device name, view through ADB devices
 Desired? Caps ['apppackage '] =' com. Taobao. Taobao '? Package name of apk
 Desired ﹐ caps ['appactivity '] =' com. Taobao. Tao. Welcome. Welcome '﹐ launch activity of apk
 #Desired ﹐ caps ['unicode keyboard '] = true ﹐ use Unicode keyboard's encoding to send strings
 #Desired? Caps ['resetkeyboard '] = true? Hide keyboard
 Driver = webdriver. Remote ('http://127.0.0.1:4723/wd/hub ', desired ﹐ caps) ﹐ start server address, followed by mobile phone information

Well, this is the night God simulator and AVD simulator to start Taobao app. All demonstrations have been completed, and the 18 dragon subduing palms have been completed. After that, take them back. Well….. It’s only 17 palms short of one

3、 Summary (Kang long regrets)

Kang long has regrets. Sum up the 17 palms in front:

1. To introduce,Marked information, how to fill in and search

Devicename: This is the device name, which can be filled in by IMEI in the properties set by the simulator, or the phone name

UDID: fill in the above for you to remember. If you use other simulators or real machines to connect, just write down the same location

Apppackage and appactivity teach you a relatively simple way to get them. Of course, you can also take the means of decompilation (APP compressed into rar or zip, and then open to see the XML file). In a word, there are many ways!

Enter the directory of SDK \ build tools \ version number (do not need to enter after configuring the system variable), CMD command:

AAPT dump badging C: \ apps \ xxxxx.apk (path \ app package name, that is, the location of the installation package on your computer)

Look, the two values we want are marked on the top!

As for the bottomURLIt’s a fixed format. Don’t study why (a thousand year old son of a bitch’s egg, a thousand year old turtle’s ass – drink a mouthful of water to set it down, this is the rule)!

Start to run and report an error. Finally, use the above method to check whether the error is caused by appactivity. After modifying the version number and appactivity, continue to report an error. Say: the installation package does not exist, and then configure it in appium

After configuration, run the code according to the above steps. You can see that there is no error in the appium log, no error in the running code, and Taobao’s installation package has been successfully installed on the night God simulator

2. Pit 1 encountered: enter appium in the CMD command, and the prompt is as shown below

Solution: reduce the version of nodejs, see the link: https://www.jb51.net/article/163240.htm

3. Pit 2 encountered: error: couldn’t start appium rest HTTP interface listener. Requested port is already in use. Please make sure there’s no other instance of appium running already

Solution: because the port is occupied by the node, you can exit the node with the following command to find the PID command: netstat – ano| findstr “7922” (this 4723 is the occupied port, we need to find the PID of the program occupying the port first). Stop PID command: taskkill / PID [process code] – t (end the process) – f (force to end the process and all subprocesses).

I don’t know if the port is occupied. You can read this blog of Hongge: portal

summary

The above is the connection simulator of appium + Python automation introduced by Xiaobian to you and starts Taobao app (super detailed explanation), hoping to help you. If you have any questions, please leave a message to me, and Xiaobian will reply to you in time. Thank you very much for your support of the developepaer website!
If you think this article is helpful to you, welcome to reprint, please indicate the source, thank you!