Skip to content

fix: Set appropriate fluent wait timeouts #1316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ variables:

jobs:
- job: E2E_Tests
timeoutInMinutes: 120
timeoutInMinutes: 60
steps:
- task: NodeTool@0
inputs:
Expand Down
52 changes: 42 additions & 10 deletions src/test/java/io/appium/java_client/ios/IOSAlertTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,42 +22,74 @@

import io.appium.java_client.MobileBy;
import org.apache.commons.lang3.StringUtils;
import org.junit.After;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.util.function.Supplier;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class IOSAlertTest extends AppIOSTest {

private WebDriverWait waiting = new WebDriverWait(driver, 10000);
private static final long ALERT_TIMEOUT_SECONDS = 5;
private static final int CLICK_RETRIES = 2;

private WebDriverWait waiting = new WebDriverWait(driver, ALERT_TIMEOUT_SECONDS);
private static final String iOSAutomationText = "show alert";

@Test public void acceptAlertTest() {
private void ensureAlertPresence() {
int retry = 0;
// CI might not be performant enough, so we need to retry
while (true) {
try {
driver.findElement(MobileBy.AccessibilityId(iOSAutomationText)).click();
waiting.until(alertIsPresent());
return;
} catch (TimeoutException e) {
retry++;
if (retry >= CLICK_RETRIES) {
throw e;
}
}
}
}

@After
public void afterEach() {
try {
driver.switchTo().alert().accept();
} catch (WebDriverException e) {
// ignore
}
}

@Test
public void acceptAlertTest() {
Supplier<Boolean> acceptAlert = () -> {
driver.findElement(MobileBy.AccessibilityId(iOSAutomationText)).click();
waiting.until(alertIsPresent());
ensureAlertPresence();
driver.switchTo().alert().accept();
return true;
};
assertTrue(acceptAlert.get());
}

@Test public void dismissAlertTest() {
@Test
public void dismissAlertTest() {
Supplier<Boolean> dismissAlert = () -> {
driver.findElement(MobileBy.AccessibilityId(iOSAutomationText)).click();
waiting.until(alertIsPresent());
ensureAlertPresence();
driver.switchTo().alert().dismiss();
return true;
};
assertTrue(dismissAlert.get());
}

@Test public void getAlertTextTest() {
driver.findElement(MobileBy.AccessibilityId(iOSAutomationText)).click();
waiting.until(alertIsPresent());
@Test
public void getAlertTextTest() {
ensureAlertPresence();
assertFalse(StringUtils.isBlank(driver.switchTo().alert().getText()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void touchWithPressureTest() {

new MultiTouchAction(driver).add(tap1).add(tap2).perform();

WebDriverWait waiting = new WebDriverWait(driver, 10000);
WebDriverWait waiting = new WebDriverWait(driver, 10);
assertNotNull(waiting.until(alertIsPresent()));
driver.switchTo().alert().accept();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
public class XCUITModeTest extends AppIOSTest {

private boolean populated = false;
private WebDriverWait waiting = new WebDriverWait(driver, 10000);
private WebDriverWait waiting = new WebDriverWait(driver, 10);

@HowToUseLocators(iOSXCUITAutomation = ALL_POSSIBLE)
@iOSXCUITFindBy(iOSNsPredicate = "label contains 'Compute'")
Expand Down