As we have all faced that we need to wait for loading in mobile application.Mostly we use Thread.sleep() but it is not advised to use this as we can predict the exact time to wait. Appium provides Implicit wait and Explicit wait feature. We can use implicit wait when we know the exact time to wait and Explicit wait when we don't know the exact time to wait but we need to wait until any mobile element is visible.
In this post we will see two types of Waits which are widely used in Appium-
Video -
1.Implicit Wait.
1.Implicit Wait
Implicit Wait means informing appium web driver to wait for specific
amount of time and if the web element is not visible after waiting for
that specific point then throw "No such Element found Exception".
Check out the Example given below to understand how to use Implicit wait
in Appium Test Case.In below Test case we will add a wait for 30
seconds after opening the browser so that that the page is gets loaded
completely.As we implicitly specify the time and Time Unit this is
called as implicit wait.
method implicitlywait() accepts 2 parameters first one is time value and second one is time unit like days,hours,minutes,seconds,milliseconds etc.
driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
2. Explicit Wait -
In Explicit wait along with wait time we also provide the wait
condition. It will wait till the condition or the maximum wait time
provided before throwing the Exception"ElementNotVisibleException".
We can say that Explicit wait is intelligent wait as it waits
dynamically for specified condition. Check out the below test case
example for using Appium Explicit wait.First We need to instantiate
WebDriverWait wait object with Web Driver Reference and time frame in
seconds.
Then we can use until() method for passing Expected Wait
Condition and use it in our test case for waiting until the element is
visible on the screen.Here we are using visibilityofElementLocated() condition.To
find out about other conditions type ExpectedConditions in eclipse IDE
and press cltr+space bar and you will get the list of conditions which
you can use in with Explicit Wait.
WebDriverWait wait = new WebDriverWait(driver,20); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("about_me")));
With this you can get rid of test case failure due to wait issues.
I hope you find this post useful. fallow me on facebook or google plus to get latest post updates. Happy Testing.
Thanks for your all the posts on Appium :) Much appreciated
ReplyDeleteThanks for reading .many more posts are coming soon on Appium. Stay connected via Facebook and Google+
DeleteCan both of these Implicit wait and explicit wait be used for native apps too right? and can they be used together? when I already set implicit wait at @beforeClass, can I use explicit wait in any other @test ? then which was has the priority?
ReplyDeleteAnswer to both of your question is "YES" you can use it for native apps and you can use both types of wait together.
DeleteThanks for visiting ,
Anuja
Explicitly wait is not working for me for appium
ReplyDeleteAn implicit wait tells WebDriver or Selenium Scripts to poll the DOM for a certain amount of time when Selenium Scripts trying to find an Object/Element or Object/Elements if they are not visible or Interactable.
ReplyDeletexplicit wait tell the WebDriver to wait for certain time on basis of certain Expected conditions before throwing an “ElementNotVisibleException” exception ,Explicit wait is specific wait applied only for specified elements. Explicit wait have better flexibility then Implicit wait.
For Detail With Best Example Link :
http://www.qamantra.com/2018/01/how-to-use-explicit-and-implicit-wait.html
Hi,
ReplyDeleteI am facing an issue with the wait.until(ExpectedConditions.elementToBeClickable(by));
My function is defined as
public static MobileElement waitForMobileElementToBeClickable(By by) {
try {
return (MobileElement) wait.until(ExpectedConditions.elementToBeClickable(by));
}
catch(NoSuchElementException nse) {
System.out.println("No such element found !");
return null;
}
catch(TimeoutException toe) {
System.out.println("Timeout exception cought !");
return null;
}
}
The error I am getting is this
WARNING: WebDriverException thrown by findElement(By.name: login settings)
[testng] org.openqa.selenium.WebDriverException: Returned value cannot be converted to WebElement: {ELEMENT=CAE0CBA1-8A14-4BBA-86BA-EBAF83895B41}
What string should be used in place of "about me"
ReplyDeleteThanks for the information. Very helpful. How do I follow more of your work?
ReplyDeleteI am impressed. I don't think I've met anyone who knows as much about this subject as you do. You are truly well informed and very intelligent. You wrote something that people could understand and made the subject intriguing for everyone. Really, great blog you have got here.
ReplyDeleteB2B Marketplace
Wholesalers
Our Service Partners
Refrigerator Repair Service
Satta King
Mumbai Call Girls
Buy Best Dog Kigurumi 10% OFF
ReplyDelete