SoFunction
Updated on 2024-11-13

Appium + python automation of connecting to the simulator and start Taobao APP (super detailed)

synopsis

This macro will take the guys to share how to connect the emulator (computer version of the virtual phone), and then install an APP-Taobao as an example.

First, appium+pycharm+connect to Night God simulator and start Taobao APP (recommended)

1, first open pycharm and write a good code, here to Taobao APK as a test Demo, Taobao APK I was placed on the desktop of the computer (or placed in the same directory with the code). As you can see in the picture below

where |: driver = ('http://127.0.0.1:4723/wd/hub',desired_caps) # Where did this address come from? See the appium settings item, as shown below

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

3. Open the Night God Emulator as shown below

4, open CMD, enter the Night God emulator installation path: D: \software\nox\Nox\bin, run the command: nox_adb.exe connect 127.0.0.1:62001 and the command adb devices to see the name of the device, as follows

5, run pycharm code, and view the results, as shown in the following chart (temporarily ignore the problem of errors, the follow-up will explain) but in the simulator to see the addition of two new small robots, it means that it has been successful:

6. Reference code

# coding=utf-8
# 1. First set the encoding, utf-8 can support Chinese and English, such as the above, generally placed in the first line
# 2. Comments: Include when the record was created, who created it, and the name of the project.
'''
Created on 2019-6-17
@author: Beijing, capital of People's *-* businessman QQcommunication group:707699217
Project:Learning and using python code appium+pycharm+connect night god simulator
'''
# 3. Import module
from appium import webdriver
import time
desired_caps = {}
desired_caps['platformName'] = 'Android' #android apk or IOS ipa
desired_caps['platformVersion'] = '4.4.2' #android version number
desired_caps['deviceName'] = '127.0.0.1:62001' # Cell phone device name, viewed via adb devices
desired_caps['appPackage'] = '' The package name of the #apk
desired_caps['appActivity'] = '' #apk's launcherActivity
# desired_caps['unicodeKeyboard'] = True # Use unicodeKeyboard's encoding to send the string
# desired_caps['resetKeyboard'] = True # # Hide the keyboard.
driver = ('http://127.0.0.1:4723/wd/hub', desired_caps) ##Startup server address,Followed by a cell phone message.

II. appium+pycharm+connect AVD emulator (not recommended)

1. The first and second steps are the same as connecting to Night God Emulator.

2, start the AVD simulator (this last (Portal) are demonstrated to the partners, not clear return to the head to review, you can. Quite simple)

3, we are testing, we definitely need to check whether the device connection is successful, whether the device information can be obtained. adb devices can be realized, directly in the command line console type "adb devices", we can see as shown in the figure connected successfully:

4, modify the code, will be some of the simulator's information can be fixed to the

5. Google's own AVD emulator before running the code

6. Running results after running the code

(1) AVD simulator:

Wait a little while, the Taobao App launched automatically:

Agree to the agreement and the Taobao App can be launched on the AVD emulator and go to the homepage!

(2) Code run results:

(3) Results of the appium run:

(7) Reference code:

 # coding=utf-8
 # 1. First set the encoding, utf-8 can support Chinese and English, such as the above, generally placed in the first line
 
 # 2. Comments: Include when the record was created, who created it, and the name of the project.
 '''
 Created on 2019-6-17
 @author: Beijing, capital of People's *-* businessman QQcommunication group:707699217
 Project:Learning and using python code appium+pycharm+connect night god simulator
 '''
 # 3. Import module
 from appium import webdriver
 import time
 desired_caps = {}
 desired_caps['platformName'] = 'Android' #android apk or IOS ipa
 desired_caps['platformVersion'] = '8.0' #android version number
 desired_caps['deviceName'] = 'emulator-5554' # Cell phone device name, viewed via adb devices
 desired_caps['appPackage'] = '' The package name of the #apk
 desired_caps['appActivity'] = '' #apk's launcherActivity
 # desired_caps['unicodeKeyboard'] = True #Use unicodeKeyboard's encoding for sending strings
 # desired_caps['resetKeyboard'] = True #Hide the keyboard.
 driver = ('http://127.0.0.1:4723/wd/hub', desired_caps) #Startup server address,Followed by a cell phone message.

Well, to this night god simulator and AVD simulator to start Taobao APP, has all demonstrated complete, a great success, descending dragon eighteen palms has all played, play to take back. Er 。。。。。 There is still one palm short of seventeen palms (Hyper Dragon)

III. Summary (hyperactive)

Hyperion, summarizing the previous seventeen palms together:

1. Introduction.Marked information, how to fill in and find

deviceName: this is the name of the device, you can choose to fill in the IMEI in the properties of the emulator settings, or the name of the phone

udid: fill in here what the OP told you to remember, if using other emulators or real machines etc. to connect, same location, just write it down

appPackage and appActivity, to teach you a relatively simple way to get, of course, you can also take the means of decompilation (app compressed into rar or zip, and then open to look at the xml file), in short, there are many ways!

Enter sdk\build-tools\version number of the directory (after configuring system variables resonance do not need to enter), cmd command:

aapt dump badging C:\apps\ (path\app package name, which is the location of the installer on your computer)

Take a look, marked at the top are the two values we want!

As for the lowerURL It's a fixed format, don't research why (thousand year old bastard's egg, ten thousand year old turtle's ass - take a sip of water to lighten (egg) up, it's a rule (turtle butt))!

Started to run the error, and finally through the above method to see because the appActivity error, modify the version number and appActivity or continue to report errors, saying: the installation package does not exist, and then configure the appium in the

After the configuration, run the code according to the above steps, you can see that the appium log does not report errors, run the code does not report errors, the Taobao installation package will be successfully installed on the Night God emulator!

2, encountered pitfalls 1: in the CMD command to enter appium, the prompt is shown below

Solution: lower the version of nodejs, refer to the link:https:///article/

3、Pitfalls encountered2:(of a computer) runappiumdraw attention to sth.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 node, you can use the following exit node, find out the PID command::: netstat -ano|findstr "7922" (this 4723 is the occupied port, we need to find the PID of the program that occupies the port first). Stop PID command: taskkill /pid [process code] -t (end the process) -f (force the end of the process and all child processes).

For those of you who don't know about port occupancy, you can read this blog post by Macro on checking port occupancy:portal

summarize

The above is a small introduction to the Appium + python automation of the connection simulator and start Taobao APP (super detailed), I hope to help you, if you have any questions please leave me a message, I will promptly reply to you. I would also like to thank you very much for your support of my website!
If you find this article helpful, please feel free to reprint it, and please note the source, thank you!