On some version of phones this is selected as chrome default but on some the test is failing when the user is prompted with a decision Samsung web / chrome for example ;
Any solutions for this ?
@Slf4j
public class MobileSettingsActions extends BaseSettingsActions {
private static final String BROWSER_BUNDLE_ID = "com.android.chrome";
private final AppiumDriver appiumDriver;
@Override
protected void pageShouldBeOpenedInNewBrowserTab(UIElementLocator buttonLocator) {
try {
DriverWaiter.await()
.timeout(10, TimeUnit.SECONDS)
.pollInterval(2, TimeUnit.SECONDS)
.until(() -> monosyneDriver.getRequiredElement(buttonLocator).isTouchable());
} catch (ConditionTimeoutException exception) {
appiumDriver.isAppInstalled(BROWSER_BUNDLE_ID);
log.info("App is not installed on device");
}
setBrowser();
Driver.click(buttonLocator);
browserShouldBeOpened();
applicationShouldBeOpened();
}
private void setBrowser() {
DesiredCapabilities.android().setCapability(BrowserType.CHROME, true);
DesiredCapabilities.chrome().setPlatform(Platform.ANDROID);
// appiumDriver.activateApp(BROWSER_BUNDLE_ID);
}
private void browserShouldBeOpened() {
await().atMost(30, TimeUnit.SECONDS).untilAsserted(() -> assertThat(getCurrentApplicationState() == RUNNING_IN_FOREGROUND)
.as("Link wasn't opened in browser.")
.isTrue());
log.info("Link was opened in browser.");
}
private void applicationShouldBeOpened() {
Retry.twoTimes(() -> appiumDriver.navigate().back(), ConditionTimeoutException.class);
await().atMost(30, TimeUnit.SECONDS).untilAsserted(() -> assertThat(getCurrentApplicationState() == RUNNING_IN_BACKGROUND)
.as("Switch back to application wasn't made.")
.isTrue());
log.info("Switch back to application was made.");
}
private ApplicationState getCurrentApplicationState() {
return appiumDriver.queryAppState(BROWSER_BUNDLE_ID);
}
}