Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more helper methods for Android/IOS #200

Open
akamarouski opened this issue Nov 27, 2023 · 1 comment
Open

Add more helper methods for Android/IOS #200

akamarouski opened this issue Nov 27, 2023 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Milestone

Comments

@akamarouski
Copy link
Contributor

No description provided.

@akamarouski akamarouski added the enhancement New feature or request label Nov 27, 2023
@akamarouski
Copy link
Contributor Author

public void hideKeyboardIfPresent(Duration timeout) {
    boolean isKeyboardShown = false;
    try {
        isKeyboardShown = new FluentWait<>(getDriver()).pollingEvery(Duration.ofMillis(300))
                .withTimeout(timeout)
                .until((driver -> isKeyboardShown()));
    } catch (TimeoutException e) {
        //do nothing
    }
    if (!isKeyboardShown) {
        return;
    }

    try {
        ((HidesKeyboard) getDriver()).hideKeyboard();
    } catch (Exception e) {
        if (!StringUtils.containsIgnoreCase(ExceptionUtils.getRootCauseMessage(e), "The software keyboard cannot be hidden")) {
            ExceptionUtils.rethrow(e);
        }
        // try another way to close keyboard
        ((PressesKey) getDriver()).pressKey((new KeyEvent((AndroidKey.BACK))));
    }
    try {
        isKeyboardShown = !new FluentWait<>(getDriver()).pollingEvery(Duration.ofMillis(300))
                .withTimeout(timeout)
                .until((driver -> !isKeyboardShown()));
    } catch (TimeoutException e) {
        // do nothing, isKeyboardShow already true
    }
    Screenshot.capture(getDriver(), ScreenshotType.EXPLICIT_VISIBLE);
    if (isKeyboardShown) {
        throw new IllegalStateException("The keyboard still present.");
    }
}

@akamarouski akamarouski added the help wanted Extra attention is needed label Feb 13, 2024
@akamarouski akamarouski added this to the 1.3.x milestone Feb 13, 2024
@akamarouski akamarouski changed the title Add more helper methods for Android Add more helper methods for Android/IOS Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
Status: Todo
Development

No branches or pull requests

1 participant