Build appium environment under linux

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

desc = {}
        desc['deviceName'] = 'a391caaf'
        #desc['deviceName'] = 'MQS0219701005445'
        desc['platformVersion'] = '12'
        desc['platformName'] = 'Android'
        #desc['appPackage'] = ''
        #desc['appActivity'] = ''
        desc['appPackage'] = 'com.zte.mifavor.launcher'
        desc['appActivity'] = ''
        self.driver = webdriver.Remote('', 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

Or the following json information appears in the web page access. The website is above


{"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/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):
        screensize = self.getSize()
        x1 = int(screensize[0]*0.5)
        y1 = int(screensize[1]*0.75)
        y2 = int(screensize[1]*0.25)

    def swipdown(self,t):
        screensize = self.getSize()
        x1 = int(screensize[0]*0.5)
        y1 = int(screensize[1]*0.25)
        y2 = int(screensize[1]*0.75)

    def swipleft(self,t):
        screensize = self.getSize()
        x1 = int(screensize[0]*0.75)
        y1 = int(screensize[1]*0.5)
        x2 = int(screensize[1]*0.25)

    def swipright(self,t):
        screensize = self.getSize()
        x1 = int(screensize[0]*0.25)
        y1 = int(screensize[1]*0.5)
        x2 = int(screensize[1]*0.75)


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


Added by dodgei on Mon, 03 Jan 2022 17:00:24 +0200