Skip to content

Commit c3fab15

Browse files
committed
fix: add a wait in the browser opening
Signed-off-by: Jesus Recio <jrecio@izertis.com>
1 parent c6dd5d9 commit c3fab15

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

‎src/test/java/e2e/pages/ShortcutDialogPage.java‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88

99
import static e2e.support.log.Log.Log;
1010

11+
import org.openqa.selenium.TimeoutException;
1112
import org.openqa.selenium.WebElement;
1213
import org.openqa.selenium.support.PageFactory;
14+
import org.openqa.selenium.support.ui.WebDriverWait;
1315

16+
import java.time.Duration;
1417
import java.util.logging.Level;
1518

1619
import io.appium.java_client.android.AndroidDriver;
@@ -54,8 +57,17 @@ public void openShortcut() {
5457

5558
public boolean isBrowserOpen() {
5659
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+
}
6072
}
6173
}

0 commit comments

Comments
 (0)