Appium - Native Application Monitoring with Minimal OS

Prev Next

Introduction

Appium is a server written in Node.js. It can be built and installed from source or installed directly from NPM.

Appium is a freely distributed open-source mobile application UI testing framework. It allows native, hybrid and web application testing and supports automation test on physical devices, emulator or simulator. It also offers cross-platform application testing

Appium Clients Appium offers different client libraries (Java, Ruby, Python, PHP, JavaScript, and C#) that support Appium's extensions to the WebDriver protocol. When using Appium, you want to use these client libraries instead of your regular WebDriver client. You can view the full list of libraries here: http://appium.io/docs/en/about-appium/appium-clients/index.html.

To integrate Appium with our custom monitors we will need to install the below applications as well:

  1. JDK
  2. Android studio with Android SDK
  3. Xampp (installs all required php packages.)
  4. Composer (A dependency manager for PHP)

Prerequisites

  1. CentOS 7.4+
  2. 64-bit Operating System, x64-based processor 3. Node JS (NPM)
  3. An admin user account with the ability to run commands as sudo
  4. Android Device.

Video Tutorial for Installation:

Installation & Configuration

  1. Installing Appium
    Make sure that the latest node version is installed on the machine.

    1. If needed, update the node by running:
      $ sudo yum update
    2. Install Appium server by running:
      $ sudo npm install -g appium --unsafe-perm=true --allow-root
  2. Install Xampp

    1. Download the latest version of Xampp for Linux from the link below (PHP 7.4.1):
      $ wget <https://www.apachefriends.org/xampp-files/7.4.1/xampp-linux-x64-7.4.1-0-installer.run>
    2. Change the permissions to the installer:
      $ chmod 755 xampp-linux-*-installer.run
    3. Run the installer
      $ sudo ./xampp-linux-*-installer.run
      Xampp is now installed below the /opt/lampp directory.
  3. Install JDK

    1. $ yum install java-1.8.0-openjdk
    2. Check if the correct version has been installed by running:
      $ java -version
      (If Java path is not set properly, you will get error messages.)
  4. Install Android SDK

    1. Download SDK Command line tools from https://developer.android.com/sdk/index.html.
      $ wget https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip

    2. Unzip the files to a folder of your choosing within your home directory (e.g. ~/android-sdk)
      $ unzip sdk-tools-linux-4333796.zip

    3. Navigate to tools/bin directory and run the sdkmanager tool :

$ ./sdkmanager –update
$ ./sdkmanager "platforms;android-29" "platform-tools"  "build-tools;29.0.2" "extras;google;m2repository" "extras;android;m2repository"
$ ./sdkmanager --licenses
  1. Set Environment variables for Android SDK and PHP
    1. Create a shell script with any name under the /etc/profile.d/ directory:
      $ sudo vim appium_config.sh
    2. Copy and paste the below contents into this file and save it.
export PATH=$PATH:/opt/lamp/bin
export ANDROID_HOME=/home/<username>/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools

Note: Make sure that Android SDK is set properly in the ANDROID_HOME path. The directory will usually be /root/Android/Sdk/ or /home/\<username\>/Android/Sdk/

  1. Install Composer
    1. Once Environment variables are set for PHP, download the Composer installer script:
      $ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
      This command will download the composer-setup.php file to the current working directory. Learn more.
    2. To verify the data integrity of the script, compare the script SHA-384hash with the latest installer hash found here: Composer Public Keys / Signatures. The following wget command will download the expected signature of the latest Composer installer from the Composer's Github page and store it in a variable named HASH:
      $ HASH="$(wget -q -O - https://composer.github.io/installer.sig)"
    3. To verify that the installation script is not corrupted, run the following command:
      $ php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
      • If the hashes match, the message "Installer verified" will be displayed.
      • If the hashes don't match you will see "Installer corrupt". In this case, you need to redownload the Composer installation script and double-check the value of the $HASH variable with echo $HASH. Learn more.
        Once the installer is verified, you can continue to the next step.
    4. Run the following command to install Composer in the /usr/local/bin directory:
      $ php composer-setup.php --install-dir=/usr/local/bin --filename=composer
      All settings correct for using Composer
      Downloading...
      Composer (version 1.8.5) successfully installed to: /usr/local/bin/composer
    5. Use it: php /usr/local/bin/composer
      The composer is now installed as a system-wide command and it will be available for all users.
    6. Finally, verify the installation:
      $ composer
      This command will print the Composer's version, commands, and arguments.
   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __  / __ `__  / __  / __  / ___ / _ / ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/

Composer version 1.8.5 2019-04-09 17:46:47
Usage:
    command [options] [arguments]

At this point, you have successfully installed Composer on your CentOS system.

  1. Install Appium client
    1. Create a file called composer.json under the following directory:
      /opt/3genlabs/hawk/syntheticnode/service/shellmonitor/sandbox

    2. Add the following JSON to the file:
      {
      "name": "username/my-php-project",
      "repositories": [
      {
      "type": "vcs",
      "url": "https://github.com/appium/php-client"
      }
      ],
      "require":
      {
      "appium/php-client": "dev-master"
      }
      }

    3. Execute the following commandto install the required packages for the Appium PHP client:
      $ sudo composer update

Implementation

The attached sample php script installs an APK file and then asserts for an element before it clicks on a button. Code snippet will Copy this php file under the following directory:
/opt/3genlabs/hawk/syntheticnode/service/shellmonitor/sandbox/venddor/appium/php-client/test/apps/

The platform version for the PHP file is the OS version of your emulator or the android device.
Implementation.png
All the PHP scripts which are used to write the test cases will be under this directory.

  • You can also use the sample APK file which is attached for testing purposes. This apk file should be Copied under the following directory
    /opt/3genlabs/hawk/syntheticnode/service/shellmonitor/sandbox/vendor/appium/php-client/test/apps/

All the APK files which should be tested on the device will be under this directory.

  • For reference or for more examples, please look at the files under following directory:
    /opt/3genlabs/hawk/syntheticnode/service/shellmonitor/sandbox/vendor/appium/php-client/test/functional/android/
    https://github.com/appium/php-client

8. Create a custom script:
Copy the shell script appium.sh under the following directory.
/opt/3genlabs/hawk/syntheticnode/service/shellmonitor/sandbox

This script will Invoke the php file. Shell script is also attached to this article. Catchpoint requires that the script is executable. To change the file permissions, run:
$ chmod 500 appium.sh
$ chown serveruser appium.sh

  1. Create the Custom Test
    Create a Custom Test within the Catchpoint Portal using the JSON template below.  Make sure that you replace the filename with the one you chose. {"shell_command_file_name":" appium.sh"}

  2. Set up the Android Device
    You can either use a real android device or set up an emulator to test the APK files. To use ADB with your device, you’ll need to enable developer options and USB debugging:

    1. Open Settings, and select About.
    2. Tap on Build number seven times.
    3. Go back, and select Developer options.
    4. Scroll down, and check the Android debugging or USB debugging entry under Debugging.
    5. Plug your device into your computer.
    6. On the computer, open up a terminal/command prompt and type ADB devices.
    7. A dialog should show on your device, asking you to allow USB debugging. Check always allow, and choose OK.

To Set up Emulator on Android Studio, follow the links below: https://developer.android.com/studio/run/managing-avds#createavd https://developer.android.com/studio/run/managing-avds
11. Start Appium server
Make sure you start Appium as  a root user before running the tests from the catchpoint portal.
$ appium &

Results

We can set up indicators to capture the results from catchpoint’s STDOUT.

  • appium_test_time_ms
  • appium_errors\_#

appium_test_time_ms: This is the total time taken by the PHP file to execute. This is similar to thr Exec Command Time (ms) metric in the waterfall. Regular expression for Insights: (?:Time\\:\\ (\d+.\d+ )seconds)

appium_errors_#: Shows the number of errors for that particular execution of the test case or the test run. Regular expression for Insights: (?:Errors\\:\\ (\d+)\\.)

appium_errors.png

Scatterplot Results:

Scatterplot_Results.png

You can also refer to:
Appium - Native Application Monitoring