Vaibhav_Sharma
Vaibhav_Sharma

Reputation: 546

How can I navigate to home screen by clicking home button in appium while automatiing Android app?

In one test cases I used this

@Test
public void Test1()
{
    driver.launchApp();
    System.out.println("this is First test in appium suite");
    ((AppiumDriver) driver).sendKeyEvent(AndroidKeyCode.HOME); // This line of code gives error.
}

Upvotes: 1

Views: 5856

Answers (3)

Naman
Naman

Reputation: 31878

Well as of now if you are using the updated version of the java client for appium (ver 3.2.0), there is no method to go home. You can keep the app in background though for the desired amount of time using : driver.runAppInBackground(120); //where time:120 is in seconds

Upvotes: 1

Atman Bhatt
Atman Bhatt

Reputation: 23

driver.findElementByClassName("android.widget.ImageButton").click();
    WebDriverWait wait = new WebDriverWait(driver, 1000);
    wait.until(new Predicate<WebDriver>() {
        @Override
        public boolean apply(WebDriver input) {
            return input.findElement(By.name("Login")) != null;

        }
    }); 
    driver.navigate().back();

Upvotes: 1

Darshan Ambhaikar
Darshan Ambhaikar

Reputation: 785

I think your code is correct driver.sendKeyEvent(AndroidKeyCode.HOME); Must work, You can try to give some timeout after driver.launchAPP(); method because It might try to print the Line and navigate to Home before app launch.

Use Thread.sleep(5000); After the driver.launchAPP(); Let me know if it works.

Upvotes: 0

Related Questions