Search code examples
androidauthenticationautomated-testsgoogle-smartlockpasswordsfirebase-test-lab

How to provide login credentials to an automated android test?


I'm looking for a way to "provide a login" to my app so an automated test "is logged in" and can test the entire app. Currently it's of course blocked by the login-screen.

Because I'm using SmartLock for Passwords, this might be a chance to provide some credentials for the test - but I don't know how.


Is there some best-practice to provide credentials to / skip the login during a test? I could think of a special buildType / -flavor which is mocking the login but this way it can't be used to test a release build.

It would be great when I could test a final release build which can be uploaded to the store when the test succeeds. This way, I could use the embedded pre-launch-reports in the PlayStore as well (which would be really nice).


Solution

  • Go to Firebase Console->Test Lab->Select Dimensions, then click

    Show Advanced Options

    and look for

    Test account credentials (Optional)

    Then fill in as follows:

    Enter username resource : name of your username (email) EditText resource, skipping the R.id part, so for R.id.edit_text_email input edit_text_email

    Enter password resource : same as above, but for password. Again, skip the R.id, eg. edit_text_password

    Enter username : username or email you'd use for testing, eg. [email protected]

    Enter password : password you'd use for testing, eg testTEST123


    It seems Robo (the test bot) types in the credentials as soon as it finds the EditTexts specified with the ID resources, yet may take a little while figuring out which button to click to log in if you have other auth options such as 'Sign in with Google' and 'Continue with Facebook'. After a few minutes of attempts in other services it seems to luckily press the right button to continue through the authentication using the credentials you provide.

    At the time of writing this, there is no way to script a login behaviour and as such suggest which buttons to use for authentication, so just use the method above and give Robo enough test time (Test timeout in the Console) in case it sticks around without clicking the right button for a while.

    If you provide Sign in With Google button for Robo to use its own Google credentials to sign in, remember that this will not work if you provide the Test account credentials. Ie. to be able to use Sign in with Google make sure your haven't provided any other login credentials, otherwise it will fail.


    Note: You can make Robo fill in other EditText fields using a similar method - check the Test Lab documentation for more info.