Windows 10 builds Appium automatic test environment

Windows 10 builds Appium automatic test environment

Environment building list

  • Java JDK
  • Node
  • Android SDK
  • Platform-tools
  • Build-tools
  • Emulator
  • Appium
  • Appium-doctor

I install Java JDK

download Java jdk According to the steps, Windows 10 is installed in the Path C: \ program files \ Java \ jdk1.8.0_bydefault. After installation, you need to set three properties in the control panel = > system and security = > system = > advanced system settings = > environment variables = > system variables: JAVA_HOME, classpath (case does not matter), Path. If it exists, click Edit. If it does not exist, click new.

The variable setting parameters are as follows (refer to for details: Here):

  • Variable name: JAVA_HOME

  • Variable value: C: \ program files \ Java \ jdk1.8.0_ / / configure according to your actual path

  • Variable name: CLASSPATH

  • Variable value:.;% JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar; / / remember that there is a "."

  • Variable name: Path (this variable generally exists, click Edit to add)

  • Variable value:% Java \ home% \ bin% Java \ home% \ JRE \ bin

To verify that the installation was configured successfully, open the command line tool:

java -version
# java version "1.8.0_181"
# Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
# Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
javac -version
# javac 1.8.0_181

II installation of node & NPM

download Node , install according to steps. Windows 10 is installed by default in the Path C:\Program Files\nodejs \. Generally speaking, environment variables have been added by default during installation, and it is unnecessary to add >; if not, environment variables Path should be set in control panel = > system and security = > system = > advanced system settings = > environment variables = > system variables.

  • Variable name: Path (this variable generally exists. Click Edit to add the installation Path of Node)
  • Variable value: C:\Program Files\nodejs\

Verify that the installation was successful:

node -v
# v10.14.2
npm -v
# 6.4.1

Ⅲ install Android SDK

You can use direct download to install the Android SDK environment Android studio To install, but will download a lot of useless things, occupy memory, but do not need to configure too many settings.

Here's how to install with the command line (command line installation may fail, just try several times more):

  • Select Command line tools only, sdk-tools-windows-4333796.zip for Windows, or download directly from the online disk (link: https://pan.baidu.com/s/1lQQR71t75cXucHm6sLlbVg Extraction code: dub3)
  • Create the Android SDK folder under the C disk (or your custom location)
  • Then unzip, and put the unzipped tools folder into the directory C: \ Android SDK
  • Configure environment variable Android home
    • Variable name: Android Ou home
    • Variable value: C: \ Android SDK / / to be configured according to your actual path
    • Variable name: Path
    • Variable value:% Android \ home% \ bin% Android \ home% \ tools \ bin

Verify that the installation was successful:

sdkmanager --update
# [=======================================] 100% Computing updates...

Question 1

If: warning: file C: \ users \ ly_uul.android \ repositories.cfg could not be loaded

You need to create an empty repositories.cfg file under the path C: \ users \ ly_ul.android \

Ⅳ install build tools

sdkmanager --install "build-tools;29.0.0"

V. install platform tools

  • Sdkmanager installs platform tools (sdkmanager detailed Command Reference: Here )

    # Installing with sdkmanager
    sdkmanager  --install  "platform-tools" "platforms;android-29"
    
  • Configure environment variable Path

    • Variable name: Path
    • Variable value:% Android Ou home% \ platform tools
  • Verify installation success:

    adb version
    # Android Debug Bridge version 1.0.41
    # Version 29.0.5-5949299
    # Installed as C:\android-sdk\platform-tools\adb.exe
    

The final Path is set to:

Ⅵ installation of Appium

Appium (Version 1.15.1) is an open source test automation framework for local, hybrid, and mobile web applications. It uses the WebDriver protocol to drive iOS, Android, and Windows mobile applications. Terminal installation server version input:

# Install server version
npm install -g appium

Install the latest version by default. If you want to install the specified version:

npm install -g appium@1.7.2

Uninstall Appium:

npm uninstall -g appium
npm cache clean --force

Install the desktop version (because the desktop version is convenient for element positioning, two types can be installed at the same time), download Install the corresponding version (install in two ways, easy to use).

ⅶ install appium doctor

Appium doctor is a small software that checks all (almost all) prerequisites for appium to run successfully. Terminal input:

npm install -g appium-doctor

The output of appium doctor check precondition should be as follows:

So far, the Android environment has been built!!! The real machine can run directly.
If you need to use android simulator, you need to install the simulator in step Ⅷ.

Ⅷ installing the Emulator

  • First, you need to download the image file:

    # View all installable components
    sdkmanager --list --verbose
    # Update components
    sdkmanager --update
    # install
    sdkmanager --install "system-images;android-28;google_apis;x86"
    
  • Then download the hardware accelerator:

    sdkmanager --install "extras;intel;Hardware_Accelerated_Execution_Manager"
    
  • The next step is to create the simulator (refer to avdmmanager for details: Here):

    avdmanager create avd -n android-emulator -k "system-images;android-28;google_apis;x86" -b x86 -c 100M -d 7 -f
    
  • Finally, run the simulator:

    # Android emulator is the name of the emulator created above (- N Android emulator)
    emulator -avd  android-emulator
    # perhaps
    emulator  @android-emulator
    

Tips:

android emulator cannot be run on virtual machine because there is conflict between components of virtualBox (Hyper-V or Credential Guard) and components of emulator (HAXM)

Question 1
"PANIC: Cannot find AVD system path. Please define ANDROID_SDK_ROOT"
Check whether there are 4 directories in the Android SDK Directory: emulator, platforms, platform tools, system images
Which installation is missing (if platform is missing, you can create an empty folder), installation method:
sdkmanager --install "emulator"
sdkmanager --install "platforms;android-26"
sdkmanager --install "system-images;android-26;google_apis;x86"
Reference resources: Here

Question two
"[6100]:ERROR:android/android-emu/android/qt/qt_setup.cpp:28:Qt library not found at ...\emulator\lib64\qt\lib
Could not launch 'C:\android-sdk...\emulator\qemu\windows-x86_64\qemu-system-x86_64.exe': No such file or directory "
You need to use the emulator in the emulator directory to start the virtual device (try the emulator in the tools directory and the one in the emulator directory)

IX test code

  • Install the Python environment, download install

  • Check add Python 3. X to path during installation to avoid manually configuring environment variables

  • After installation, run the python script and use it directly on the terminal: python test_android.py
    Run the test "Android. Py script (the real machine or the simulator switches the comment code by itself)!!! Script Download):

    # coding=utf-8
    import unittest
    from appium import webdriver
    import time
    import os
    
    
    class AndroidSimpleTest(unittest.TestCase):
        def setUp(self):
            calculator_desired_caps = {
                    'platformName': 'Android',
                    'platformVersion': '9.0',
                    # emulator
                    'deviceName': 'emulator-5554',
                    'appPackage': 'com.android.calculator2',
                    'appActivity': 'com.android.calculator2.Calculator'
                    # real device
                    # 'deviceName': '520381b347dd148b',
                    #'appPackage': 'com.sec.android.app.popupcalculator',
                    #'appActivity': 'com.sec.android.app.popupcalculator.Calculator'
                }
            self.driver = webdriver.Remote('http://localhost:4723/wd/hub', calculator_desired_caps)
        
        def tearDown(self):
            self.driver.quit()
        
        def test_calculator(self):
            # Test native calculator
            # The positioning elements in the code may be changed according to the actual situation
            # real device
            #self.driver.find_element_by_accessibility_id("5").click()
            #self.driver.find_element_by_accessibility_id("Plus").click()
            #self.driver.find_element_by_accessibility_id("6").click()
            #self.driver.find_element_by_accessibility_id("Equal").click()
            #self.assertEqual(self.driver.find_element_by_id("txtCalc").text, "11")
            
            # ************
            # emulator
            self.driver.find_element_by_id("digit_5").click()
            self.driver.find_element_by_accessibility_id("plus").click()
            self.driver.find_element_by_id("digit_6").click()
            self.driver.find_element_by_accessibility_id("equals").click()
            self.assertEqual(self.driver.find_element_by_id("result").text, "11")
        
        @unittest.skip("skip")
        def test_something(self):
            pass
    
    if __name__ == '__main__':
        unittest.main()
    
    

Tips:

# View device name
adb devices 
# View simulator version
adb shell getprop ro.build.version.release
# Check appPackage and appActivity, and make sure the app is opened when running the command
# For example: open the calculator first, and then run the command to get (separated by / with appPackage in front and appActivity in back)
adb shell dumpsys window windows | findstr "Current" 

View other adb related commands: Here

99 original articles published, 67 praised, 210000 visitors+
Private letter follow

Tags: Android emulator Java SDK

Posted on Wed, 15 Jan 2020 01:02:44 -0500 by aurigus