Skip to content

Commit 820dbb7

Browse files
fix: Set appropriate fluent wait timeouts (#1316)
1 parent 568eeed commit 820dbb7

File tree

4 files changed

+45
-13
lines changed

4 files changed

+45
-13
lines changed

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ variables:
1717

1818
jobs:
1919
- job: E2E_Tests
20-
timeoutInMinutes: 120
20+
timeoutInMinutes: 60
2121
steps:
2222
- task: NodeTool@0
2323
inputs:

src/test/java/io/appium/java_client/ios/IOSAlertTest.java

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,42 +22,74 @@
2222

2323
import io.appium.java_client.MobileBy;
2424
import org.apache.commons.lang3.StringUtils;
25+
import org.junit.After;
2526
import org.junit.FixMethodOrder;
2627
import org.junit.Test;
2728
import org.junit.runners.MethodSorters;
29+
import org.openqa.selenium.TimeoutException;
30+
import org.openqa.selenium.WebDriverException;
2831
import org.openqa.selenium.support.ui.WebDriverWait;
2932

3033
import java.util.function.Supplier;
3134

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

35-
private WebDriverWait waiting = new WebDriverWait(driver, 10000);
38+
private static final long ALERT_TIMEOUT_SECONDS = 5;
39+
private static final int CLICK_RETRIES = 2;
40+
41+
private WebDriverWait waiting = new WebDriverWait(driver, ALERT_TIMEOUT_SECONDS);
3642
private static final String iOSAutomationText = "show alert";
3743

38-
@Test public void acceptAlertTest() {
44+
private void ensureAlertPresence() {
45+
int retry = 0;
46+
// CI might not be performant enough, so we need to retry
47+
while (true) {
48+
try {
49+
driver.findElement(MobileBy.AccessibilityId(iOSAutomationText)).click();
50+
waiting.until(alertIsPresent());
51+
return;
52+
} catch (TimeoutException e) {
53+
retry++;
54+
if (retry >= CLICK_RETRIES) {
55+
throw e;
56+
}
57+
}
58+
}
59+
}
60+
61+
@After
62+
public void afterEach() {
63+
try {
64+
driver.switchTo().alert().accept();
65+
} catch (WebDriverException e) {
66+
// ignore
67+
}
68+
}
69+
70+
@Test
71+
public void acceptAlertTest() {
3972
Supplier<Boolean> acceptAlert = () -> {
40-
driver.findElement(MobileBy.AccessibilityId(iOSAutomationText)).click();
41-
waiting.until(alertIsPresent());
73+
ensureAlertPresence();
4274
driver.switchTo().alert().accept();
4375
return true;
4476
};
4577
assertTrue(acceptAlert.get());
4678
}
4779

48-
@Test public void dismissAlertTest() {
80+
@Test
81+
public void dismissAlertTest() {
4982
Supplier<Boolean> dismissAlert = () -> {
50-
driver.findElement(MobileBy.AccessibilityId(iOSAutomationText)).click();
51-
waiting.until(alertIsPresent());
83+
ensureAlertPresence();
5284
driver.switchTo().alert().dismiss();
5385
return true;
5486
};
5587
assertTrue(dismissAlert.get());
5688
}
5789

58-
@Test public void getAlertTextTest() {
59-
driver.findElement(MobileBy.AccessibilityId(iOSAutomationText)).click();
60-
waiting.until(alertIsPresent());
90+
@Test
91+
public void getAlertTextTest() {
92+
ensureAlertPresence();
6193
assertFalse(StringUtils.isBlank(driver.switchTo().alert().getText()));
6294
}
6395
}

src/test/java/io/appium/java_client/ios/IOSTouchTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void touchWithPressureTest() {
8282

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

85-
WebDriverWait waiting = new WebDriverWait(driver, 10000);
85+
WebDriverWait waiting = new WebDriverWait(driver, 10);
8686
assertNotNull(waiting.until(alertIsPresent()));
8787
driver.switchTo().alert().accept();
8888
}

src/test/java/io/appium/java_client/pagefactory_tests/XCUITModeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
public class XCUITModeTest extends AppIOSTest {
4848

4949
private boolean populated = false;
50-
private WebDriverWait waiting = new WebDriverWait(driver, 10000);
50+
private WebDriverWait waiting = new WebDriverWait(driver, 10);
5151

5252
@HowToUseLocators(iOSXCUITAutomation = ALL_POSSIBLE)
5353
@iOSXCUITFindBy(iOSNsPredicate = "label contains 'Compute'")

0 commit comments

Comments
 (0)