What applescript commands can be sent to iOS Simulator? - ios

I know you can tell the iOS Simulator to quit with applescript. Can you tell it to go "home" from the current app? And then click on the app's icon to relaunch it? This would be useful for me for Application Tests that need to verify background tasks complete and numerous other cases.

Any AppleScriptable app must export a scripting dictionary in order for AppleScript to know what its commands are. You can see any app's dictionary by opening the app in Script Editor.
Note that even if an app doesn't provide script commands for what you want, System UI Scripting or Automator can likely still be used to drive its UI. (For example, to choose the Home or Rotate commands in iOS Simulator's menu bar.)
There's also iOS-specific UI automation stuff you can do from the Instruments app that comes with Xcode.

The iOS Simulator does not directly support AppleScript. It doesn't have a scripting dictionary. This means that the only real way to manipulate it in AppleScript is to use the UI commands that work for any application.

Related

How does a UI app inspectors (like the one in Appium) work?

Appium has a way to inspect the view hierarchy of an app using an inspector. I am interested in building one myself.
I know the overview answer of: it uses some webdriver to accomplish this. But how?
It puzzles me that a separate iOS app can some how communicate to another app, and show even its screen.
How does it work under the hood? or how does the iOS app communicate to the UI inspector to send its screen shots and hierarchy?
It puzzles me that a separate iOS app can some how communicate to another app, and show even its screen.
Yes! Apps should not be able to do this. But there exists a special kind of app, built just for testing, which IS able to do this.
The way this is done is using Apple's XCUITest framework. When you write an XCUITest in XCode, it builds a special app which is able to start your test app and then communicate with it using the XCUITest methods. These methods allow you to inspect elements in the view.
In order to create a view tree, you start at the root view and iterate over the children, building out a tree with a tree traversal.
Normally, the XCUITest app exits when your test script finishes, which means you won't be able to access it from a desktop app for viewing the tree as it updates. If you write your test script to run an infinite loop and open a network port for communication with an outside process, now you can build your viewer. This is exactly what Appium does, so I suggest you check out the appium source code and maybe just use that?
More information in this blog post
[edit]: Oh yeah, Appium uses Feacebook's WebDriverAgent project as the script that runs on the app. So WebDriverAgent is basically an XCUITest script which runs a server and can take commands during a test. Appium does a ton of work to bundle and package it into the special kind of companion app that is able to access your app, installs it on the iOS device, and then runs the test. WebDriverAgent has a command which iterates over the UIHierarchy and returns the whole tree.

How can I automate WiFi testing using Xcode Instruments?

I want to automate the UI flow on iOS, specifically below steps:
User taps on Settings
Opens WiFi options
Taps on the desired SSID
Enters Username and Password
Taps connect
Opens up a browser
I can do similar flow on Android with Android Debug Bridge. In Xcode Instruments, I don't see any WiFi options listed. Do we have any other tool to automate UI flow on iOS?
The standard is now to use UI Unit tests from XCode. Automation via instruments is deprecated (as far as I know).
However you can automate iOS itself, only the app you are testing. So accessing the settings like this will not work.
I'm also wondering why you need to test this. It's part of iOS and not your app. Therefore it's Apple's job to test it. You can just assume it works.
There is no way to do this on iOS. You may want to look into something like http://www.tapster.io.
Also ui_automation is remove from Xcode 8, so theres that.
I'm having pretty good luck with http://www.tapster.io

phonegap iOS app working on simulator but not in device. How to debug

I just finished developing a Cordova / Phonegapp app. When I test it on iOS simulator it all works fine and quick, but, when testing on device it works only part of it.
My app is a game with the kingdom background and has 8 buttons (8 buildings).
When I click on each building it leads me to a screen representing what it's inside the building, but one of them doesn't work and gets my app frozen.
How can I see fail or crash reports that helps me debug my app on device?
If you provide full path to your file i.e. "file:///Users/.../someDir/some.html" it will work only on simulator running on the same machine where your project is.
I suggest just adding the additional path to the file you want to access i.e. if you are in "/someDir" you will need to provide only "some.html" or if you want to access parent directory just use "../".
As far as debugging Cordova app, I suggest downloading this plugin and using console.log instead of alert.
Hope this helped.
Ok, I found a "spartan" way to debug my app via alert and found that an url wasn't set properly (still don't know why it worked on simulator)

How to support/assing ALL file types (UTIs) in iOS?

I'm developing something like file manager for remote filesystem with some basic operations including transferring file(s) between server and iPad and viewing them.
In order to be useful I need my app to open all types of files from other apps (like Mail, Safari, etc.) via "Open in.." dialog to get them into my app, i. e. Dropbox-like behaviour. When I use public.data and public.content, like it is described in this answer (and this), it sometimes work, but most of the time, it isn't. Moreover, iOS 6.1 simulator behaves nondeterministic regarding file handling.
When I Run in Xcode and it launches simulator, it doesn't work. When I let simulator running, Stop in Xcode and then Run in Xcode, it suddenly work. When I completely quit simulator and Run in Xcode I get at start of this loop. Mysterious.
When I run app on physical iPad with iOS 6 and start Safari or Mail and go to some document or attachment in it, [Open in...] dialog appears including my app but tapping does nothing, no reaction.
My goal is to make it work for iOS from 5.1 up.
Base SDK: iOS 6.1
Target: 5.1
I'm rookie here on SO. Although I've read instruction how to write good questions, help me improve my question if you feel it is needed, please.
Using public.item, in documentation:
Documentation UTIs

UI Recorder template not found in instruments

I have installed xcode4 and used profiling for leaks and allocations, etc. However, I don't find the new UI Recorder template in instruments under iOS however I find a template named Automation. Please let me know how to enable UI Recorder template in instruments for xcode 4 and also any idea what is this Automation template for?
Thanks.
There is no UI Recorder template for iOS applications, it can't be done. The Automation template is for automated UI unit tests. It runs a JavaScript test script that you put together that is able to drive the UI and record successes or failures. You can find details about UI Automation in the Instruments Users Guide.
It helps a lot to read the documentation first and then ask specific questions later, when you don't understand something in the documentation or something doesn't work as expected. If you don't read the documentation, you'll just get answers where people either reiterate the documentation to you, or point you to the documentation.
Well, instead you can record the user actions of the iOS simulator.
Make sure that the 'Enable access for assistive devices' setting is enabled in your Universal Access pane of System Preferences.
In instruments, just choose the 'UI Recorder' template (Mac OS X).
Start the iOS simulator and connect it to instruments by attaching the 'iPhone simulator' process in the 'choose target' selection box.
Press 'Record'.
Welcome!
I've just tried Rolands suggestion below and it works - not perfectly, it misses to play some recorded interactions, but it works and creates an editable script! I'm using Xcode 4.6.2, Instruments 4.6 and running iPhone 6.1 Simulator.

Resources