|
8 | 8 |
|
9 | 9 | import static e2e.support.log.Log.Log; |
10 | 10 |
|
| 11 | +import org.openqa.selenium.TimeoutException; |
11 | 12 | import org.openqa.selenium.WebElement; |
12 | 13 | import org.openqa.selenium.support.PageFactory; |
| 14 | +import org.openqa.selenium.support.ui.WebDriverWait; |
13 | 15 |
|
| 16 | +import java.time.Duration; |
14 | 17 | import java.util.logging.Level; |
15 | 18 |
|
16 | 19 | import io.appium.java_client.android.AndroidDriver; |
@@ -54,8 +57,17 @@ public void openShortcut() { |
54 | 57 |
|
55 | 58 | public boolean isBrowserOpen() { |
56 | 59 | Log.log(Level.FINE, "Starts: check if browser is open"); |
57 | | - String currentPackage = driver.getCurrentPackage(); |
58 | | - return currentPackage.equals("com.android.chrome") || currentPackage.equals("org.mozilla.firefox") |
59 | | - || currentPackage.equals("com.microsoft.emmx") || currentPackage.equals("com.android.browser"); |
| 60 | + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(WAIT_TIME)); |
| 61 | + try { |
| 62 | + return wait.until(d -> { |
| 63 | + String currentPackage = ((AndroidDriver) d).getCurrentPackage(); |
| 64 | + Log.log(Level.FINE, "Current package while waiting browser: " + currentPackage); |
| 65 | + return currentPackage.equals("com.android.chrome") || currentPackage.equals("org.mozilla.firefox") |
| 66 | + || currentPackage.equals("com.microsoft.emmx") || currentPackage.equals("com.android.browser"); |
| 67 | + }); |
| 68 | + } catch (TimeoutException e) { |
| 69 | + Log.log(Level.WARNING, "Browser was not opened. Last current package: " + driver.getCurrentPackage()); |
| 70 | + return false; |
| 71 | + } |
60 | 72 | } |
61 | 73 | } |
0 commit comments