diff --git a/azure-pipelines.yml b/azure-pipelines.yml index ea502ec76..39ffdeb6b 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -17,7 +17,7 @@ variables: jobs: - job: E2E_Tests - timeoutInMinutes: 120 + timeoutInMinutes: 60 steps: - task: NodeTool@0 inputs: diff --git a/src/test/java/io/appium/java_client/ios/IOSAlertTest.java b/src/test/java/io/appium/java_client/ios/IOSAlertTest.java index 06df51bd7..cb810e4d0 100644 --- a/src/test/java/io/appium/java_client/ios/IOSAlertTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSAlertTest.java @@ -22,9 +22,12 @@ 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; @@ -32,32 +35,61 @@ @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 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 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())); } } diff --git a/src/test/java/io/appium/java_client/ios/IOSTouchTest.java b/src/test/java/io/appium/java_client/ios/IOSTouchTest.java index ea2f83d9d..247e167d1 100644 --- a/src/test/java/io/appium/java_client/ios/IOSTouchTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSTouchTest.java @@ -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(); } diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/XCUITModeTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/XCUITModeTest.java index c54bf9129..ee2324256 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/XCUITModeTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/XCUITModeTest.java @@ -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'")