Capture OTP while Sign in/Sign up


#1

How to capture otp from android mobile during registration/login in a app


#2

Hi @nazneen,

Check out this post and video for a walkthrough on how to capture One Time Password (OTP):


#3

@Chris_Trevarthen Could you please help me with the same OTP reading when I try to sign in using android mobile app ?


#4

Hi @janani0515,

I haven’t worked with OTP testing, but if you are able to share screenshots or videos of the process, I might be able to help figure out how to inspect some elements.

– Chris


#5

Hi @Chris_Trevarthen,

As soon as I enter my login credentials, the OTP will get displayed as a notification. It will also be in my ‘Text Messages’ folder.
I need to read this otp from either notification or sms folder and enter it to login my application. There are several ways to do it for a web application but for a mobile app there are no procedures.

Please help me.
Refer attached images.


#6

Hi @janani0515,

Thanks for the screenshot, that helps me understand a bit better what you’re trying to do. I don’t think you’ll be able to access the notification popup message with Katalon Studio/Appium, but I think you might be able to switch to the Notifications application and read the latest notification to get the OTP code.

  1. Use Katalon Studio to Spy Mobile using an apk file that you have on your machine
  2. Trigger the OTP notification on your emulator or device
  3. In the emulator or device, switch to the Android Notifications app
  4. Capture the object for the corresponding notification message in the Notifications app - this is probably the latest one - name this something like “First Notification Item”
  5. Capture the text object for the notification that contains the OTP - name this something like “OTP Text”
  6. Save the text object in the Test Object repository
  7. Stop the spying process
  8. Open your test case
  9. Switch to the “Script” view of the test case
  10. After the spot in your test case that you trigger the OTP request and the notification appears, add a line for:
    Mobile.openNotifications()
    This should open the Android Notifications app programmatically
  11. Add code to tap the latest notification object, which should be something like:
    TestObject notification = findTestObject('Object Repository/First Notification Item')
    Mobile.tap(notification, 10)
    
    Where “First Notification Item” is what you named the captured first notification element when you were spying
  12. Add code to get the text of the OTP:
    TestObject otp = findTextObject('Object Repository/OTP Text')
    String otpText = Mobile.getText(otp, 10)
    
  13. You can then switch back to the main app using
    Mobile.closeNotifications()
  14. Use the OTP text you captured above and set it in to the password field in your app using Mobile.sendKeys() or Mobile.setText().

It’s a bit of a round-about process, but I think the concept should work for what you want to do.

Hope this helps,

Chris