Skip to main content

How to Automate OTP using Appium and Selenium Framework ?



Hello Everyone! Welcome back to another Fresh article of MODTECHSTUFF where you Learn Automation testing.
In this article, we will talk about Integrating the OTP SMS reading capability with your Selenium - Appium Framework that will surely help you out.


Automation testing


There can be three solutions to this problem.
Solution 1: Ask your development team to fix the OTP check process to any static value.
Solution 2: Ask your development team to provide you an API in which you can pass some parameter in response he can return you the OTP sent against that number. 
Solution 3: Design two Appium scripts one is two handle Websites and one is to handle the Android message box, so after sending OTP from the web execute the second script to read a message from the message box.
OTP is a 2-factor authentication mechanism that was build to avoid ROBOT / Automation SO you never find the solution direct solution for that.

What is Appium?

Appium is an open-source structure that permits you to lead automating testing of versatile applications on various stages like Android, iOS, and Windows. 
Local Mobile Applications that are composed utilizing iOS, Android or Windows SDKs 
Portable Web Applications that can be gotten to utilizing cell phone programs, for example, Safari, Chrome or the in-assembled local program applications for Android gadgets 
Half and half Mobile Applications that have a local wrapper around the web see 
Appium is a cross-stage testing structure that is adaptable, empowering you to compose the testing code against various stages, for example, iOS, Windows, and Android utilizing similar API. This implies you can utilize a similar code for iOS that you have composed for Android, sparing bunches of time and exertion. 
Appium, like that of Selenium, offers you to compose the test content in various programming langyage for eg Java, JavaScript, PHP, Ruby, Python, and C#.

How does Appium Work?

Appium permits you to collaborate with your application consequently, by utilizing the conduct of the different segments, for example, button and content marks that are accessible in the UI of the application. 
It tends to be reused to compose and run tests over and again against the given application at different meetings.  

Android

Appium utilizes the UIAutomator structure (or Selendroid), which is intended for testing the Android UI for automating applications on Android gadgets. The bootstrap.jar document functions as a TCP server that sends the test order for following up on the Android gadget with the assistance of the UIAutomator or Selendroid system. 

Apple IOS

Like that of Android gadgets, Appium utilizes the JSON wire convention for iOS devices too. Here, it utilizes Apple's UIAutomation API to collaborate with the UI components to automate the applications on iOS gadgets. The bootstrap.js document fills in as a TCP server that sends the test order for following up on the iOS gadget with the assistance of Apple's UIAutomation API structure.

How to Automate OTP?

Day by day we face difficulties when automating web UI and versatile applications. The job of a specialist is to conquer these difficulties in one way or another. Today in this article I will show how we can peruse the OTP SMS from perusing devices connected to your PC and proceeding with the automating of validation situation. 
The First Step is we have to add the Appium Dependency to our Selenium Framework.
Here is the code
<dependency>
    <groupId>io.appium</groupId>
    <artifactId>java-client</artifactId>
    <version>7.0.0</version>
</dependency>
Next step is to create a JSON data file with all the capability details below

{
    "BROWSER_NAME": "Android",
  "deviceName": "JYNBB18B17155625",
  "platformName":"Android",
"appPackage": "com.android.mms",
"appActivity": "com.android.mms.ui.ConversationList"
}

After that add the following commands to the test scenario which will read the first message from your device.
package TestBankPkg;
import org.testng.annotations.AfterClass;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import org.testng.annotations.Test;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;

import Utility.JSONReader;
import Utility.DriverStart;
import org.json.simple.parser.ParseException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.*;



public class SMSRead {

DriverStart drv;
WebDriver driver;



@BeforeTest
public void setUp() throws FileNotFoundException, IOException, ParseException{

JSONReader JSONRead = new JSONReader();
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("BROWSER_NAME", JSONRead.ReadJSONFile("BROWSER_NAME", ".\\Data\\wsData.json"));

capabilities.setCapability("deviceName",JSONRead.ReadJSONFile("deviceName", ".\\Data\\wsData.json"));
capabilities.setCapability("platformName",JSONRead.ReadJSONFile("platformName", ".\\Data\\wsData.json"));
capabilities.setCapability("appPackage", JSONRead.ReadJSONFile("appPackage", ".\\Data\\wsData.json"));
capabilities.setCapability("appActivity", JSONRead.ReadJSONFile("appActivity", ".\\Data\\wsData.json"));
   
driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
}

@Test
public void ReadOTP() throws Exception {



     driver.findElement(By.id("com.android.mms:id/subject")).click();
    

      System.out.println( driver.findElement(By.id("com.android.mms:id/text_view")).getText());
 
}

@AfterClass
public void teardown(){
//close the app
driver.quit();
}



If you like this article, do share it & For any query send me a message here. I will ready to help(In FREE).





Author:: HAROON

For more details please visit  MODTECHSTUFF

FOLLOW ME @

      



Comments

Post a Comment

Donate Us to Keep this site Alive! With PayPal

Popular posts from this blog

How to create my own blog| A complete beginner's guide| Updated(May 2020)

Hello Everyone! Welcome back to MODTECHST UFF.  In this blog, we will talk about How to create your own blog and how to earn from the blog. This guide will provide each and every possible detail about blogging. I realize that beginning a blog can appear to be overpowering and scary. This free guide is tied in with blogging for amateurs and will show you how to be a blogger with simply the most essential PC aptitudes. So whether you're a student or professional, you can make your own blog in just 1 hour!!! I am not afraid to concede that when I was first figuring out how to manufacture a blog I committed a huge amount of errors. You can profit by overtime of my experience so you don't repeat these equivalent mix-ups when you make your own blog. I made this free guide with the goal that anybody can figure out how to blog rapidly and without any problem. What's more, on the off chance that you stall out anytime if you don't mind send me a message and I will give a magnific

Write data from Excel file and Capture ScreenShot Using Selenium WebDriver

File Read and Write is a basic piece of any product or software process. We as often as possible make a document, open it, and update something or erase it in our Computers. The same is the situation with Selenium Automation. We need a procedure to control records with Selenium.  Java gives us various classes to File Manipulation with Selenium. In this article, we will figure out how might we Read Data on Excel documents with the assistance of the Java and Apache POI library. Do check my Latest video on Open Source Behavior-Driven Development (BDD) Tools and Subscribe my Channel for Latest Updates!!! Here is the link:::  https://youtu.be/t7EwU8LWfr0 Installing JAVA in your System. TestNG requires Java which means you should download and install Java on your system. In my previous blog, I have shown how to install JAVA on your computer in detail. Here is the link   https://modtechstuff.blogspot.com/2020/05/how-to-start-automation-using-selenium.html Eclipse Installation Eclipse IDE is o

Ad

Enter your email address:

Delivered by FeedBurner