When I first changed my job, I needed to use the python language, so at this time, it was not very difficult for Python to practice. So I thought of the game task script. In order to simulate the basic operations of key pressing and sliding, I thought of using appium module and environment to realize this function. The following is the process of deploying the environment. Check the solutions and record your problem process.
1. It involves the tools used, Python, AS, node JS and npm used in the appium installation, and cnpm installed, which was not used later.
2. This module is mainly used to call the corresponding driver module code to connect the corresponding device to realize the operation of the device.
2.1 the first is to deploy the server environment. The following is the reason for deployment. Use webdriver Remote must first have a corresponding server, that is http://127.0.0.1:4723/wd/hub
desc = {} desc['deviceName'] = 'a391caaf' #desc['deviceName'] = 'MQS0219701005445' desc['platformVersion'] = '12' desc['platformName'] = 'Android' #desc['appPackage'] = 'com.huawei.android.launcher' #desc['appActivity'] = 'com.huawei.android.launcher/.unihome.UniHomeLauncher' desc['appPackage'] = 'com.zte.mifavor.launcher' desc['appActivity'] = 'com.android.launcher3.uioverrides.QuickstepLauncher' self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desc)
2.2. Install node JS. Generally, the version is in the later installation. The version should be greater than version 10
sudo apt-get install node.js
The corresponding version may not work. The upgrade method will be npm described later
2.3 installation npm. The version is generally greater than version 3
sudo apt-get install npm
sudo npm install -g -n installs the version management tool of node to refine the version of node
sudo n table/v 7.0.0/latest stable installation / version 7.0.0 / latest version
2.4 when installing cnpm, sometimes the download of the original image path is slow, so you need to use the domestic Taobao image, so install cnpm. But I didn't use it
sudo npm install -g cnpm
2.5 installing appium
sudo npm install -g appium
2.6 npm unloading
sudo npm uninstall appium -g / cnpm -g
3. During installation, one is the permission problem and the other is the version problem. You can analyze it by looking at the error information. It is not listed here
4. The startup interface and network access represent the correct deployment environment
Run appium under the terminal, and the following version information appears normally
[Appium] Welcome to Appium v1.22.2
[Appium] Appium REST http interface listener started on 0.0.0.0:4723
Or the following json information appears in the web page access. The website is above http://127.0.0.1:4723/wd/hub
{"status":9,"value":{"error":"unknown command","message":"The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource","stacktrace":""}}
5. Environment configuration before startup
export ANDROID_HOME=/home/liulei/Android/Sdk export PATH=$PATH:$ANDROID_HOME/tools export PATH=$PATH:$ANDROID_HOME/tools/bin export PATH=$PATH:$ANDROID_HOME/platform-tools
vi ~/. zshrc source ~/. After zshrc, remember to restart appium service to take effect
6, the problem of adb, after this configuration, when calling the connection machine, it should correspond to the information of the system, system version, device ID, application interface and so on. The adb used is adb under platform-tools. There may be problems. My way of processing is to connect the adb of the system to Tools Directory, so that it can be used. Another
It's about configuring the system adb. I haven't tried this yet
7. After that, the python part needs to download the corresponding package for program development, and the first auxiliary script can be developed. The additional corresponding package names used are OPENCV python, appium Python client, and selenium modules
def getSize(self): x = self.driver.get_window_size()['width'] y = self.driver.get_window_size()['height'] return (x,y) def swipup(self,t): print("UPUP") screensize = self.getSize() x1 = int(screensize[0]*0.5) y1 = int(screensize[1]*0.75) y2 = int(screensize[1]*0.25) self.driver.swipe(x1,y1,x1,y2,t) def swipdown(self,t): print("DOWNDOWN") screensize = self.getSize() x1 = int(screensize[0]*0.5) y1 = int(screensize[1]*0.25) y2 = int(screensize[1]*0.75) self.driver.swipe(x1,y1,x1,y2,t) def swipleft(self,t): print("LEFTLEFT") screensize = self.getSize() x1 = int(screensize[0]*0.75) y1 = int(screensize[1]*0.5) x2 = int(screensize[1]*0.25) self.driver.swipe(x1,y1,x2,y1,t) def swipright(self,t): print("RIGHTRIGHT") screensize = self.getSize() x1 = int(screensize[0]*0.25) y1 = int(screensize[1]*0.5) x2 = int(screensize[1]*0.75) self.driver.swipe(x1,y1,x2,y1,t)
8. appium is better than the traditional coordinate method. It is not limited by the resolution. It also has many corresponding integration functions to use, which is more convenient for mobile phone simulation
See the API documentation for details https://www.kancloud.cn/testerhome/appium_docs_cn/2001600