Setting Up and Configuring for Mobile Site AutomationSetting up and Connecting to a Mobile Emulator

Setting up and Connecting to a Mobile Emulator

Install Appium, Android Studio, and Python, then configure a mobile emulator for testing.

Installation steps for Appium

  1. Install Appium version 1.22.3 or the latest stable version.
  2. Download the installer from this link: Appium Desktop Releases. Choose the appropriate file for Windows.
  3. Click the downloaded file, "Appium-Server-GUI-windows-1.22.3-4.exe."
  4. The Appium Setup dialog box appears. Click "Install".
    Appium Setup Choose Installation Options dialog with Only for me option and Install button
  5. Wait for the process to complete.
  6. After completing the process, click "Finish".
    Appium Setup wizard Completing Appium Setup screen with Run Appium checkbox and Finish button
  7. Next, launch Appium and click the Start Server button, as shown:
    Appium window with Simple tab and startServer button highlighted
  8. The server starts running.
    Appium window showing The server is running status and REST http interface log output

Installation steps for Appium through command prompt

Download the latest Node and npm tools from the link: Node.JS and add the following path to the environment variables:

Under Path Variable:

C:\Program Files odejs\

Run the following commands in the Command Prompt to install the following:

  1. Install Appium
    npm install -g appium
    
  2. Install appium-installer
    npm install -g appium-installer
    
  3. Install Appium Server
    Run 'appium-installer'
    Select the 'appium server' in the list
    Click Enter.
    
  4. Install uiautomator2 driver
    Run 'appium-installer' in the Command Prompt
    Select 'Appium Driver' in the list
    Select 'uiautomator2' by pressing the Spacebar
    Press Enter
    Run the Appium server through the Command Prompt using the 'appium' command
    

Installation steps for Android Studio

  1. Download the installer from this link: Android Studio.
  2. Select "I agree with the terms." Choose the file named "android-studio-windows.exe"."
  3. Click the downloaded file, "android-studio-ide-202.7486908-windows.exe."
  4. Android Studio Setup window appears. Click Next.
    Android Studio Setup Choose Components screen with Android Virtual Device checked and Next highlighted
  5. Choose the Android Virtual Device option and click Next.
    Android Studio Setup Configuration Settings screen with install location and Next button highlighted
  6. Click Next.
    Android Studio Setup Choose Start Menu Folder screen with Install button highlighted
  7. Wait for the process to complete and click Next.
    Android Studio Setup Installation Complete screen with Next button highlighted
  8. Click "Finish".
    Android Studio Setup completion screen with Finish button highlighted
    Set the path for Android Studio in the system variables under environment variables:

    Note: Make sure that a compatible Java version is installed. To download the compatible version, refer to Java Downloads.

    • ANDROID_HOME -> C:\Users\DELL\AppData\Local\Android\Sdk

    • JAVA_HOME -> C:\Program Files\Java\jdk1.8.0_201

    • Update the following paths:

      -> C:\Users\DELL\AppData\Local\Android\Sdk\platform-tools\

      -> C:\Users\DELL\AppData\Local\Android\Sdk\tools\

      -> C:\Users\DELL\AppData\Local\Android\Sdk

Installation steps for Python

  1. Download the stable Python version

    Download the Python stable version from Python Downloads.

  2. Run the .exe file and enable the "Add Python 3.7 to PATH" checkbox. This automatically adds the environment variables during installation. Select "Install Now".

    Python 3.7.3 setup screen with Install Now and Customize installation options
  3. Wait for the process to complete and Click "Close".

  4. Install the Python Packages by running the following commands in the command prompt.

    allure-behave         2.13.2
    allure-python-commons 2.13.2
    Appium-Python-Client  3.1.1
    async-generator       1.10
    atomicwrites          1.4.1
    attrs                 23.2.0
    beautifulsoup4        4.12.3
    behave                1.2.6
    certifi               2023.11.17
    cffi                  1.16.0
    charset-normalizer    3.3.2
    colorama              0.4.6
    cryptography          41.0.7
    h11                   0.14.0
    idna                  3.6
    imageio               2.33.1
    iniconfig             2.0.0
    lazy_loader           0.3
    MouseInfo             0.1.3
    networkx              3.2.1
    numpy                 1.26.3
    opencv-python         4.9.0.80
    outcome               1.3.0.post0
    packaging             23.2
    parse                 1.20.0
    parse-type            0.6.2
    pillow                10.2.0
    pip                   23.3.2
    pixelmatch            0.3.0
    pluggy                1.3.0
    py                    1.11.0
    pycparser             2.21
    pyOpenSSL             23.3.0
    pyparsing             3.1.1
    pyperclip             1.8.2
    PySocks               1.7.1
    pytest                7.4.4
    PyWavelets            1.5.0
    PyYAML                6.0.1
    requests              2.31.0
    scikit-image          0.22.0
    scipy                 1.11.4
    selenium              4.16.0
    setuptools            69.0.3
    six                   1.16.0
    sniffio               1.3.0
    sortedcontainers      2.4.0
    soupsieve             2.5
    tifffile              2023.12.9
    tomli                 2.0.1
    trio                  0.24.0
    trio-websocket        0.11.1
    urllib3               2.1.0
    wsproto               1.2.0
    xmltodict             0.13.0
    
  5. Open the Command Prompt and type "pip install Package Name".

    For example, in the Command Prompt window, type 'pip install allure-behave'.

    Command prompt showing output of pip install allure-behave command

Launching the Emulator

Perform the following:

  1. In the Android Studio Screen, click the Device Manager icon as shown:

    Android Studio project window with Device Manager icon highlighted in top right
  2. Click the Plus icon to choose a virtual device.

    Android Studio Device Manager panel with add device plus icon highlighted, no devices connected
  3. Click Create Virtual Device.

    Android Studio Device Manager with Create Virtual Device option highlighted
  4. Choose the device model as "Pixel 8 Pro" or any other model you want to simulate and click Next.

    Android Studio Select Hardware screen with Pixel 8 Pro device and Next button highlighted
  5. Select the System Image as "API 35" corresponding to the Android version you want to use and click Next.

    A system image is a file that contains the operating system (OS) for a specific version of Android that is used to run an Android Virtual Device (AVD) in the Android Emulator.

  6. In the AVD pop-up window, click Finish.

    Virtual Device Configuration dialog for Pixel 8 Pro API 35 AVD with Finish button highlighted
  7. The virtual device (emulator) is added to the Device Manager. Click the play icon to launch the device.

    Android Studio Device Manager panel with Pixel 8 Pro API 35 emulator and play button highlighted
  8. The emulator is launched, as shown:

    Android Studio with Pixel emulator running in the Running Devices panel highlighted in blue

To set the Appium Settings

Perform the following:

  1. Open the Appium desktop app and click the "Start Server v1.13.0" button.

    Appium desktop app with Host, Port fields and Start Server v1.13.0 button
  2. The server is launched. Click the search icon to start an Inspector Session.

    Appium window showing server is running with search icon highlighted
  3. Download and Install Appium Inspector. To download and install the latest version of Appium-Inspector-windows-2023.12.2-x64.exe file, click here.

  4. To configure the desired capabilities in the Appium Inspector, click Custom Server and click Desired Capabilities.

  5. To set the desired capabilities, add the following data along with the App Package, App Activity, and device name in the Appium Inspector. To add the App Package and App Activity, see How to Fetch App Activity and App Package.

    To get the connected emulator details, run adb devices -l in the Command Prompt.

    NAME                      Value
      "platformName":      "Android",
      "automationName": "Appium",
      "deviceName":       "generic_x86",
      "browserName":      "Chrome
    
  6. After saving the Appium desired capabilities, click "Start Session" to initiate the session.

    Appium Desired Capabilities screen with platformName, deviceName, platformVersion and browserName fields
  7. Click the Start Session button.

  8. Prepare your Android phone as an emulator.

    1. Start the session > Appium is launched in the Chrome browser. This indicates that the emulator is successfully connected.
      Appium Inspector window with App Source tree and device screen showing Cookie consent buttons
    2. To verify that your Appium server is running, look for the Appium icon, similar to the one shown in the following image:
      Android emulator home screen with Appium icon highlighted in the status bar