Automate the OTP functionality

2,907 views
Skip to first unread message

Gaurav Sharma

unread,
Jun 9, 2016, 2:23:38 AM6/9/16
to Selenium Users
Hi All,

I am automating a scenario in which after the successful login, we get
the OTP page and we have to enter it. We get the OTP in the email.

I am required to enter the OTP only once and then I can login without OTP.

But when I am running the script using Selenium it is asking me to
enter the OTP everytime. Please suggest some method to automate such
scenario.

You help will be highly appreciated.

Thanks & Regards,
Gaurav Sharma

Purushotham Karimbedu

unread,
Jun 9, 2016, 3:40:58 AM6/9/16
to seleniu...@googlegroups.com
Hi Gaurav Sharma, 

Selenium not support this functionality. Better to you can use Thread.sleep(20L); and you can enter manually you received OTP and continue next written script.

---
Thanks & Regards,
Purushotham Karimbedu,
Drupal Developer and QA Engineer,
Phone no: 09000109120.



--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CAFJ8LYu71hd%3D4%3DTMU7AZJwigES1yBFnESMVPDxEy3YJQ_-t3Gg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Gaurav Sharma

unread,
Jun 10, 2016, 5:45:05 AM6/10/16
to Selenium Users
Thank You Purushottam.

But entering the OTP would not work for large regression suit.
> https://groups.google.com/d/msgid/selenium-users/CAB9YC5NhBOzLtXFCnr2Dj4viaTp7V8UdLzZWqFUN-OFiOs9PSQ%40mail.gmail.com.

Aniket Gadre

unread,
Jun 10, 2016, 5:56:29 AM6/10/16
to seleniu...@googlegroups.com

Entering OTP has nothing to do with selenium supporting it. Our application has api exposed only to internal users which can help you get OTP for automation purpose.

It seems for your application , when you enter OTP, a cookie is set which knows you have entered OTP before.

Because selenium starts a fresh instance of browser everytime, you are being prompted to enter OTP everytime

Sent from Android

⇜Krishnan Mahadevan⇝

unread,
Jun 10, 2016, 5:59:10 AM6/10/16
to Selenium Users
Gaurav,
Am guessing that once the OTP is keyed in your website basically drops in some cookie into the machine which identifies the machine as a "known/trusted" machine and that is why in your manual flow the second attempt to login doesnt ask for an OTP. But since Selenium always by default starts with a clean slate [ no previous sessions/cookies etc are remembered by it], your website basically assumes that each login is a first login.

So you have two options.
You can try creating a firefox profile, spawn firefox using that profile, then go through with your flow, causing firefox to dump the cookie into the profile folder in the sqllite file (see here ), the cookie that you need is now persisted into your file system.

Now you begin your automation by having firefox refer to the profile that you created above and wherein the cookie was saved as well.

The caveat here is that you are now stuck with ONLY firefox for this test and you cannot toggle to Chrome/IE and try and run the same test.

The other option is basically always go through the OTP generation flow, and then use JavaMail API to read the mailbox to which the OTP was sent, parse the mail using JavaMail API and then use it to proceed further with your flow. This would be a much more browser agnostic solution which is guaranteed to work across all the browser flavors. 



Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

Reply all
Reply to author
Forward
0 new messages