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).
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 theR.id
part, so forR.id.edit_text_email
inputedit_text_email
Enter password resource
: same as above, but for password. Again, skip theR.id
, eg.edit_text_password
Enter username
: username or email you'd use for testing, eg.test@mywebsite.com
Enter password
: password you'd use for testing, egtestTEST123
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 theTest account credentials
. Ie. to be able to useSign 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.
For a Robo test (which does power the pre-launch report on the Play Store Developer Console), bypassing sign-in is one of the known limitations, which you can read about at the bottom of the documentation. However, there is a recent capability of Robo that can automatically use a Google account to login. All devices in Test Lab now has a Google account associated with them that will be used whenever a Google account is required to log in.
If you want to test an app that normally requires some other kind of login, you are correct in guessing that you would need to provide an alternative APK configured to not require login. It's not very convenient to do this, especially for apps being tested in alpha/beta. One thing you could try, in order to programmatically decide whether or not to require login, could be to consult a special system property ("firebase.test.lab") that will be set on Test Lab devices. You can read about that here. That is normally used in instrumentation tests, but it may work for Robo tests as well (I haven't tried, and I'll have to confirm this with the team later).