Monday 6 May 2019

Mobile UI Automation Using Python uiautomator Module

Mobile UI Automation Using Python uiautomator Module

Let's see how we can automate mobile UI using python uiautomator module. It works on Android 4.1 + .
Install python 2.7 on your system.First you need to install uiautomator package


1. How to Automate call functionality using uiautomator.

This is how you identify the element from uiautomator. You have to pick the unique properties like className,packageName,Text,resourceId etc. by using uiautomator.


from uiautomator import device as d
from uiautomator import Device
from time import sleep
import os
def VoLTE_call():
  print("Inside Call Method.")
  call = d(className='android.widget.TextView',
                     packageName='com.cyanogenmod.trebuchet',
                     text ='Phone').click()
  sleep(2)
  dialer = d(className='android.widget.ImageButton',
           packageName='com.android.dialer',
           resourceId='com.android.dialer:id/
                       floating_action_button').click()
  sleep(1)
  dialling_page = d(className='android.widget.EditText',
                    packageName='com.android.dialer',
                    resourceId='com.android.dialer:id/digits')
                                    .set_text(number)
  sleep(1)
  press_call_button = d(className='android.widget.ImageButton',
                    packageName='com.android.dialer',
                    resourceId='com.android.dialer:id/
                                dialpad_floating_action_button').click()
  sleep(5)
  #hold call
  hold = d(className='android.widget.ImageButton',
                    packageName='com.android.dialer',
                    resourceId='com.android.dialer:id/holdButton')
                             .click()
  sleep(5)
  #unhold Call
  unhold = d(className='android.widget.ImageButton',
                    packageName='com.android.dialer',
                    resourceId='com.android.dialer:id/holdButton')
                             .click()
  sleep(5)
  # mute Call
  mute= d(className='android.widget.ImageButton',
             packageName='com.android.dialer',
             resourceId='com.android.dialer:id/muteButton').click()
  sleep(5)

  #unmute call  
  unmute= d(className='android.widget.ImageButton',
             packageName='com.android.dialer',
             resourceId='com.android.dialer:id/muteButton').click()
  sleep(5)
  #speaker on  
  speaker_on= d(className='android.widget.ImageButton',
           packageName='com.android.dialer',
           resourceId='com.android.dialer:id/audioButton').click()
  sleep(5)
  # speaker off  
  speaker_off = d(className='android.widget.ImageButton',
             packageName='com.android.dialer',
             resourceId='com.android.dialer:id/audioButton').click()
  sleep(5)
  press_endcall_button = d(className='android.widget.ImageButton',
                        packageName='com.android.dialer',
                        resourceId='com.android.dialer:id/
                              floating_end_call_action_button').click()
  d.press.home()
#Call The main Method
VoLTE_call()
print(""Your test is completed...")


Friday 3 May 2019

How to Capture screenshot and video using adb commands

adb command There are multiple situations where you want to capture the screenshots or video and store in a folder all programmatically. This is simple and one line adb command that can be used to capture the screenshot and video.

Capture Screenshot:

Please find the below steps to capture the screenshot of an android device

1. Connect device to laptop. To confirm whether device is connected or not, run below command
 2. Screencap is the adb command which is used for capturing the screenshots



3. Once the screenshot is captured, its time to pull out from device to laptop.



The image is pulled on your system.

Capture Video:

Please find the below steps to capture the video of an android device. This is generally required when you want to give steps for reproducing certain issues.

1. Connect device to laptop. To confirm whether device is connected or not, run below command


2. Screenrecord is the adb command which is used for capturing the screenshots


3. Once the screen activities are recorded press ctrl+C to stop the recording.

The video which was captured is stored on sdcard. To pull out the video from sdcard please run below command

Here is simple program that depicts how programatically you can use above two commands
Same way we can also write script for video recording.


Feature Posts

Python Appium - Step by step procedure for capturing screenshot

 Why To capture screenshot? It is as important as your logs. If there is any failure for any test scenario, we can provide screenshot for th...