Typing text with UiAutomator Android
<p>I'm trying to test my app <code>google signup / login feature</code>, <code>particularly</code> the case that the user tries to add a new account that's not listed on the dialog.</p>

<p>The setup used corresponds to the default google "add account" setup.</p>

<p>The issue I'm having is that I can't seem to type the the e-mail when the app asks for it and then press the 'next' button</p>

<p><strong>Here's my code</strong></p>

<pre><code>        // Find add account button using uiautomator
        UiObject addButton = mDevice.findObject(new UiSelector().resourceId("android:id/button2"));
        assertEquals(true, addButton.exists());
        // Click the button

        // Fill email text box
        UiObject emailBox = mDevice.findObject(new UiSelector().resourceId("identifierId"));
        emailBox.waitForExists(TIMEOUT);
        assertEquals(true, emailBox.exists());
        emailBox.legacySetText(googleEmail);

        // Find 'NEXT' Button
        UiObject nextButton = mDevice.findObject(new UiSelector().resourceId("identifierNext"));
        assertEquals(true, nextButton.exists());
        nextButton.click();

        // Fill password
        UiObject passwordBox = mDevice.findObject(new UiSelector().resourceId("password"));
        passwordBox.waitForExists(TIMEOUT);
        assertEquals(true, passwordBox.exists());
        emailBox.clearTextField();
        emailBox.setText(googlePassword);

        // Find 'NEXT' Button
        nextButton = mDevice.findObject(new UiSelector().resourceId("next"));
        assertEquals(true, nextButton.exists());
        nextButton.click();

        // Find 'ACCEPT' Button
        nextButton = mDevice.findObject(new UiSelector().resourceId("next"));
        nextButton.waitForExists(TIMEOUT);
        assertEquals(true, nextButton.exists());
        nextButton.click();
</code></pre>

<p>The app gets to the screen where is the email is supposed to be typed, and it doesn't fail on the the <code>"assertEquals(true, emailBox.exists());"</code> so I believe that the app is detecting it correctly.</p>

<p>I've also tried using <code>"setText"</code> instead of <code>"legacySetText"</code> and the string is injected but then the "next" button isn't enabled.</p>

<p>Also, sometimes the keyboard pops up and the text is typed but this seems to be random and I can't replicate it at will.</p>

<p>What am I doing wrong here?</p>

<p>EDIT:</p>

<p>I've commented the rest of the code and changed the button assertion and as expected the "next" button doesn't get enabled because no text was typed.</p>

<pre><code>// Find add account button using uiautomator
        UiObject addButton = mDevice.findObject(new UiSelector().resourceId("android:id/button2"));
        assertEquals(true, addButton.exists());
        // Click the button
        addButton.click();

        // Fill email text box
        UiObject emailBox = mDevice.findObject(new UiSelector().resourceId("identifierId").descriptionContains("Enter your email "));
        emailBox.waitForExists(TIMEOUT);
        assertEquals(true, emailBox.exists());
        emailBox.legacySetText(googleEmail);

        // Find 'NEXT' Button
        UiObject nextButton = mDevice.findObject(new UiSelector().resourceId("identifierNext"));
        assertEquals(true, nextButton.isEnabled());
        nextButton.click();
</code></pre>

<p>The error says that it expected true but the result was false at the "assertEquals(true, nextButton.isEnabled());" line</p>

<p>EDIT 2:
I've found the issue to be the way the text is interpreted by google's login page.</p>

<p>With uiautomatorviewer I grabbed a screenshot of the view and inspected the EditText field in which i had manually written some text. I've found that the text I've written didn't populate the text attribute but instead it went to the content-description attribute. </p>

<p>My issue now is that I've only found a way to edit text with the setText method from the framework. I've tried clicking the view and then setting the text but with no success. Is there any way to change the content-description with uiautomator?</p>