How to test OTP verification with Appium.
I want to do OTP verification by appium can any one help me?.
Using Appium you can automate and control your app but there are certain limitations You need to understand the process of generating OTP. Whenever you do some transaction OTP will get generated and send to your Mobile device. So you can automate the process to perform such transaction. But after that to enter OTP which is in your Inbox you need to open your Inbox, Find the Message, Extract the OTP, Enter it. This is very complex process to automate using Appium.
I think the better alternative is to Set one fix OTP number for testing purpose instead of requesting OTP Real time.
You can switch between apps in Android. On sending OTP using your app, switch to android default message app and read OTP and then switch back to your test app.
driver.startActivity(AppPackageName, AppActivityName);
The above call can be used to switch between different app. Replace AppPackageName and AppActivityName with your test app package name / activity name and android default message app name respectively.
You can automate OTP validation from Appium in two ways.
By opening messages application in android and reading OTP from there.
By opening notifications and read OTP.
To open messages application we need to open the app using below code:
driver.startActivity(AppPackageName, AppActivityName);
To Read OTP from notification pane we can open notification pane using below code:
driver.openNotifications()
Now you can inspect OTP text element and read the text. For example, if your OTP text is
Your OTP is 3357
You will get otp as below:
string otp = driver.findElementByXpath("//*[contains(#text,"Your OTP is")]").getText().split(" is")[1]
Above code will return OTP into the string variable. Now you can use below code to come back to the application.
driver.navigate().back();
This solution is for Android only.
yes, i think you are right but, i need to login before use the app and login page have a OTP verification thats why i need to check OTP.
i can build a app with out OTP for testing but can not do every time because i have to test production build which are going to far user and in this build i can not hide OTP verification.
For OTP verification you can use Android messenger. Download android messenger apk, create test scrips to launch and read message using this app.
I don't know how to do for iOS, Can any one suggest here how to do for iOS based application.
Thanks,
Sadik
Related
I have a use case where I need each user to be identified by a phone number, this is because my shops will need to call the users who request an order , I have followed the documentation and all the github repo with the code
Actually the code worked, and sended to me the sms to verify and all worked just fine !
Now, before release, I have just plugged another phone, requested the code to verify and the code never arrived !
I just tried in another phone with another number and also the verification code has never reached that phone either.
But I actually verified a phone number with the actual code and it works, so, why is the code not reaching my users phone ?
My use case needs this feature and if this is on Firebase side I will need to move to another service
Any suggestions ?
For testing you can use the verification code you added with the test phone number on the console.
Firebase Console Dashboard -> Authentication -> SignIn Method -> Phone -> Phone numbers for testing.
Sometimes, firebase don't need to send the otp for confirmation. it can automatically be done.
This method is called in two situations:
Instant verification: in some cases the phone number can be instantly verified without needing to send or enter a verification code.
Auto-retrieval: on some devices, Google Play services can automatically detect the incoming verification SMS and perform verification without user action. (This capability might be unavailable with some carriers.)
In either case, the user's phone number has been verified successfully, and you can use the PhoneAuthCredential object that's passed to the callback to sign in the user.
https://firebase.google.com/docs/auth/android/phone-auth#onverificationcompletedphoneauthcredential
Check out the docs for Firebase Phone Verification for Android : https://firebase.google.com/docs/auth/android/phone-auth?authuser=1#test-with-whitelisted-phone-numbers
I've implemented firebase phone authentication in my app and it's working fine when the user uses the app on the phone which the user receives the OTP on. I'm able to verify the OTP perfectly once I receive the OTP on my phone.
But, I just thought of another use case where a user might be using the app on the tablet and when he/she has to verify their mobile number in order to continue using the app. So they enter their mobile number on the tablet and receive the OTP on their phone. In this case, when they enter the OTP they received on their phone in the tablet, I'm not able to verify the OTP since the onVerificationCompleted() method holding null in place of the value.
Can anyone help handle this case gracefully?
Thank you.
In that case, you have to use the onCodeSent and onCodeAutoRetrievalTimeOut callbacks and ask the use to enter the code and initialize a PhoneAuthCredential to complete sign in.
I am developing an app wherein the users use either email and phone to perform registration.
Users can enter their email or phone for log in, I want the same OTP to be sent to mobile and email simultaneously. Please Help!
If you want to work only with Firebase Authentication, then there is not any suitable solution that meets your requirement.
Some limitations you can find with Firebase are Firebase Authentication Limits and Phone number sign-in limits.
However the alternative solution is using third-party SMS gateway. through with you can send OTP to phone number as well as to email also simultaneously.
Lets assume you already have mechanism to generate OTP and verify OTP from android app.
Now the problem is how to send OTP to the user's email.
One of solution is using MailGun service to send email from your backend.
Also, if you want to templating your email, you can use library called handlebar
I'm using firebase for phone number verification via sms.
This works nice when the verification is automatically done (SMS is sent and automatically app reads it and does the operations related to that the phone number has been verified).
But I'm now trying to make the verification with the code that is sent in this sms, as maybe not every user is going to be able to automatically read the sms message.
I thougt that the function PhoneAuthProvider.getInstance().verifyPhoneNumber would be overloaded with some option that would allow to send that code and perform the verification, but unless I'm missing something there doesn't seem to be a way with it.
On the other hamd I know this way of performing a verification via sent code, but it does require to sign in firebase, and I don't want that unless there's no another way, all that should happen is that the user sends its phone number along with the code and if correct, firebase sends something that is understood by the app as that the verification has been correct (no signing in anywhere).
Is there a way to do what I'm mentioning?
I have a similar problem with my new app released in Google Play Store. I just don't receive de sms code.
I mention that when I tested the app in debug mode and release mode it worked perfectly fine. The problem occurs when I download the app from Play Store.
Maybe you are right and the problem is that i didn't login user, because at this moment rules in Firebase Database are read and write == true.
I am using Firebase Phone Auth for my app in both iOS and Android. When I receive OTP message I noticed there is a difference in the received messages on both iOS and Android.
The iOS OTP Message Reads xxxxxx is your verification code for myAppName.firebaseapp.com. (authorised domain name).
Whereas Android OTP Message Reads xxxxxx is your verification code.
In the firebase console under the Authentication section and under Templates tab selecting the SMS reveals a different template. %LOGIN_CODE% is your verification code for %APP_NAME%.
I need to show the OTP message as xxxxxx is your verification code for My App Name. in both iOS and Android.
I have changed the projects name and Public-facing name in project settings too. But no change in the messages.
Is this a Bug or am i missing something ?
I have files a bug report to the support team and got response from them. The mail response is as follows
"Is your app still in the development stage and hasn't yet in AppStore/ PlayStore? If so, this behavior of having no app name in the verification code is working as intended. It will only have an app name after your app has been published to the App/Play Store. If it's released Android / iOS app, then we do have the application name in the SMS, and we get it from the AppStore / PlayStore (and website domain for Web).
Just an additional information, there might be a delay for the APP_NAME to appear once the app is published. The update may be delayed because of the propagation between the AppStore/PlayStore update and our server picking up the changes."
As my app is in development stage i am not getting the app name in the OTP Messages. Once the Apps are published to the app store and play store this will be resolved.
firebaser here
There is no way for you to change the message that is sent for the OTP. See:
How to change the sms verification template in firebase phone auth
Is there a way to customize the sms message sent by Firebase phone Authentication in Swift?
If you consider the difference a bug, you can file a bug report.
In addition to #Kautham Krishna's answer, for iOS, it is necessary to add the App ID & Team ID to app settings in the firebase console.