mardi 26 janvier 2016

Getting Toolbar's title with Android's UI integration test framework

I have an fragment which set's the title to the entity the user is currently editing as follows:

        Activity activity = this.getActivity();
        CollapsingToolbarLayout appBarLayout = (CollapsingToolbarLayout) activity.findViewById(R.id.toolbar_layout);
        if (appBarLayout != null) {
            appBarLayout.setTitle(mItem.name);
        }

In the testing code I successfully navigate to the fragment, however I'm unable to locate the element by the text as follows:

class DetailWrapper {

    protected UiObject2 find( BySelector selector ){
        device.wait(Until.findObject(selector), 2 * 1000);
        return device.findObject(selector);
    }

    public ItemView hasName(String itemName) throws Exception {
        UiObject2 title = find(By.text(itemName));
        assertEquals(title.getText(), itemName);
        return this;
    }
}

title in hasName(String) is always null in the assert despite being on the correct activity with the correct title. What is the best method to assert the AppBar's title?

Aucun commentaire:

Enregistrer un commentaire