Check Email during Xcode UI Testing? - ios

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

Related

iOS Switch between Parse Server Connections with a button click

Is it possible to initialize Parse configuration more than once in the app through a button?
The scenario is, Add a button inside a ViewController. When clicking, the app switches from my current live parse server to the testing server and vice versa.
Taking into consideration that the app cannot be killed and forced to restart as stated in apple documentation.
You have 2 options:
With Parse IOS SDK - Parse client is a singleton means that you can create only one instance of it. If you don't mind that users will need to close and open your app what you can do is to use NSUserDefaults there you can save the mode of the client (Test or Prod). Again... Users will need to manually restart the app.
Without Parse IOS SDK - it can be done (without restarting the app) only if you will create a custom REST client that will work against Parse REST API. In this way you can create as many client as you want and each client will have it's own configurations.

Removing iOS permission alert for local notifications when running app in simulator

I'm trying to write an acceptance test in KIF on an app that asks for local notification permissions pretty early on. Unfortunately due to iOS simulator security reasons it isn't possible to automate accepting iOS permission alerts using KIF. Per https://stackoverflow.com/a/28443743/62 it looks like there are ways to disable the permission alerts for location, address book, calendar, and photos, but I couldn't find a way to disable the local notification permission. I tried the entitlement approach from the linked question but none of the following keys worked:
kTCCServiceNotifications
kTCCServiceNotification
kTCCServiceLocalNotification
kTCCServiceLocalNotifications
Any other ideas? For now I'm working around this by changing my production code to conditionally disable local notifications when acceptance tests are running, but ideally I wouldn't have to.
Unfortunately, I don't think in an automation test there is a good way to do this. I know that even resetting the simulator isn't sometimes enough to reset permissions. I would design your tests to not test a system call, but your own application code.
One way to test different functionality based on whether the user allows notifications is to extract the call to check for permissions and then stub this method out in the testing. This method would be the best practice since the goal is not to test if iOS works but if your application code is correct.
Notification permission can be suppressed by granting permission in applicationState.plist:
Run your app on a simulator and tap on "ok" for any permission popups
navigate to "~/Library/Developer/CoreSimulator/Devices/{$deviceId}/data/Library/BackBoard/applicationState.plist"
Replace the applicationState.plist of the UI test simulator with the above one before bootstrapping it

how to read sms while testing in appium or selenium

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!

How to resume your app using calaba.sh

I'm using Calaba.sh to to ui testing of my iOS app. I want to be able to test tapping on a link in the app which takes the user to a web address in their browser. I then want to be able to resume the app. Is there a way to do this?
This is not possible in Calabash iOS.

Call Javascript function in background task in iOS

I have a phonegap app and I want to execute Javascript code in a background task. When the application enters background I start executing a javascript function which takes data out of a web database and sends some values to a web service, the returning data may toggle a push-notification to the user.
I found either how to call javascript from Objective-C here on Stackoverflow and how to implement Long-Running Background Tasks in the iOS SDK Documentation pages, but I haven't found anything in combining both (what I think is e.g.: When I invoke javascript code via a webview, does this View even exist when the App is in background?) so I want to ask some more experienced iOS Developers if this is even possible.
I don't think its really possible. Javascript requires a UIwebview to run (in realtime) and must be visible to the user. When an app is put in background only a small amount of tasks are allowed to run- webview not one of them.
Your better off sending your data to a web server that runs a cron-job or similar to send out a push notification via apples push notification server - You can also bypass this and use a service like http://urbanairship.com/
I experimented with this on iOS 5+ and it's possible. I created a small PhoneGap plugin that demonstrates how this works. Check it out, and see the README for most of the info.
https://github.com/jocull/phonegap-backgroundjs

Resources