Simulating SMS Messages on Android
Our mobile devices are, well, mobile! We can send and incur various kinds of communication through them, include text/SMS message. Sometimes, SMS messages might be an integral part of the user experience of our own apps. This is certainly true for messaging apps themselves, but you could ideate a variety of other applications that tie into the SMS world. The case report we & # x27; ll look at today involves fleece into SMS messages in order to mechanically control a 2d factor of hallmark. What does this mean? It & # x27; s common recitation present when signing up for a service to confirm your phone figure as a way to verify your individuality for future requests. The flow for verifying your phone number is often a pain: you have to receive a text message with a code, navigate to your message app, then back to the app you & # x27; re trying to use to enter the code. Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script. Fortunately, Android apps can hook into the SMS system and read text messages for you, make the possibleness of mechanically verifying your phone number based on a codification received from an app & # x27; s backend SMS service. I have append just this kind of functionality toThe App-- -fake, of course! First, we sail to a screen that looks like this: And nothing happens until we get a text message that hold the appropriate code. Once we do, the position change: Of trend, since this is just a demo app, the confirmation code is statically hard-coded into the app itself, whereas in the real world it would be randomly generated and mail by a backend service. But this is outstanding for now. The question turn, how do we test this flow with Appium? How can we have Appium send a schoolbook message to the emulator so we can see the app verification conduct at work? The answer is to use the aptly-namedsendSMS command: And that & # x27; s really it. Simply furnish the two String parameters (& quot; from & quot; sound act and message). Well, there is one more necessary for this whole scenario to work: you have to be testing on emulator, since thesendSMScommand is not available for real devices. So to prove to Appium that we & # x27; re running an emulator and not a existent device, it & # x27; s currently required to send in theavd capability with the gens of the imitator you & # x27; re pass the trial on. If that aper is already up and running, Appium will simply use it as is. If it & # x27; s not up and running, then Appium will commence it for you. If you don & # x27; t furnish this capability, Appium will complain when you try to use thesendSMS bid that it only works on emulators. (Curious how you might test the same stream with a real gimmick? You could mix in something like theTwilio SMS APIto send actual SMS message to the phone number associated with your twist). So, with this new command at our disposal, we can now construct a simple test to verify the flowing we discourse: It & # x27; s reasonably fun to watch a simulated text substance show up on the emulator blind! Of course, if we wanted, we could also switch apps to the Messages app itself, and verify other belongings of the content that came through. Anyway, a full code sample involving the flow above is below (or you can check it outon GitHub: Lead, Content Marketing, HeadSpin Inc. Piali is a dynamic and results-driven Content Marketing Specialist with 8+ years of experience in crafting engaging narratives and marketing collateral across diverse manufacture. She excels in collaborating with cross-functional teams to develop innovative substance strategies and deliver compelling, reliable, and impactful content that resonates with quarry audiences and enhances brand authenticity. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts..png)



Simulating SMS Messages on Android
AI-Powered Key Takeaways
Check:


driver.sendSMS (`` 555-555-5555 '', `` Your substance here! ``);// assume we have a driver and a wait object all ready to go by this point // first set up the locators for the factor we use for verification By waiting = MobileBy.xpath (`` //android.widget.TextView [contains (@ text, 'Waiting to incur ')] ''); By verified = MobileBy.xpath (`` //android.widget.TextView [contains (@ schoolbook, 'verified ')] ''); // begin the stream by asserting we are in the 'waiting ' state wait.until (ExpectedConditions.presenceOfElementLocated (waiting)); // initiatory test an incorrect code and ensure that the waiting message is however present driver.sendSMS (`` 555-555-5555 '', `` Your codification is 654321 ''); driver.findElement (waiting); // now try the correct codification and assert that the verification substance is present driver.sendSMS (`` 555-555-5555 '', `` Your code is 123456 ''); wait.until (ExpectedConditions.presenceOfElementLocated (verified)); // if we get hither we have successfully checked the auto-verification functionalitymeaning io.appium.java_client.MobileBy; import io.appium.java_client.android.AndroidDriver; import java.io.IOException; import java.net.URL; import org.junit.Test; importation org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.openqa.selenium.By; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; @ RunWith (JUnit4.class) public category Edition011_Android_SMS {private String APP = `` https: //github.com/cloudgrey-io/the-app/releases/download/v1.3.0/TheApp-v1.3.0.apk ''; individual String AVD_NAME = `` emu27 ''; individual By verifyScreen = MobileBy.AccessibilityId (`` Verify Phone Number ''); individual By waiting = MobileBy.xpath (`` //android.widget.TextView [contains (@ schoolbook, 'Waiting to find ')] ''); individual By verified = MobileBy.xpath (`` //android.widget.TextView [contains (@ text, 'verified ')] ''); @ Test populace void testSMS () throws IOException {DesiredCapabilities capabilities = new DesiredCapabilities (); capabilities.setCapability (`` platformName '', `` Android ''); capabilities.setCapability (`` deviceName '', `` Android Emulator ''); capabilities.setCapability (`` automationName '', `` UiAutomator2 ''); capabilities.setCapability (`` avd '', AVD_NAME); capabilities.setCapability (`` app '', APP); // Open the app. AndroidDriver driver = new AndroidDriver (new URL (`` http: //localhost:4723/wd/hub ''), capabilities); WebDriverWait look = new WebDriverWait (driver, 5); try {wait.until (ExpectedConditions.presenceOfElementLocated (verifyScreen)) .click (); wait.until (ExpectedConditions.presenceOfElementLocated (waiting)); // first test an wrong code and see that the waiting message is still present driver.sendSMS (`` 555-555-5555 '', `` Your code is 654321 ''); driver.findElement (waiting); // now test the correct code and assert that the verification message is present driver.sendSMS (`` 555-555-5555 '', `` Your code is 123456 ''); wait.until (ExpectedConditions.presenceOfElementLocated (verified));} finally {driver.quit ();}}}Piali Mazumdar
Simulating SMS Messages on Android
4 Parts
-1280X720-Final-2.jpg)
Regression Intelligence hard-nosed guide for advanced users (Part 3)
-1280X720-Final-2.jpg)
Regression Intelligence practical guide for modern users (Part 4)
Discover how HeadSpin can empower your business with superior testing capabilities







Discover how HeadSpin can empower your business with superior testing potentiality
Discover how HeadSpin can authorise your concern with superior testing capability
Connet Now


Automate This With SUSA
Test Your App Autonomously







.png)












