|
22 | 22 | import org.junit.jupiter.api.Disabled; |
23 | 23 | import org.junit.jupiter.api.Test; |
24 | 24 | import org.openqa.selenium.ScreenOrientation; |
| 25 | +import org.openqa.selenium.WebDriverException; |
25 | 26 | import org.openqa.selenium.remote.RemoteWebElement; |
26 | 27 | import org.openqa.selenium.remote.Response; |
27 | 28 | import org.openqa.selenium.remote.http.HttpMethod; |
|
32 | 33 | import static io.appium.java_client.utils.TestUtils.waitUntilTrue; |
33 | 34 | import static org.hamcrest.MatcherAssert.assertThat; |
34 | 35 | import static org.hamcrest.Matchers.greaterThan; |
35 | | -import static org.junit.jupiter.api.Assertions.assertEquals; |
36 | 36 | import static org.junit.jupiter.api.Assertions.assertFalse; |
37 | 37 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
38 | 38 | import static org.junit.jupiter.api.Assertions.assertTrue; |
@@ -94,10 +94,17 @@ public void getDeviceTimeTest() { |
94 | 94 | } |
95 | 95 |
|
96 | 96 | @Test public void orientationTest() { |
97 | | - assertEquals(ScreenOrientation.PORTRAIT, driver.getOrientation()); |
98 | | - driver.rotate(ScreenOrientation.LANDSCAPE); |
99 | | - assertEquals(ScreenOrientation.LANDSCAPE, driver.getOrientation()); |
100 | | - driver.rotate(ScreenOrientation.PORTRAIT); |
| 97 | + rotateWithRetry(ScreenOrientation.LANDSCAPE); |
| 98 | + waitUntilTrue( |
| 99 | + () -> driver.getOrientation() == ScreenOrientation.LANDSCAPE, |
| 100 | + Duration.ofSeconds(5), Duration.ofMillis(500) |
| 101 | + ); |
| 102 | + |
| 103 | + rotateWithRetry(ScreenOrientation.PORTRAIT); |
| 104 | + waitUntilTrue( |
| 105 | + () -> driver.getOrientation() == ScreenOrientation.PORTRAIT, |
| 106 | + Duration.ofSeconds(5), Duration.ofMillis(500) |
| 107 | + ); |
101 | 108 | } |
102 | 109 |
|
103 | 110 | @Test public void lockTest() { |
@@ -138,4 +145,27 @@ public void applicationsManagementTest() { |
138 | 145 | () -> driver.queryAppState(BUNDLE_ID) == ApplicationState.RUNNING_IN_FOREGROUND, |
139 | 146 | Duration.ofSeconds(10), Duration.ofSeconds(1)); |
140 | 147 | } |
| 148 | + |
| 149 | + private void rotateWithRetry(ScreenOrientation orientation) { |
| 150 | + final int maxRetries = 3; |
| 151 | + final Duration retryDelay = Duration.ofSeconds(1); |
| 152 | + |
| 153 | + for (int attempt = 0; attempt < maxRetries; attempt++) { |
| 154 | + try { |
| 155 | + driver.rotate(orientation); |
| 156 | + return; |
| 157 | + } catch (WebDriverException e) { |
| 158 | + if (attempt < maxRetries - 1) { |
| 159 | + try { |
| 160 | + Thread.sleep(retryDelay.toMillis()); |
| 161 | + } catch (InterruptedException ie) { |
| 162 | + Thread.currentThread().interrupt(); |
| 163 | + throw new RuntimeException(ie); |
| 164 | + } |
| 165 | + continue; |
| 166 | + } |
| 167 | + throw e; |
| 168 | + } |
| 169 | + } |
| 170 | + } |
141 | 171 | } |
0 commit comments