I'm trying to test my app google signup / login feature, particularly the case that the user tries to add a new account that's not listed on the dialog.
The setup used corresponds to the default google "add account" setup.
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
Here's my 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();
The app gets to the screen where is the email is supposed to be typed, and it doesn't fail on the the "assertEquals(true, emailBox.exists());" so I believe that the app is detecting it correctly.
I've also tried using "setText" instead of "legacySetText" and the string is injected but then the "next" button isn't enabled.
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.
What am I doing wrong here?
EDIT:
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.
// 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();
The error says that it expected true but the result was false at the "assertEquals(true, nextButton.isEnabled());" line
EDIT 2: I've found the issue to be the way the text is interpreted by google's login page.
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.
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?
instead of:
emailBox.legacySetText(googleEmail);
try to write a code like this:
// click the admin button
new UiObject(new UiSelector().text("admin")).click();
// set pwd text
new UiObject(new UiSelector().description("pwdEditText")).setText("admin");
// click login button
new UiObject(new UiSelector().description("loginButton")).click();
I think you might also find very useful to write tests in Espresso. I think it's much more fitted for this purpose. uiatomator would be better to get permisson or notifications or screen lock and it works like charm with Espresso. Both are developed by Google:
Check this site to learn more about them: https://google.github.io/android-testing-support-library/
Checking EditText with Espresso: Updating an EditText with Espresso
Hope it help
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With