mercredi 20 janvier 2021

How to access Telegram using UIAutomator in Android?

I am trying to use UIAutomator in order to be able to have a wider range of Instrumentation tests for my Android app.

One of my tests is supposed to check if it's possible to share a link from the app via Telegram.

These are the functions I use:

public static void clickUiTextButton(UiDevice device, String text, boolean waitForNewWindow) throws UiObjectNotFoundException {
    UiObject button = device.findObject(new UiSelector().text(text));
    if (!waitForNewWindow) {
        button.click();
    } else {
        button.clickAndWaitForNewWindow();
    }
}

public static void clickTelegramChat(UiDevice device, String text) throws UiObjectNotFoundException {
    UiObject button = device.findObject(new UiSelector()
            .textMatches(TEXT_TELEGRAM_CHAT_NAME));

    button.click();
}

I use the first function to click the "Telegram" text in the share intent and it works flawlessly. However, when I try to click the chat that I want to share the link to (using the second function), nothing happens.

I read in the docs that there are multiple ways to select a text, but .textMatches() seems to be the only one that can match non-widget objects.

Can anybody help me to figure out how to properly select the correct Telegram chat?

Aucun commentaire:

Enregistrer un commentaire