Search code examples
javaandroidseleniumappium

Why does Appium on Android fail to find objects if Implicit Wait is set to 0 seconds?


I am trying out Appium for native app testing. So far, I have been evaluating Appium on native Android devices and also on the simulator (for use with a service like Sauce Labs).

I would like to move away from using implicit waits, since in my Selenium experience they aren't always reliable and don't play nice with FluentWait/WebDriverWait.

When I set Implicit Wait to 0 or disable it entirely, the very first Selenium command I issue will fail with an unhelpful error message:

Code

@BeforeMethod
public void setUp(){
        driver =  new AndroidDriver(serverAddress, capabilities);
}

@Test
public void myTest(){

    WebDriverWait wait = new WebDriverWait(driver, 10);
    wait.until(ExpectedConditions.presenceOfElementLocated(By.name("MyElement")));

}

Error: org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command.

I discovered that if I manually wait about 3 seconds using Thread.sleep(3000); after first starting up the AppiumDriver instance, then everything is okay.

It appears that Appium will allow you to send commands even if the app under test hasn't finished launching yet. If the app has not finished launching, then you get that error.

Is there a better solution than using Thread.sleep(3000);? Could I configure Appium's server to avoid this situation?


Solution

  • Yes, there is better solution than sleep. Set capabilities appWaitActivity and/or appWaitActivity.