buttons

 

Appium Concepts : Simulating “Incoming Phone Calls On Android” — Appium2.0

Simulating Incoming Phone Calls On Android

Please watch below video for complete details:

Java Code:

package demo;

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.GsmCallActions;
import io.appium.java_client.android.options.UiAutomator2Options;
import java.net.*;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class PhoneCallTest {

private AndroidDriver driver;
private String phoneno1="1111111111";
private String phoneno2="2222222222";
private String phoneno3="3333333333";

@BeforeClass
public void stepup() throws MalformedURLException {
UiAutomator2Options cap=new UiAutomator2Options();
cap.setPlatformName("android");
cap.setAutomationName("uiautomator2");
cap.setDeviceName("device14");
cap.setAppPackage("com.wdiodemoapp");
cap.setAppActivity("com.wdiodemoapp.MainActivity");

driver=new AndroidDriver(new URL("http://127.0.0.1:4723"), cap);

}

@AfterClass
public void teardown() {
if(driver!=null) {
driver.quit();
System.out.println("Test Completed");
}
}

@Test(priority=1)
public void Scenarnio1() throws InterruptedException {
//Scenario -1 receiving & decline a call
System.out.println("Scenario -1 receiving & decline a call");
Thread.sleep(5000); //pause to see the call effect
driver.makeGsmCall(phoneno1, GsmCallActions.CALL);
System.out.println(phoneno1 +" - "+"call received");
driver.openNotifications();
Thread.sleep(5000); //pause to see the call effect
driver.makeGsmCall(phoneno1, GsmCallActions.CANCEL);
System.out.println(phoneno1 +" - "+"call cancelled");
}

@Test(priority=2)
public void Scenarnio2() throws InterruptedException {
//Scenario -2 receiving,accept & decline a call
System.out.println("Scenario -2 receiving,accept & decline a call");
Thread.sleep(5000); //pause to see the call effect
driver.makeGsmCall(phoneno2, GsmCallActions.CALL);
System.out.println(phoneno2 +" - "+"call received");
driver.openNotifications();
Thread.sleep(5000); //pause to see the call effect
driver.makeGsmCall(phoneno2, GsmCallActions.ACCEPT);
System.out.println(phoneno3 +" - "+"call answered");
Thread.sleep(10000); //pause to see the call effect
driver.makeGsmCall(phoneno2, GsmCallActions.CANCEL);
System.out.println(phoneno1 +" - "+"call cancelled");
}

@Test(priority=3)
public void Scenarnio3() throws InterruptedException {
//Scenario -3 receiving,accept,Hold & decline a call
System.out.println("Scenario -3 receiving,accept,Hold & decline a call");
Thread.sleep(5000); //pause to see the call effect
driver.makeGsmCall(phoneno3, GsmCallActions.CALL);
driver.openNotifications();
System.out.println(phoneno3 +" - "+"call received");
Thread.sleep(5000); //pause to see the call effect
driver.makeGsmCall(phoneno3, GsmCallActions.ACCEPT);
System.out.println(phoneno3 +" - "+"call answered");
Thread.sleep(10000); //pause to see the call effect
driver.makeGsmCall(phoneno3, GsmCallActions.HOLD);
System.out.println(phoneno3 +" - "+"call kept on-Hold");
Thread.sleep(10000); //pause to see the call effect
driver.makeGsmCall(phoneno3, GsmCallActions.CANCEL);
System.out.println(phoneno3 +" - "+"call cancelled");
}
}

Step By Step Details:

Appium Java client provides a method — “makeGsmCall()”. This method takes two parameters:

driver.makeGsmCall(phonenumber,Action);

Parameters:

The phone number to call to:

1.A string representing the phone number which the emulator will show as calling it (this should be purely numbers, no dashes or parentheses).

List of Actions: -CALL, ACCEPT, CANCEL, HOLD

Defining an ‘action’ to be perform on the emulator will take with respect to the given phone number

Action Details:

1.GsmCallActions.CALL — To Receive a Call

2.GsmCallActions.CANCEL — To Decline a call

3.GsmCallActions.ACCEPT — To Answer a call

4.GsmCallActions.HOLD — To Keep a call on Hold

i.e. members of the GsmCallActions enum

List of Sceranios

Sceranio1 — Receiving & Decline a call

Sceranio2 — Receiving, Accept & Disconnect a call

Sceranio3 — Receiving, Accept, Hold & Disconnect a call

Sceranio1 — Receiving & decline a call

driver.makeGsmCall(phonenumber,GsmCallActions.CALL);

driver.makeGsmCall(phonenumber,GsmCallActions.CANCEL);

Sceranio2 — Receiving, Accept & Disconnect a call

driver.makeGsmCall(phonenumber,GsmCallActions.CALL);

driver.makeGsmCall(phonenumber,GsmCallActions.ACCEPT);

driver.makeGsmCall(phonenumber,GsmCallActions.CANCEL);

Sceranio3 — Receiving, Accept, Hold & disconnect a call

driver.makeGsmCall(phonenumber,GsmCallActions.CALL);

driver.makeGsmCall(phonenumber,GsmCallActions.ACCEPT);

driver.makeGsmCall(phonenumber,GsmCallActions.HOLD);

driver.makeGsmCall(phonenumber,GsmCallActions.CANCEL);

Note: Works only for Android — Emulator

GitHub Link:


No comments:

Post a Comment