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.
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).
Thanks for delivering a good stuff, Explanation is good, Nice Article.
ReplyDeletesoftware testing training in chennai