Automation for Non-Functional Testing – Mobile Network Connectivity

161

     Most of the time I thought Automation only possible for functional testing. Now, Appium supports non-functional testing like testing of connectivity while automation script execution. Here, I would like to show the capability of Appium to do connectivity testing of Android Native applications. The connectivity testing includes:

  • WiFi
  • Mobile Data
  • Airplane

     HasNetworkConnection interface support setting the connectivity while test script execution. If you are declared the driver as WebDriver then you need to cast the driver with HasNetworkConnection interface. Following are the different connectivity testing actions:

Set WiFi connection on mobile native Android
((HasNetworkConnection) driver).setConnection(Connection.WIFI);

Set Mobile Data connection on mobile native Android
((HasNetworkConnection) driver).setConnection(Connection.DATA);

Set Airplane mode on mobile native Android
((HasNetworkConnection) driver).setConnection(Connection.AIRPLANE);

Set both WiFi and Mobile Data on mobile native Android
((HasNetworkConnection) driver).setConnection(Connection.ALL);

Turn-off both WiFi and Mobile Data on mobile native Android
((HasNetworkConnection) driver).setConnection(Connection.NONE);

To understand the current connectivity on mobile native Android
((HasNetworkConnection) driver).getConnection();

     Try to use all the above actions in your Automation scripts whenever you automate mobile native Android.

make it perfect !

Inspect elements in Mobile Web application

     Web content behaves differently on mobile than on desktop. While automating mobile web application most of the time I have faced lots of problem in identifying the element locators to do the actions. Here we have the Chrome DevTools for inspect element of Mobile Web application in Android and Safari Web Inspector for inspect elements of Mobile Web application in iOS.

Inspect elements using Chrome DevTools

Requirements:

1. Chrome 32 or later installed on your development machine.

2. A USB cable to connect your Android device.

3. Android 4.0+ and Chrome for Android.

Steps:

1. Connect Android mobile device to PC (make sure that Android Debugging enabled in Android Developer Option in device).

2. Open chrome browser in Android mobile device.

3. Open below URL in Desktop chrome browser:

              chrome://inspect/#devices

You can see the connected device in Chrome Developer Tool page.

1

4. Enter the URL which you want to automate and inspect elements. URL must be entered in “Open tab with url” edit box, then tap on ‘open’ button and you can see that the specified URL gets open in Device browser.

5. Click on ‘inspect’ link and it will open another window to inspect the elements. Once it gets loaded you can start inspect elements and go ahead automation.

2

 

Inspect elements using Safari Web Inspector           

1. Open Safari on your iOS device.

2. Connect it to your computer via USB.

3. Open Safari on your computer.

4. In Safari’s menu, go to Develop and, look for your device’s name.

5. Select the tab you want to inspect.

 

 

Android – ADB essential commands

     Android Debug Bridge (ADB) is an application that available along with Android SDK (in platform-tools folder). The ADB is typically accessed through the command-line interface. In Android application environment, ADB plays an important role especially in debug situations. Your Android device should be in debug mode enabled state to get the interaction with ADB services. ADB provides lot of useful services and we can utilize those by running it as ADB commands. Run the ADB commands in the following way in your command prompt (in Windows) or terminal (in Mac OS):

adb <commands>

Following are the prerequisites to run the ADB commands:

1. Android SDK should be available in your system.

2. ANDROID_HOME (of Android SDK) and PATH (of platform-tools and tools) in system environment variables.

3. Make sure that your devices debug mode is enables while running the ADB commands.

Essential ADB Commands

     Here I would like to share some essential adb commands that would be useful in Automation as well as manual testing.

  • To get device list

Purpose: This command helps to get list of all connected devices (real devices as well as virtual devices).

How to use: Run below command in command-line tool

           adb devices

list of devices

  • To install Android Application

Purpose: This command helps to install Android application into the connected devices (real devices as well as virtual devices).

How to use: Run below command in command-line tool. In the command section we need to specify location of the .apk file which stored in your system.

adb install <path of the .apk file>

install

  • To uninstall Android Application

Purpose: This command helps to uninstall Android application from connected devices (real devices as well as virtual devices).

How to use: Run below command in command-line tool. In the command section we need to specify package name of the application which need to uninstall from device.

adb uninstall <package>

unistall

  • To know package name and activity name of Android Application

Purpose: This command helps to get the package name and activity name of current running Android application. This command is very much useful for me for Appium – Android automation. The situation was I already installed the application in device but I need to specify the package name and activity name of the application in Desired Capabilities of Appium configuration. In that situation this command was very much useful for me.

How to use: Run below commands in command-line tool. In this case first we need to switch to the shell after that doing the dumpsys to get the details.

adb shell

dumpsys window windows | grep -E ‘mCurrentFocus|mFocusedApp’

getpackage

  • To capture the screenshot

Purpose: This command helps to capture the current active screen of your application in connected device. Same thing we can do from the Phone itself using the shortcut keys. But in some devices we can’t identity the shortcut keys. So in such a situation this command was helps me to capture the screenshots.

How to use: Run below commands in command-line tool. In this case first we need to create a folder in sdcard. Secondly, run the screencap command to capture the screenshot.

adb shell mkdir /sdcard/screenfolder

adb shell screencap /sdcard/screenfolder/”%time%”.png

You can save this command in a batch (.bat) executable file and run it by double click on it to capture the screenshot instead of writing the whole above commands.

screencapt

  • To record the screen flow in video format

Purpose: This command helps to record the current running flow of any application from connected devices. Sometimes the managers or client may ask the screen-recorded flow of an issue; in such a situation we can do it with help of ADB command.

How to use: Run below commands in command-line tool. In this case first we need to create a folder in sdcard. Secondly, run the screenrecord command to record the screen flow as video.

adb shell mkdir /sdcard/screenrecorded

adb shell screenrecord /sdcard/screenrecorded/test.mp4

You can save this command in a batch (.bat) executable file and run it by double click on it to record the video instead of writing the whole above commands.

video

  • Trace your device logs

Purpose: This command helps to trace the device logs. This command helps me to take the crash logs of the applications.

How to use: Run below commands in command-line tool. Here [<filter-spec>] includes different log priority levels like,

V  – Verbose

D  – Debug

I  –  Info

W – Warn

E  – Error

F  – Fatal

S  – Silent

adb logcat [ <filter-spec> ]

You can save this command in a batch (.bat) executable file and run it by double click on it to trace device logs instead of writing the whole above commands.

  • Run Android Apps over WiFi

Purpose: This command helps to run your Android applications over WiFi connection. I have faced lots of risk in executing my automation test scripts without USB cable. Finally I got a solution to run/debug my scripts in Android devices over WiFi. The concept has already there in Android SDK with help of adb. Now, I can run my test scripts in multiple Android devices without cable.

How to use: We can run the commands in following methods:

Method 1:

1.  Activate debug mode in android

2. Connect to pc via usb

3. Open command prompt type: adb tcpip 5555

4. Disconnect your tablet or smartphone from pc

5. Open command prompt type: adb connect <IPADDRESS> (IPADDRESS is the DHCP/IP address of your tablet or smartphone, which you can find by Wi-Fi -> current connected network)

6. Check for list of devices by using adb devices

Method 2:

1.  Activate debug mode in android

2. Connect to pc via usb

3. Open command prompt type: adb connect <IPADDRESS>:<port>

4. Disconnect your tablet or smartphone from pc.

5. Check for list of devices by using adb devices