Reputation: 39
Im automating a load money operation on android using appium, java, JUnit and as a maven project. And in order to handle timeout exception, i have a wait capacity like this:
wait = new WebDriverWait(driver, 15);
And i usually write the lines like this:
wait.until(ExpectedConditions.elementToBeClickable(By.id("login_btn"))).click();
This approach works just fine except for one line. I want my code to wait around 60 seconds for a specific line. Because it takes about 60 seconds for that page to load.
public void loadMoney() {
successfulLogIn();
wait.until(ExpectedConditions.elementToBeClickable(By.id("loadBtn"))).click();
wait.until(ExpectedConditions.elementToBeClickable(By.id("currencyEur"))).click();
wait.until(ExpectedConditions.elementToBeClickable(By.id("activityLoadMoney_textView_cardLastFourDigit"))).click();
wait.until(ExpectedConditions.elementToBeClickable(By.id("rowYourCards_card_container"))).click();
wait.until(ExpectedConditions.elementToBeClickable(By.id("moneyInputLayout_editText_mainCurrencyAmount"))).sendKeys(loadMoneyAmount);
wait.until(ExpectedConditions.elementToBeClickable(By.id("activityLoadMoney_textView_loadMoney"))).click();
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("successtext")));
MobileElement result = driver.findElement(By.id("successtext"));
Assert.assertEquals((result.getText()), "Successfully sent!");
}
In the code above, I want my code to wait around 60 seconds for this line
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("successtext")));
because it takes about 60 seconds for this text to show up. And as i mentioned above, my wait time is set to 15 seconds. Therefore im getting TimeoutException.. I dont wanna change the whole wait time to 60 seconds because it would take too much time for other methods. I just want my code to wait for 60 seconds specifically for this line only. How can i do that? Do i need to write a new method for that? If so how?
Upvotes: 1
Views: 248
Reputation: 17573
You can do like
WebDriverWait wait = new WebDriverWait(driver,10);
wait.until(ExpectedConditions.elementToBeClickable(By.id("activityLoadMoney_textView_loadMoney"))).click();
wait.wait(60); // you need to add this line
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("successtext")))
By this way you to do not create an another object of WebDriverWait
Note: you again need to change wait time further to 10 if next element waiting for 10 seconds only as after wait.wait(60);
the driver wait time set to 60 not 10 anymore
Upvotes: 1