Issue
If i try to create a new user with createUserWithEmailAndPassword(emai, password)
in an espresso test case by using the Firebase Emulator Suite nothing happens. The same code is working for the live Firebase instance. The log shows nothing.
I'm trying to use the Firebase Emulator Suite to test my app. The emulator started correctly. The logs shows:
┌─────────────────────────────────────────────────────────────┐
│ ✔ All emulators ready! It is now safe to connect your app. │
│ i View Emulator UI at http://localhost:4000 │
└─────────────────────────────────────────────────────────────┘
┌────────────────┬──────────────────────────────────┬─────────────────────────────────┐
│ Emulator │ Host:Port │ View in Emulator UI │
├────────────────┼──────────────────────────────────┼─────────────────────────────────┤
│ Authentication │ localhost:9099 │ http://localhost:4000/auth │
├────────────────┼──────────────────────────────────┼─────────────────────────────────┤
│ Functions │ localhost:5001 │ http://localhost:4000/functions │
├────────────────┼──────────────────────────────────┼─────────────────────────────────┤
│ Firestore │ localhost:8080 │ http://localhost:4000/firestore │
├────────────────┼──────────────────────────────────┼─────────────────────────────────┤
│ Database │ localhost:9000 │ http://localhost:4000/database │
├────────────────┼──────────────────────────────────┼─────────────────────────────────┤
│ Hosting │ Failed to initialize (see above) │ │
├────────────────┼──────────────────────────────────┼─────────────────────────────────┤
│ Pub/Sub │ localhost:8085 │ n/a │
└────────────────┴──────────────────────────────────┴─────────────────────────────────┘
Emulator Hub running at localhost:4400
Other reserved ports: 4500
And the emulator UI is working, too. I'm using the Firebase tools in Version 9.4.0
My espresso test code looks like:
@Test
fun registerAndSigningInWithVeryNewUser() {
val auth = Firebase.auth
auth.useEmulator("10.0.2.2", 9099) // like https://firebase.google.com/docs/emulator-suite/connect_auth#android_ios_and_web_sdks
// sign out at first to ensure that accidentally no other user is logged in
auth.signOut()
// and now creating new user
auth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener { task ->
if (task.isSuccessful) {
// Sign in success, update UI with the signed-in user's information
Log.d(TAG, "registerAndSigningInWithVeryNewUser: creating new user success")
val user = auth.currentUser
} else {
// If sign in fails
Log.w(TAG, "registerAndSigningInWithVeryNewUser: creating new user failure", task.exception)
assert(false)
}
}
Thread.sleep(10000)
val user = auth.currentUser
Log.d(TAG, "registerAndSigningInWithVeryNewUser: User = $user")
}
I thought the reason was the async function call, though I added the ugly Thread.sleep(10000)
statement. But no effect.
The same happens (nothing), if I create the user by hand in the emulator UI and trying to sign in with signInWithEmailAndPassword(email, password)
Any ideas?
Solution
The problem was, that I tried to run the test cases from a real hardware device. From within a virtual device it works.
But be aware to allow cleartext traffic in the network security configuration (https://developer.android.com/training/articles/security-config#CleartextTrafficPermitted) if you test on Android 9.0 (API level 28) or above.
Answered By - Manuel Siebeneicher
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.