Do we have wait for Activity to be loaded?

Hi,

While considering for Web application, we’ve wait for page (DOM) to be loaded function available for Selenium.

Selenium Web application : ((String)((JavascriptExecutor)driver).executeScript(“return document.readyState”)).equals(“complete”);

Likewise, Do we have any function/implementation for activities to be loaded.? Here, Static waits are taking much time. Please let me know other alternatives if any existing.

Note : Tried with wait for element to be disappear for Loading Spinn bar, wait.until(ExpectedConditions.invisibilityOfElementLocated(locator));, but no luck.

Thanks & Regards,
Vijay Bhaskar.

You can wait for an element on the activity you want to be visible.

We have implemented a screen factory which detects the visible screen based on a combination of current activity and visible elements. If we are waiting for a screen change, we call the factory in a loop until the screen has changed.

We are using a wait method for the element we will interact on the page. Something like;

public WebElement visibilityWaitOfElement(int timeoutInSeconds, WebElement element) {
    return new FluentWait<>(webDriver).
            withTimeout(timeoutInSeconds, TimeUnit.SECONDS).
            pollingEvery(500, TimeUnit.MILLISECONDS).
            ignoring(NotFoundException.class).ignoring(NoSuchElementException.class).
            until(visibilityOf(element));
}

webdriver.click(visibilityWaitOfElement(15, element));

So you should use a method like visibilityWaitOfElement for all the methods on the page you will interact right after page load.

And also if there is a spin bar, you should wait for it to dissapperar after page load. Like you suggested.

WebDriverWait wait = new WebDriverWait(webDriver, seconds);
wait.until(invisibilityOfElementLocated(elementLocator));

Well…all suggestions will be working fine. Mostly, we must have to wait for an element and that should be unique from each screen. Great !!!

But, it would be better if wait functions are provided by appium team to wait for particular Activity/elements to be loaded.

@jonahss

Thanks,
Bhaskar.

You can implement wait for activity by using below logic:
long startTime = System.currentTimeMillis();
while(System.currentTimeMillis() - startTime < Time_Out)
if (getDriver().currentActivity().equals(activity))
break;

1 Like

Yes, I agree. This will be a good approach. But this requires additional verification for each activity.

Regards,
Bhaskar.