How to automate OTP number in Selenium and API || Using Twilio SMS APIs

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this conference will now be recorded hey guys this is Lavinia welcome back to marine or a mission ops sole for this particular video I have come up with the scenario where we have to use OTP right spatially when we do some registration then we have to do some login some authentication factors whenever we are doing any transactions through maybe through some wallet or some credit card or debit card OTP is coming okay either on email ID or maybe on SMS through your SMS on your phone number so the OTP is important so how will you get to know that ODB which which code it is coming what is the value of that OTP penis for TB is always dynamic in nature it's not like same OTP we can use it and this is kind of blocking that look I mean blocking your testing that how can we get the OTP so if sport it is coming in email ID maybe it's for some email API we can do that but what DP let's see it's coming on your on your phone number especially weather let's see in mobile based applications where of OTP is coming on the phone number in that case how will you automate let's see if you are doing some transition through Amazon pay or through some Google pay or maybe some Paytm or any kind of wallet code TV is always coming on your phone number or let's your banking transition is happening Bank will always send one OTP number or six digit of four-digit OTP number okay to your phone number so how do you read the data how do you relate some SMS because as such we don't have anything and selenium can not support that so to automate that thing I have I have found out or a really good solution about that so in the previous company somewhere we were using some authentication point of view and we were using some one application that is third-party application Twilio so this is what I'm talking about actually so share this link to your computers won't do okay when you're a PA you open the studio REST API so what exactly these guys they do things they say that okay we will provide some APs and you can create your own forth number you can generate some fake number or you can generate some you know some sample our phone numbers and you can use that phone number in your script okay for your test cases and then we will okay of this user application we'll send the data will send the OTP number to that particular phone number so from that particular phone number SMS is coming and we will give you some ApS to read the data from those SMS so how to do that so they have very good a documentation is available so what exactly I am trying to say guys what exactly we will do in this particular process so we will write a script over here so let's see this is my script and this particular script I'll write muscling info let's say launch some website let's the amazon.com we will enter the username you will enter the password we will enter the phone number over here and this particular phone number how exactly we will get we will not use our person phone number what exactly you will do on twin you're calm you will create one fake phone number or sample phone number just for your this is not a fake this is not a right word but this is just for your test automation point of your testing point of view and the same phone number whatever the phone number is there the same phone number we will enter over here so what will happen the moment we click on submit right the OTP will be generated and both tt will be given to this particular phone number right so OTP is available over here and then once the OTP is there then you will hit the APA that page is provided by Twilio dot-com and through the APA right through the some recipes are there through the APA we will get the only B number over here in our script right the moment we click on this continue button or submit button it will ask you that okay what is your OTP so same OTP we will enter over here so this is the thing guys we really do not know what is this Twilio a because this video API they they are paid a B they are not free but you can create some free accounts as well for trial point of view and and it's very very cheap hardly and it's less than one dollar are actually you guys can pay for it so what we need to do we need to go to there let's explore this video come in first you need to create you need to sign up right there so let me click on sign up and I will create my first name last name email ID password it's very simple so let's see I'm writing my sign up lobbyist automation email acne I'm giving let's see I have already created one email at disability system and using this Naveen animation 20 and gmail.com so that user registration we will do it on this particularly minute so you guys also follow the same thing and the password let's see I'm giving some password over Elizabeth and you accept the license agreement and okay and they start your free drive that means save the password over here ok so once this is done this time and say that okay hey verify your email id so I'll quickly go to my email ID this is a new email id guys I have created and you can see that verify your email id and we will come from the emulator so I quickly confirm the immunity and the moment I confirm confirmation will happen right and then it will ask you your original phone number so you just need to do that okay you are the right person so you just find your one phone number over here so you can write any random phone number so what I do I'll quickly write my phone number over here so just a second I'll do one thing this conference will now be recorded okay so guys I stopped the recording just because it's my phone number we're busy but so anyway so once you enter your audition phone number and it will send you one more indication code or ho TP number to your phone number but I'm not bother about that on TV this is just for your registration on Twilio calm so once this is done then you can simply it will ask you a couple of questions okay here do you write any code or something yes I write the code on which language what's a preferred language Java and I use Twilio is a student or hackathon project or Explorer to you so I just want the explode will you and what do you want to do first so let's see send or receive SMS and just so this is the basic thing I really want to do and once this is done what would happen race so it will give you a trial version so and in the trial balance was rate will give you around fifteen dollars you can use this fifteen dollars and some trial version will be there after let's say for 14 days or something like this so it will give you two important things what is your account s ID can you see that account s ID that means only and then this is your authentication token also you click on show it will give you your dedication token now you can create a trial number you can create your own number so let's see I want to create a trial number let's click on create a trial number and this is the trial number of days you will get it 3 3 4 3 7 3 4 0 1 9 now this is your twill your phone number your first tween your phone number if you don't like this you can search for another number also and like this what exactly you can do you can do a voice SMS and MMS you can incoming call and outgoing calls also you will do it and 3 3 4 3 7 3 fours you know one line is that you number and the same number I'll be using in my test script for my scenario right so let's see I'll prefer this number click on this number choose this number and now this number will be confirmed so your new phone number is this done and what exactly it will do it will say that ok yes this is the number that I have this is my number and this is my balance so for every SMS it takes around 0.1 cent okay which is quite less than so you guys can use it and then we can okay you can we can write our test cases with this particular trial number so I'll tell you what exactly other things are there and if you go to their talks so you just click on API Doc's right click on it and open a new tab and they have given lot of API documentation also that what kind of you know for let's see for SMS API you just click on it until your messaging API is are available so if you are interested you can look into their you know ApS as well in which language let's yell through the Java language so Hal you go to the Java and it will give you some C and you see that some sample examples also some sample code also it will generate so what exactly I have done I did one TOC and it's quite working fine and then I have taken some such kind of examples from their website and these code I have taken and then I am invited in my own code and then and using it and then it's absolutely working by in fact you can see the right-hand side it supports php.net in Java also it supports Python also it supports and complete API overview these guys have given Ruby JavaScript also these days have created so all the APA documentation is literally over here it's with different languages right so you we don't need to cover each and everything over here we just need to cover what kind of a piece we can use what end of you know read the messages or create the message SC you can create the messages this is your two number okay and this is your phone number what kind of message you want to send let's say I want to send where is Wallace or some number I will do okay awesome message I want to do this is my message and this is my two number and this is my formal from number so like this also you can do that and you can actually read the messages also you can read the SMS also and from there SMS you can read the OTP number and then you guys can complete it the scenario so let's do it so what I have been I have put this particular Amazon dot in so what exactly do people go to Amazon dot you go to this particular page let's see hello sign in and click on start here and here that is you know that this number is there can you see that your name I am writing my name is Naveen test and my number then this guy has created the number for the USA and USA code is plus one so I'll go to United States plus one and what is the number that I have okay right that particular number what is the number Oh Julia dot-com we have generated so I think we have generated this particle of us it's the same number I'll be using over here ok and then what exactly I'll do that you don't need to write the email id and create some password on Amazon that's interacting some password and then I click on continue ok and the moment I click on continue it is asking for what is your OTP right now this is us in are you p1 is blocked what is my OTP number now the OTB number is coming what are the number that we have given now see I'll show you the thing ok you go to your account whatever the count on twitter.com that we have created will go to uses ok means you go to the spot a great app uses and on uses it will give you this is my first failure project you go over there and then we just see that some programmable SMS I got one SMS inbound means incoming SMS outbound means Decimus be ascending from this particular umber an inbound means yes we got some SMS you click on it and you can see SMS inbound and there we will should see that particular message somewhere you should get an SMS on this number check for number number this local phone number someday we should get decimals one second let me check it again okay maybe the OTP is green triggered or not let me check it once again first affected it takes some time to get the OTP - so let's go to uses once again okay so it's saying that phone number you have created programmable SMS also it's they're inbound SMS and the standard end out s Lewis what exactly this guy's saying okay so yeah you can see that one it is got created from we have got one new message from this particular umber and this is Amazon number and to this particular mer and this is our number and one segment means one message is there and we click on it and here you will see the details can you see that this is my password this is my body be is your Amazon OTP OTP is fun potential for security reasons do not share this or to be with anyone and now I'll and same or to be you guys can use it over here okay like this and then create your own and the sort of how you can connect to it the question here is how do you read this particular mu TP from this particular do you not how do you read Decimus this particular and this is fine a method SMS body right leg so and this is the message details are available these are the health messages message details are available from which number its come it's come message is coming and decision number so this number is from Amazon and this is my own number that have created through to you so obviously are not coming through selenium over here and read this particular through selenium ex-father or something no Twilio Gong it will give you some messaging EPS and then through those days we will read this particular body and from the body we will capture this particular entire string and from this pottery string we will capture this number and then and they're over there right here so let's do it how exactly we will do it in programming so I have only created one project OTP handles this is the maven project and I have already added my selenium decoding as well as spawning ratio webdriver that will be run forever manage unlikely and to use a Twilio api guys what we have to do we have to use our Twilio twill your dependency also we have to add so these guys there is anywhere exactly to your dependency so here you can see that this is the trivial dependency it's available on the documentation we just copy this ok the popular XML file dependency and you just need to save it so the latest version of is this 7.4 2.0 you can in fact find it on on maven also that will you not SDK and if you are using the rider you can use this particular gradual or dependency also if you are using the riddle project ok ok so once this is done then I will close my format xml file and quickly create under a source in in java and quickly create one package the cheaper package name is my little package and under this potato util package what exactly I'm gonna do I'm gonna create a class and let's see I create go TP handle ok I'll write something like this Amazon OTP handle select the main method and click on finish so inside the main method we will write our code and the basic code is I have already written so first what exactly we have to do first okay you need two things over here the first thing is you need to go to your account so I'll just come back go back to your account on pure calm ok and you go to a dashboard or from your dashboard you need two things this is your account s ID okay guys n authentication token so these two strings you need it ok so quickly what I'll do at the class level I will create public static final spring let's do this is my account underscore s ib is equal to this right and then I will create one more string variable that is for authentication token so that is my art token is equal to this is math integration token so you guys can create the pump and on the basis of that in this step well give you your own s ID or your own authentication token so you just copy paste your token over here right and once these things are done what you need to do is the first thing you need to write you prevent the selenium pool first right so how to write it so before I get the stadium code okay let's write in important to do we need to write the driver driver equal to new program so in I am perfectly right on driver driver okay import these two things and then I will be using one is a ratio so the driver manager dot chromedriver dot setup okay and then driver dot you get method and then we will launch amazon dotted so s GDP as double double double dot amazon gone then right let's see this guy is working or not still here so quickly I check I'm not using to you right now cement okay so maybe some problem with this bonding right here I will do one two let me delete this I'll set up the path directly so the paths I am already coffee based on where in my notepad file is still slow here okay so this is the this is the basic thing launching the Google Chrome setting the Google Chrome driver dot exe file path and then finally Amazon bottom then I will be using that you driver dot only using for typing let's use driver dot manager of timeout or implicitly wait it was Italy wait for it same giving 30 seconds and the unit dot seconds okay so let's see this is my driver got a nice rise with this particular interestedly wait time out and then what we have to do so first we will go to Amazon dot [Music] you will go to amazon.com so the first scenario is that we have to click on it and you have to click on start here so we have to click on this ok whatever the this element is there so let me quickly so this code guys I have already written so let's not waste our time so I'll tell you what exactly I am doing over here right so unnecessary thusly input we can save our time so let's say this is the code I have already written some it because I was doing some to you see so this phone it's already written see this is a goal so I quickly explain you so this guy is clicking on this accounts and this right so you just click on it and if you click on start here right can you see that it start here and when you click on start here it will come over there on this particular page so this page is important to me because here we have to enter the mobile number right and the name and the password same thing I'm doing over here and clicking on start here and then finally am entering let's say this is my customer name so this is your your link if you inspect this type I am using the same idea you can see that a customer name and using the same thing at first mi name dot sin is nicely I'm writing the mean test OTP is my customer or my name then we have to select one it's a USA number so you have to select this bed so the USA United States of America plus one we need to select right because we have generated the number but USA right so for that one exactly have done first you to click on it so you have to click on it and then from this particular entire list what exactly have done I get the Xbox directly for United States so this is the expert you can see that you will roll application so you can quickly I'll show you how exactly I did it to the expert let's see let me give expert for this well right at the states and you can see that if all the Li is there are two many countries are there in this particular top down you can see everything is coming under this particular ul right and the role is application so I'll do one thing and with need to be 8 they're all equal to application of the V value so I get my experts we will my place at the rate Rho is equal to right and under that particular there are number of list elements are available so I will do one thing how many lists to 23 list on here and from 223 list if you open a specific list we have to go to a it means we both with a and under that a you give me OK the country name is United States of America so let's see this is the way United States plus one so I copy this and you gain then where the text is equal to this so it is actually pointing to the sky directly United States so this is the expunge you guys can use it and the same expert I have used over here you can see that right and then simply dot click so it will click on United States of America the plus one right so let me click on this particular plus one and then I have to enter the mobile number the mobile number is whatever the number that you have generated right so what is the number that we have generated with us on TV will be sent to this number so my number is this so you ignore plus one plus one it is the country code so the actual number is three three four like this so this is my number right and what is the password you want to enter my password I see test automation at the rate 1 2 3 over here this is the email ID I'm not entering because this is all option this is the password 1 2 3 and click on continue button so it will click on this particular and digging button right so after that the moment it gets on continue button that same writing some mobile number something like this okay and then when you click on continue [Music] something like this say something audience better okay now it will ask you for your OTP numbers now how will you get the ODB know that now we have to use race video ap so then here this is fine it will click on continue button right and then get the code to be using we knew it means so to get the ODB guys so what exactly I have found two important methods from their particular site so these two important methods I will give it to you we don't need to learn if you really want to use you can use it so these are the two will generate matters actually I am somewhere modified and then used it so let's say this is the first method is this get message and get message is internally calling get messages over here so let me input one by one and all these things are coming from tree so you can import this video and it's using Java buddy 1.8 and we'll make sure that okay we are using KR e 1.8 because we are using the screen and lambda expression so we are not bothered about all these things so and this is the number which number this is a number but here you guys you have to give plus 1 plus 1 and the number like this so what exactly it will do it will go to that particular Twilio emails to that particular account with this number it will get the body and from the Dory whatever the first 40 be is there right case whatever the first one TV number is there it will capture and it will return a string ok it will give you ask so what we need to do we just need me call this particular method over here so how will you call this method the get message right so let's making a static so that you can call it directly okay so I will call this particular get message over here okay you get message and this particular get message what exactly it will do it will give you one string and let's see this spring SMS body is equal to this so whatever the SMS body is there and we will print it on the consumer that SMS body let's see what is the SMS body right lace is whatever SMS body is coming to this particular number it was we have already filled the form and we have already click on continue right it means by the time Emma's one has send SMS right in the form of OTP so let's see it is working or not so we should get the whatever the SMS is coming okay from the M from the Amazon and we will see that the OTP is there or not so let's run as java application Aleksey so see it is launching amazon.com you can see that yes somewhere oops authentication failed account s ID please call palpable yes we don't think we have missed what we have to do we have to use before polling we have to use Twilio dot one month as their dice init method is there and here we have to pass your authentication s ID account s ID not indication because obviously otherwise it will not authorize so this next ID an authentication token you will get it from your dashboard okay so this is the first method page you have to use it that's why it's giving you an error you can see that please called Twilio init method right now let's all read again so let's run it again let's see hopefully it will work fine the paint is still loading okay okay so once the page is fully loaded they're moving it will click on okay let's terminate it let's let's run it again some problem with Amazon okay not clicking on it entering the OTP oh sorry entering the phone number and by the time you can see that OTP has been sent and we have only caught the arrow tip you see that what do you think about it till here guys if you like this particular concept please put a comment right away okay pause the video stop the video right away and then put a comment did you like this solution or not see this is so amazingly good we got a road to be now this is the exact message we get it right this is your Amazon OTP what it is confidential for security reason no do not share this whole TV with info and we can check the same message with this same OTP on their dashboards so we'll go to their dashboard dashboard is this we will go to the uses right and quickly we will go to the sister project programmable SMS go to the SMS inbound SMS standard in bomb SMS to sms's are there which is costing us around 15 cents so that's not an issue use scroll down and you can see that 15 files you can see that we have got one SMS same SMS and see that six nine three seven double six is the OTP number we can see in back and so on also six nine three seven double six Israel exact same message guys we are ready so this website is not creating video is not creating any message message is coming from Amazon right then whenever we do registration on Amazon we get this message right same thing you can do the same message from ATM for sweetie or for any other account or Amazon or Walmart or any other bonnet or you debit card SMS is coming over here we just need to give your okay the current okey Twilio for the distant phone number that's it see and now icon this particular string and now that is so simple that I have to get the SMS I have to get the OTP from this but in the SMS body so I will be using some tricks over here one kind of break I can use I simply quick let's see I can use the lot of options I can use some string and occasions or I can use some a regular expression also so I'll do one thing I'll be using some regular expression so let's see this SMS body doctor I simple do but then replace all backtrack be using and then you can replace all that is my regular expression that this is for the using lot which is not coming under version mark 0 to 9 and like this and then replacement will happen with this one space right so I'm just trying to capture the essence and I will create one new spring over here that that is my OTP number is equal to this right and I will do one thing that which I got a whole degree I can either we can interact with number from that particular screen so I will run it again and let's see what is the OTB number so from that string and just I just want to capture the only minimal [Music] let's run it again with some time this well it is we can use proper weights over there but I don't want to waste my time on this thing let me run it again selenium skill later on we can improve right that is not important as of now yeah again it's coming on the stage one civilians yep that's coming so let's see yeah long the new OTP is this so we got the OTP can you see that six double zero one one point and this is what we want really this is what we want so I just capture this this is my string OTP know what I wanted that's so simple I go back to this guy and here I inspect this guy and I will be using this particular ID right and then driver dot find element by ID ID is this and dot sendkeys and whatever the send key is the OTP number that we have got same a string can be passing over them right or that's running let's see so if you're saying it's Amazon sometimes behaves awkwardly okay so it sent the OTB make sure we are getting yes things double zero one done for right and which should be able to see that yeah can you see them it actually entered six double zero underneath you right so let's run again I will show you once again so there are once let's run it again yeah so once we get see now this time you'll get we got nine eight nine to six men boot nine eight nine to six line that exact same OTB and reading lines over here as well as over here right and then that's it create your Amazon account your account should be created right so let me do it manually you just click on creator Amazon account my account what you created now see now I have logged in with this bed Naveen you see this is my account um and you see that my name is Rafe Naveen test automation what do you think about this video right this concept it's really I'm telling you and this is the free trial version you guys can practice once your trial version inspired you can generate and you number one city or you it's so low budget that on their dashboard or maybe on their documentation I read somewhere that it's very less see we have only trial trial balance is this I think there is no limitation for the number of days I guess so for every SMS they are charging around zero point one cent that's it so initially the balance was around 15 dollars now the balance is still I have my balance of fourteen point four seven like this okay and then you can upgrade the project also you can pay some amount I think one or two dollars per one subject and you can submit the bill in your company that's so low budget in Indian rupees it's around just 70 bucks 70 rupees that's it alright it's quite cheap so you guys can use it and then simply now it so easy to automate and it works like a charm base you can see that right so easily you can automate ODB's so no need to give you an audition number you just simply create one number tremble number or trial number see that's why this is called a trial number prime number you created over here what are the number you want to create and then use the same number in your estate make sure you are using your own account s ID n authentication token same thing you guys can do it in your company and these two messages are available on their particular site to read the messages I have already created alright and then this number you just need to pass that's it right nice but make sure you are not writing plus one over here while writing the phone number in in amazon.com because Amazon autumn plus one is already selected the USA plus one is already selected over here you just need to enter it Amazon will send the OTP and then that's it now you didn't apply the same formula in some other application that's it this is so amazingly good very nice so that's all for today I will send you the Squealer sorry Cleo link you guys can practice you can apply and you can give this particular solution and I upload this part of the project in my great repository is with I'll show you a link in my in the video description and if you really like this video this approach please share with others okay everywhere and share with your friends and colleagues so that they will also can get the benefit of out of this right guys so if you really like this video please put a comment over here and if you have any other approach to automate ot peace then please suggest maybe I can also learn something new for this okay so how exactly I got this solution this solution I got it from my previous two peers from me one week I was there and that guy he was losing for their own development he was a back-end developer there so he was using Twilio a place something like this for their back in generation o tvs they were using some OTV generator Davies so he suggested me that okay why don't you do this so I just explored and then I found it ok yes this is something really cool I can also use in mastering go this way so this is something really fun place you guys can implement in your framework in your company and then yes now there is no hurdle porosity okay so thank you so much for watching this video guys and please subscribe to the channel and very soon we will be reaching 100,000 subscribers very soon and thanks Beethoven support I'll see you in the next video and you bye bye
Info
Channel: Naveen AutomationLabs
Views: 36,522
Rating: undefined out of 5
Keywords: OTP, OTP number automation, Twilio API, SMS read using Selenium, OTP inn Selenium, Selenium, Authentication Number Automation in Selenium, Naveen AutomationLabs
Id: VLJIgOi7g2A
Channel Id: undefined
Length: 38min 43sec (2323 seconds)
Published: Sun Sep 29 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.