The first use of blogs, small white level, mutual communication, there is said the wrong place welcome to spray!!!
The purpose of automation is to reduce labor costs, if each time to run the automation use case to manually start the Appium client, too much trouble ~ ~ So, will Appium server's tune up and close write in the code is a necessary step.
In the steps said the pit ... (PS: Small white Pit, the great God may laugh ~ ~ ~)
1. Open the Appium client and be able to see the boot server is actually this sentence > launching Appium server with command: D:\Program Files (x86) \appium\ Node.exe lib\server\main.js--address 127.0.0.1--port 4723--platform-name Android--platform-version 23-- Automation-name Appium--device-name "MI 3W"--language en--log-no-color, such as:
You need to replace the Node.exe with the path node_modules\appium\. The cmd command is actually a node for the above command.
2. Get the command as long as the code is written into the line. The OS module is used here, and the simplest os.system can be satisfied.
The escape from the path of spaces, (), \, " is the pit daddy.
First, D:\Program Files (x86) \ Mirror into a w:, and then escape \ \ and \ ",
The Android version of the test machine corresponds to the Appium version and mobile device name, which is a unique property of the tester, so when defining the function, these two parameters are added
The specific code is as follows:
#Coding=utf-8ImportOSImport Time#Os.system ("Subst w: \" D:\Program Files (x86) \ ") #镜像用一次就行, so I commented outdefstart_appiums (devicename,level): t="start node w:\\appium\\node_modules\\appium\\lib\\server\\main.js--address 127.0.0.1--port 4723--platform-name Android--platform-version"+level+"--automation-name Appium--device-name \ ""+ DeviceName +"\ "--language zh_cn--log-no-color"Os.system (t) time.sleep (2) return
Here to deliberately emphasize, Os.system will block the process, in order to avoid not affecting the next step, before the command must add start
So far, starting Appium server has been done, and the following begins to write kill Appium server
1. Kill Appium Server is mainly to get node's process port number
Available command query port number Netstat-aon |findstr 4723
Use Os.popen to get the return value after executing the command, extracting the desired PID port number from the
Tell me about the pit I met here, first.
There are a lot of processes that are found by 4723, Os.popen are stored as character types, and there are many spaces. Here, using the stupidest little white method, go to space to split the string ~~~~~ Khan Khan-_-| |
The code is as follows:
def kill_appiums (): = Os.popen ("netstat-aon |findstr 4723"). Read () = Process.replace (' ' ,'). Split ("") [2 ]print (PID) = Os.popen ("taskkill-f-pid%s" % pid) print(M.read ())
There is no right or need to improve the place, welcome to the Big God spit Groove ~ ~
Python appium server code to start and close the pits encountered