Webservices/API Testing FAQ’s Part-2 Postman


19. What is Postman?
  • Postman is a rest client software that started as an chrome extension but is now available as native application also.
  • Postman is basically used for API testing in which you can test your APIs with different types of request method types like post, put etc and parameters, headers and cookies.
  • Apart from setting the query parameters and checking the response, postman also let us see different response stats like time, status, headers, cookies etc.  
20. In which type of encoding does postman accept authorization credentials? Why?
  • Postman accept authorization in Base64 encoding only.
  • This is provided inbuilt in Postman or else you can also refer third party websites to convert the credentials in base64.
  • We use base64 particularly because it transmits the data into textual form and send it in easier form such as HTML form data.
  • We use Base64  because we can rely on the same 64 characters in any encoding language that we use.
21.What is meant by the term Environment with respect to Postman?

Handling Dialer Using Appium


Dialer
package SystemApps;

import java.net.URL;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidKeyCode;
import io.appium.java_client.remote.MobileCapabilityType;

public class DailANumber {
   

    public static void main(String[] args) throws Exception {
        // TODO Auto-generated method stub

        DesiredCapabilities dc= new DesiredCapabilities();
       
        dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");


Handling Calculator Using Appium


Calculator
package SystemApps;

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;

public class Calculator {

    public static void main(String[] args) throws MalformedURLException, InterruptedException {

        DesiredCapabilities dc = new DesiredCapabilities();

        dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");

How to Perform Swipe Touch Using Appium


Swipe Touch
import java.net.URL;

import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import io.appium.java_client.MobileDriver;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.touch.offset.ElementOption;

public class Example18SwipeTouchAction {

    public static void main(String[] args) throws Exception {
        // TODO Auto-generated method stub

        DesiredCapabilities dc = new DesiredCapabilities();

        dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");

Handling Ratingstar Using Appium


Rating 3 Star
import java.net.URL;
import java.util.List;

import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.MobileBy;
import io.appium.java_client.MobileDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.touch.offset.ElementOption;
import io.appium.java_client.touch.offset.PointOption;

public class Example14Rating3Star {
   
    public static void main(String[] args) throws Exception {
       
        DesiredCapabilities dc= new DesiredCapabilities();
       
        dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
       
        dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");

Handling Seekbar Using Appium


Seekbar
package NativeApps;
import java.net.URL;
import java.util.List;

import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.MobileBy;
import io.appium.java_client.MobileDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.touch.offset.ElementOption;
import io.appium.java_client.touch.offset.PointOption;

public class Example13SeekBar {
  
    public static void main(String[] args) throws Exception {
      
        DesiredCapabilities dc= new DesiredCapabilities();
      
        dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");

Handling Spinner Using Appium


Spinner
import java.net.URL;
import java.util.List;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.MobileBy;
import io.appium.java_client.MobileDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;

public class Example12SpinnerApiDemo {
   
    public static void main(String[] args) throws Exception {
    DesiredCapabilities dc= new DesiredCapabilities();
       
        dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
       
        dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
       
        dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, "5.1");//Version is number here
       
        dc.setCapability(MobileCapabilityType.DEVICE_NAME, "Android");

Handling Date Picker/Time Using Appium


Date Picker/Time
import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;

public class Example11DatePicker {

    public static void main(String[] args) throws MalformedURLException, InterruptedException {
       
        DesiredCapabilities dc= new DesiredCapabilities();
       
        dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
       
        dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
       
        dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, "5.1");//Version is number here
       
        dc.setCapability(MobileCapabilityType.DEVICE_NAME, "Android");
       
        dc.setCapability(MobileCapabilityType.APP, "C:\\apkfiles\\ApiDemos.apk");
       
        URL url =new URL("http://127.0.0.1:4723/wd/hub");

        AndroidDriver driver= new AndroidDriver(url,dc);
       
       
        driver.findElementsById("android:id/text1").get(10).click(); //Views

Handling Expandable List Using Appium


Expandable List
import java.net.URL;
import java.util.List;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;

public class Example10ExpandableList {

        public static void main(String[] args) throws Exception {
        // TODO Auto-generated method stub

        DesiredCapabilities dc= new DesiredCapabilities();
       
        dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
       
        dc.setCapability(MobileCapabilityType.DEVICE_NAME, "Android"); //Android Emulator
       
        dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");

        dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, "5.1");

        //when we ara working on multiple apps we can just copy these lines of command only thing we need to change is apk file location thats it
        dc.setCapability(MobileCapabilityType.APP, "C:\\apkfiles\\ApiDemos.apk");
       
        URL url =new URL("http://127.0.0.1:4723/wd/hub");

Handling Text Box, Check Boxes & Radio Buttons Using Appium


Text Box, Check Boxes & Radio Buttons
import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;

public class Example9CheckboxRadioButtonTextField {

    public static void main(String[] args) throws MalformedURLException {
       
        DesiredCapabilities dc= new DesiredCapabilities();
       
        dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
       
        dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
       
        dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, "5.1");//Version is number here
       
        dc.setCapability(MobileCapabilityType.DEVICE_NAME, "Android");

Handling Horizontal & Vertical Scrolling in Appium


Horizontal Scrolling
import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.MobileDriver;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.touch.offset.ElementOption;

public class Example6HorizontalScrolling {

    public static void main(String[] args) throws MalformedURLException {
   
        DesiredCapabilities dc= new DesiredCapabilities();
       
        dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
       
        dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
       
        dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, "5.1");//Version is number here
       
        dc.setCapability(MobileCapabilityType.DEVICE_NAME, "Android");

Handling Drag & Drop Using Appium


Drag And Drop Action
import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.MobileDriver;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.touch.offset.ElementOption;

public class Example6DragAndDropAction {

    public static void main(String[] args) throws MalformedURLException {
        DesiredCapabilities dc= new DesiredCapabilities();
       
        dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
       
        dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
       
        dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, "5.1");//Version is number here
       
        dc.setCapability(MobileCapabilityType.DEVICE_NAME, "Android");
       
        dc.setCapability(MobileCapabilityType.APP, "C:\\apkfiles\\more\\com.mobeta.android.demodslv-0.5.0-3_APKdot.com.apk");
       
        URL url =new URL("http://127.0.0.1:4723/wd/hub");

        AndroidDriver driver= new AndroidDriver(url,dc);

        //Navigation

Handling Alerts Using Appium



Handle Alerts API Demo
import java.net.URL;
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.MobileBy;
import io.appium.java_client.MobileDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.remote.MobileCapabilityType;

public class Example5AlertsAPIDemo {

    public static void main(String[] args) throws Exception {
        // TODO Auto-generated method stub

        DesiredCapabilities dc = new DesiredCapabilities();

        dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");

Handling Drop-down Using Appium



Handle Drop Down By Class Name
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;

public class Example4HandleDropDownsByClassName {

    public static void main(String[] args) throws MalformedURLException, InterruptedException {
        DesiredCapabilities dc= new DesiredCapabilities();
       
        dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
       
        dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
       
        dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, "5.1");//Version is number here
       
        dc.setCapability(MobileCapabilityType.DEVICE_NAME, "Android");
       

Handling Switches Using Appium


Handle Switches Using Emulator
import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;

public class Example3HandleSwitchEmulator {

    public static void main(String[] args) throws MalformedURLException {
   
        DesiredCapabilities dc= new DesiredCapabilities();
       
        dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
       
        dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
       
        dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, 9.0);//Version is number here
       
        dc.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
       
        dc.setCapability(MobileCapabilityType.APP, "C:\\apkfiles\\AndroidUI.apk");
       
        URL url =new URL("http://127.0.0.1:4723/wd/hub");

        AndroidDriver driver= new AndroidDriver(url,dc);
       
       
        //Handling switch element
       
        //1 round
        driver.findElementById("com.android.androidui:id/mySwitch").click();//click on the switch
       
        String val=driver.findElementById("com.android.androidui:id/switchStatus").getText();
       
        System.out.println(val);
       
        //2nd round
       
        driver.findElementById("com.android.androidui:id/mySwitch").click();
       
        val=driver.findElementById("com.android.androidui:id/switchStatus").getText();
       
        System.out.println(val);
       
        driver.quit();
       

    }

}

Script For Install Apk File(App) On Real Device & Virtual Device


Required Desired Capabilities
DesiredCapabilities dc= new DesiredCapabilities();
dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, "5.1");
dc.setCapability(MobileCapabilityType.DEVICE_NAME, "Android");
dc.setCapability(MobileCapabilityType.APP, "F:\\IndiaMART.apk");
Script for Install Apk file(App) on Emulator(Virtual Device)

 import java.net.URL;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;

Eclipse Configuration


Configure Eclipse Editor

 First of all we need to download required files and get ready to configure Eclipse.

Downloadable's: 

Appium Client Library (java-client-7.0.0.jar) 
Selenium stand-alone server( Selenium Java jars) 
Commons_lang3 (commons-lang3-3.8.1.jar)


Identify Elements Using Appium Inspector & Uiautomator


Steps to start Appium Inspector and inspect elements

  1. First of all, you need to start Appium GUI and then start a new session with appropriate desired capabilities for the AUT.
  2. A new window will open up, as shown in the above image.
  3. Now to locate the elements, do the following -
  4. Click on any element on the image on the left-hand side of the screen.
  5. After clicking, you will find the XML hierarchy of the app source displayed on the screen.
  6. On the right-hand side of the screen, you will find the attributes of the selected element like id or XPath of the element.
  7. You can now use your preferable method of finding the element, either by XPath or by id or by class.

Install APK(Mobile App) On Real Device using adb.exe


How to install apk file on Real device using adb.exe
  • Open the command prompt
  • Start server using adb.exe start-server
        C:\Users\admin>adb.exe kill-server
        C:\Users\admin>adb.exe start-server
  • Verify total devices using adb devices
        C:\Users\admin>adb.exe devices
  • Goto apk file directory, Run the below command to Install app.
         F:\Google Drive\Training Materials\Appium\APk Files>adb.exe install ApiDemos.apk

Install APK(Mobile App) On Real Device Using Appium Desktop


Vysor App
  • Vysor App is used for displaying mobile screens on your computer.
  • Vysor is available as a extension for Chrome. You have to install it.
  • And also available on Playstore. Download and install it.
  • Only for training purpose.

Install APK(Mobile App) On Virtual Device Using Appium Destop


Install apk file on Virtual device using Appium Desktop/server



Creating Virtual Device Using Android Studio - AVD Manager


Launch Android Studio & Create Virtual Device using AVD Manger

Appium Environment Setup On Windows


Prerequisite to use APPIUM (Windows)
Pre-requisites
  • Install Java
  • Eclipse
  • Maven plugin for Eclipse
  • TestNG plugin for Eclipse
  • Selenium Standalone Server
Android Tools
  • Android Studio
  • Appium Server/Appium Desktop
  • Appium Client Library 

Followers