Tuesday, September 1, 2020

How to Click Home Button in Appium| Mobile Automation

 

How to Click Home Button in Appium| Mobile Automation

 

In this post will learn how to get click Home button when we are using other app and want to go back Home Page.

 

 We can automate this functionality using PressKey command.

 

Command:


((PressesKey) driver).pressKey(new KeyEvent(AndroidKey.HOME));

 

Now lets write one sample program and lets see how we can click Home button:

 

package tests;

 

import java.io.IOException;

import java.net.URL;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.MobileElement;

import io.appium.java_client.android.AndroidDriver;

import io.appium.java_client.android.nativekey.AndroidKey;

import io.appium.java_client.android.nativekey.KeyEvent;

import io.appium.java_client.android.nativekey.PressesKey;

 

public class turnOnWifi {

 

       public static AndroidDriver<MobileElement> driver;

 

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

 

              DesiredCapabilities cap = new DesiredCapabilities();

              cap.setCapability("deviceName", "emulator-5554"); // your device name from adb devices

              cap.setCapability("udid", "emulator-5554");// your udid from adb devices

              cap.setCapability("appActivity", "com.android.calculator2.Calculator");

              cap.setCapability("appPackage", "com.google.android.calculator");

              cap.setCapability("platformName", "Android");

              cap.setCapability("platformVersion", "R"); // your device platform version

              driver = new AndroidDriver<MobileElement>(new URL("http://0.0.0.0:4723/wd/hub"), cap);

              driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

              Thread.sleep(5000);

 

              ((PressesKey) driver).pressKey(new KeyEvent(AndroidKey.HOME));

 

       }

 

}

 

 


 

Recorded Output:

 

 






No comments:

Post a Comment

If any suggestions or issue, please provide