Before i do addition in capabilities ("automationame", "uiautomator2"), my code works well. But, after im using uiautomator2, the implicitlyWait is not working. The code doesn't wait for the element appears. If the elements doesn't exists, the automation going to shutdown soon. It also happened while move from one activity to another activity. Can anyone helps me to solve this issue?
Below is my setup code :
public void setUp() {
System.out.println("Creating session.....");
String path = System.getProperty("user.dir");
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("platformName", "Android");
cap.setCapability("platformVersion", "6.0.1");
cap.setCapability("deviceName", "88929a3d");
cap.setCapability("automationName", "uiautomator2");
cap.setCapability("appPackage", "io.selendroid.testapp");
cap.setCapability("appActivity", "HomeScreenActivity");
cap.setCapability("appWaitActivity", "HomeScreenActivity, RegisterUserActivity");
cap.setCapability("appWaitDuration", 3000);
cap.setCapability("app", path + "//apk//selendroid.apk");
try {
driver = new AndroidDriver<>(new URL("http://localhost:4723/wd/hub"), cap);
} catch (MalformedURLException e) {
e.printStackTrace();
}
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
System.out.println("Session is created successfully");
}
ImplicitWait is not a solution for element waiting. It is a way to set timeout for pulling DOM when trying to find an element(s) if it is not immediately available.
Use explicit wait to wait for element:
new WebDriverWait(driver,<timeoutInSeconds>) .until(ExpectedConditions.presenceOfElementLocated(<locator>));
Note: In your code you set appWaitDuration capability
Timeout in milliseconds used to wait for the appWaitActivity to launch (default 20000)
it has nothing to do with elements and 3 sec is not enough in my opinion
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.