how to read sms while testing in appium or selenium - appium

While testing of Android and iOS app. This is a Provisioning Screen of my app, A OTP Usecase comes up which stops further testing of App.
Usecase is.
When user enters the mobile number in app's starting page where instruction was . After tap on send button a another text box for OTP option comes up on app's screen. Upto this point, it is possible to record/playback. But after this, we stops our process.
Because this usecase is not possible to automate our app for further processings.
Here, OTP comes via SMS and for verification purpose user needs to enter the OTP(one time passcode) which comes via SMS.
So, my complication is ...How to check OTP from sms app of device, and return back to testing app and enter the verification code into it. this step validate the user and app appears for user.
My query is... How can i test this use case using automation?
Please help me because this blocks my complete further testings.

I think we cannot navigate from one application to another application with a single test as we are passing capabilities of test application only and we cannot work with another application.
However a workaround you can try is:
1. With first test, send the OTP from test application.
2. With second test, get the OTP copied to your clipboard from message box(you can get the application package/activity using any of the open source applications in android).
3. With third test, Paste/enter that OTP in your application.
Hope this will help!

Related

Is it possible to automate two apps at the same time in iOS?

We have this scenario:
Execute the script in app1, in certain step app1 sends us a SMS with a URL, app1 is expecting a validation code in a textfield
We have to open SMS app to verify if SMS exists, this SMS has a URL and when we click on it, it sends us to app1 again but automatically the validation code is written in the textfield.
then, continue with the script.
is it possible to do this?
what do we need to make it?
Thanks.
For iOS you can bring up the SMS app and do whatever you like within the app. For example, you could open SMS app, then open the latest message and then click (or copy) the link.
I use ruby. I use methods based on XCUITest driver (that Noyo linked already)
Methods that can be used are the following:
Method for launching any app installed on device:
def launch_system_app(bundle_id)
#driver.execute_script('mobile: launchApp', {'bundleId': "#{bundle_id}"});
end
Method for terminating the launched app:
def terminate_system_app(bundle_id)
#driver.execute_script('mobile: terminateApp', {'bundleId': "#{bundle_id}"});
end
Method for copying given string to iOS device clipboard:
def set_pasteboard(content)
#driver.set_clipboard(content: content)
end
Call using Messages app bundle id:
launch_system_app("com.apple.MobileSMS")
terminate_system_app("com.apple.MobileSMS")
Yes, As per your scenario you have to launch the messages(call it as app2) application in the middle of execution of script in app1. You can open the app2 by using below code.
driver.startActivity(app2PackageName, app2ActivityName);
Now app2 will be opened you can click on the link in app2 which will open app1 and you can access the elements in app1.
According to this article, it's possible if you're using Appium's XCUITest driver.
Please note it only supports iOS versions 9.3 and above.
You can find a few other application management commands that might interest you at the official docs.

Mobile Number Verification with Missed Call in iOS

I don't know this question is a good question or dumb question, but I research on SO from last 3 days, only this link I am able to see. And in this link I am not getting any solution for my Issue.
My question is How to verify my mobile number with a missed call. I got from some answer, have to use "Dial2Verify" API. But no one can said "How to use that API" in iOS mobile application through coding. I follow Dial2Verify site for more information, but its only for PHP developer.
My requirement is: I have a call button on my app screen, when I pressed that button, that method will call to Dial2Verify API, And give a missed call to Dial2Verify API and after register Dial2Verify will send that API key/ Mobile number to my App Server, Then App server will check the mobile number is registered or not, if register then it directly go to Home page off App otherwise stay on that Login page.
I would suggest use of mOTP API. (MOTP.in )
Again a service by dial2verify, but it is more suitable for app integration as it supports 200+ countries.
A clever alternative to SMS otp.
At the core it's a 2 step process.
1 sending mOTP : you would be required to call a remote URL from app ( which would send missed call otp to end user )
Step 2: you are required to call another URL from app to cross check otp entered by user.
There is a flow demo available on mOTP website.
Do share the code you build so others can be benefited.
You can probably use a service like https://checkmobi.com/ . Basically they have available 4 validations methods: SMS, IVR, Missed call (the one you need) and another one called CLI.
You can check how each method is working here: https://checkmobi.com/documentation.html#/overview
Also they have available a iOS and Android SDK for mobiles and quite good pricing model for startups.

Adding Keybinds to IOS with Xcode?

Is there a way to add functions to IOS through an app (preferably that can be done in Xcode) that also work outside of the app itself? For example (while the app is running in the background) every time a user presses the spacebar in safari, any entered text will be copied to the clipboard. Thanks!
No - this is not possible and could lead to apps intercepting sensitive data like bank account password etc. You can receive other notifications like push notifications and gps data though.

Check Email during Xcode UI Testing?

UPDATE: Is this still possible with the new way of UI testing with Xcode?
Can I programmatically access my email from an iOS UI Automation script?
I want to access the signup code that my iPhone app emails to my email account.
If you have a way for your device/simulator to receive the code while still in the app then you can write a script an iOS UIA script to do this.
However with the current state of the built in iOS UIA tool, you cannot access anything that is outside of your app. So basically you cannot launch your app, then launch another app (like safari) go to mail.google.com blah blah.
The closest thing to leaving your app in iOS UIA is using a function call to send your app to background for X amount of seconds.
Use NSURLSession to make HTTP requests from within test methods. See: https://stackoverflow.com/a/35708282/242933

Modal Application

I'm using Xamarin.Android and I would like to build an application that start in modal way and don't close if you push the home button.
So this application need to be the only one application than a user can use on device.
Somebody can suggest how it can be done?
You best way to do is to make a "Launcher"/"Home" application. The Android SDK comes with a sample on how to do this.
You basically do this by adding your main Activity to the android.intent.category.HOME and android.intent.category.DEFAULT category and you set the launchMode to singleInstance.
This will register it as a Home application, then when you press your home button it should ask you to choose which launcher you want to use. You will have to set it once and it can be changed by the user.
You can find the sample in: android-sdk\samples\android-17\Home\src\com\example\android\home (should also be available in the other API samples).
You cant stop people from installing applications on android devices. You would have to build your own hardware for that however, you can override OnKeyTouch and check for the key being home.
You could build a service that checks the package of each running application and log which applications are run on the device to prevent users from using company property on other things. However, if android ever decides to kill your application the service should stop and this wont work.
Long story short what you are trying to do is flawed in its inception given the platform you are trying to do it on.

Resources