add ios uiautomation driver doc (#9173)

* add ios uiautomation driver doc

* address review comments

* fix link to xcode-iwd.sh
This commit is contained in:
Jonathan Lipps
2017-09-13 10:04:51 -07:00
committed by GitHub
parent b29a02c8ae
commit 538f1bf1fa
14 changed files with 257 additions and 225 deletions
-14
View File
@@ -1,14 +0,0 @@
## Setting up instruments without delay (iwd) for xcode 7 and iOS >= 9.0
For iOS >= 9.0 instruments without delay (iwd) does not work by passing binaries through the command line (appium does this under the hood for xcode < 7). See [iwd](https://github.com/lawrencelomax/instruments-without-delay/tree/xcode7-quirks#xcode-7--ios-9-support)
For enabling iwd for xcode >= 7,
- Check out [appium-instruments](https://github.com/appium/appium-instruments)
- Run `xcode-iwd.sh` present in `<appium-instruments>/bin/`, with arguments as indicated below:
```
sh <appium-instruments>/bin/xcode-iwd.sh <path to xcode> <path to appium-instruments>
```
eg. `sh ./bin/xcode-iwd.sh /Applications/Xcode.app /Users/xyz/appium-instruments/`
Note: iwd with Xcode 7 will only work for iOS >= 9.0, you can switch to an older version of Xcode for iOS < 9.0
-51
View File
@@ -1,51 +0,0 @@
## Deploying an iOS app to a real device
To prepare for your Appium tests to run on a real device, you will need to:
1. Build your app with specific device-targeted parameters
2. Use [ideviceinstaller](https://github.com/libimobiledevice/ideviceinstaller), a 3rd-party tool,
to deploy this build to your device
### Xcodebuild with parameters:
A newer xcodebuild now allows settings to be specified. Taken from [developer.apple.com](https://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/xcodebuild.1.html):
```center
xcodebuild [-project projectname] [-target targetname ...]
[-configuration configurationname] [-sdk [sdkfullpath | sdkname]]
[buildaction ...] [setting=value ...] [-userdefault=value ...]
```
This is a resource to explore the available [settings](https://developer.apple.com/library/mac/#documentation/DeveloperTools/Reference/XcodeBuildSettingRef/1-Build_Setting_Reference/build_setting_ref.html#//apple_ref/doc/uid/TP40003931-CH3-DontLinkElementID_10)
```center
CODE_SIGN_IDENTITY (Code Signing Identity)
Description: Identifier. Specifies the name of a code signing identity.
Example value: iPhone Developer
```
PROVISIONING_PROFILE is missing from the index of available commands,
but may be necessary.
Specify "CODE_SIGN_IDENTITY" & "PROVISIONING_PROFILE" settings in the
xcodebuild command:
```center
xcodebuild -sdk <iphoneos> -target <target_name> -configuration <Debug> CODE_SIGN_IDENTITY="iPhone Developer: Mister Smith" PROVISIONING_PROFILE="XXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX"
```
On success, the app will be built to your ```<app_dir>/build/<configuration>-iphoneos/<app_name>.app```
### Deploy using ideviceinstaller
To install the latest tagged version of the ideviceinstaller using
Homebrew, run the following commands in the terminal:
``` center
# The first command is only required if you don't have brew installed.
> ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
> brew update
> brew install ideviceinstaller
> ideviceinstaller -u <UDID of device> -i <path of .app/.ipa>
```
Next: [Running Appium on Real Devices](real-devices.md)
+3 -3
View File
@@ -1,6 +1,6 @@
## Appium Support for Real Device Testing
Appium has support for real device testing.
Appium has support for real mobile device testing.
* For **Android** testing, see [android real device documentation](real-devices-android.md)
* For **iOS** testing, see [iOS real device documentation](real-devices-ios.md)
* For **Android** testing, see the [Android real device documentation](real-devices-android.md)
* For **iOS** testing, see the [iOS XCUITest real device documentation](/docs/en/drivers/ios-xcuitest-real-devices.md)
+5 -149
View File
@@ -2,69 +2,12 @@
Appium on OS X supports iOS and Android testing.
### System setup (iOS)
### Testing iOS Apps
* Appium requires Mac OS X 10.10 or greater.
* Make sure you have Xcode and the iOS SDK(s) installed. Xcode version 7.1 is
recommended as earlier versions of Xcode are limited in which versions of iOS
they can test against. See the next section for more detail.
* You need to authorize use of the iOS Simulator. See [below](#authorizing-ios-on-the-computer).
* If you're on Xcode 7.x and up, Instruments Without Delay (IWD) does not work.
You can enable IWD (which will significantly speed up your tests) using [this
method](/docs/en/advanced-concepts/iwd_xcode7.md)
* If you're on Xcode 6, you need to launch each simulator you intend to use
with appium in advance, and change the default to actually show the soft
keyboard if you want sendKeys to work. You can do this by clicking on any
textfield and hitting command-K until you notice the soft keyboard show up.
* If you're on Xcode 6, you have a feature in Xcode called Devices
(command-shift-2). You need to make sure that whichever deviceName you choose
to use with Appium in your capabilities, there is only one of those per sdk
version. In other words, if you send in a deviceName cap of "iPhone 5s" and
a platformVersion cap of "8.0", you need to make sure that there is exactly
one device with the name "iPhone 5s" and the 8.0 sdk in your devices list.
Otherwise, Appium won't know which one to use.
* In iOS 8, devices each have their own setting which enables or disables
UIAutomation. It lives in a "Developer" view in the Settings app. You need to
verify that UIAutomation is enabled in this view before the simulator or
device can be automated.
Instructions for getting going with one of our iOS drivers are included here:
### Authorizing iOS on the computer
You need to authorize use of the iOS Simulator by running the `authorize-ios`
binary made available through `npm`. Install the program by running
```
npm install -g authorize-ios
```
And the invoke the program using
```
sudo authorize-ios
```
If you are running [Appium.app](https://github.com/appium/appium-dot-app), you can
authorize iOS through the GUI.
You need to do this every time you install a new version of Xcode.
### Testing against multiple iOS SDKs
Xcode version 7.1 allows for automatic testing against iOS versions 7.1 and later.
If you're using multiple Xcode versions, you can switch between them using:
sudo xcode-select --switch &lt;path to required xcode&gt;
### Testing using Xcode 8 (including iOS 10) with XCUITest
In order to automate iOS devices with Xcode 8 (which includes all testing of iOS 10+),
you need to install the [Carthage](https://github.com/Carthage/Carthage) dependency
manager:
```
brew install carthage
```
* The [XCUITest Driver](/docs/en/drivers/ios-xcuitest.md)
* The (deprecated) [UIAutomation Driver](/docs/en/drivers/ios-uiautomation.md)
### Testing Mac apps
@@ -76,95 +19,8 @@ To Install Appium for Mac:
For more information on using Appium for mac, checkout the [docs](https://github.com/appium/appium-for-mac#appium-for-mac).
### System setup (Android)
### Testing Android App
Instructions for setting up Android and running tests on Mac OS X are the same as
those on Linux. See the [Android setup docs](/docs/en/appium-setup/android-setup.md).
### Running iOS tests on OS X using Jenkins
First download the jenkins-cli.jar and verify the Mac successfully connects to Jenkins master. Ensure you've run the `authorize-ios` command mentioned above.
`wget https://jenkins.ci.cloudbees.com/jnlpJars/jenkins-cli.jar`
```
java -jar jenkins-cli.jar \
-s https://team-appium.ci.cloudbees.com \
-i ~/.ssh/id_rsa \
on-premise-executor \
-fsroot ~/jenkins \
-labels osx \
-name mac_appium
```
Next define a LaunchAgent for Jenkins to launch automatically on login. A LaunchDaemon will not work because daemons don't have GUI access. Make sure the plist doesn't contain the `SessionCreate` or `User` key as that may prevent tests from running. You'll see a `Failed to authorize rights` error if misconfigured.
```
$ sudo nano /Library/LaunchAgents/com.jenkins.ci.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.jenkins.ci</string>
<key>ProgramArguments</key>
<array>
<string>java</string>
<string>-Djava.awt.headless=true</string>
<string>-jar</string>
<string>/Users/appium/jenkins/jenkins-cli.jar</string>
<string>-s</string>
<string>https://instructure.ci.cloudbees.com</string>
<string>on-premise-executor</string>
<string>-fsroot</string>
<string>/Users/appium/jenkins</string>
<string>-executors</string>
<string>1</string>
<string>-labels</string>
<string>mac</string>
<string>-name</string>
<string>mac_appium</string>
<string>-persistent</string>
</array>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>/Users/appium/jenkins/stdout.log</string>
<key>StandardErrorPath</key>
<string>/Users/appium/jenkins/error.log</string>
</dict>
</plist>
```
Finally set the owner, permissions, and then start the agent.
```
sudo chown root:wheel /Library/LaunchAgents/com.jenkins.ci.plist
sudo chmod 644 /Library/LaunchAgents/com.jenkins.ci.plist
launchctl load /Library/LaunchAgents/com.jenkins.ci.plist
launchctl start com.jenkins.ci
```
### Files generated by iOS test runs
Testing on iOS generates files that can sometimes get large. These include logs,
temporary files, and derived data from Xcode runs. Generally the following locations
are where they are found, should they need to be deleted:
```
$HOME/Library/Logs/CoreSimulator/*
```
For Instruments-based tests (iOS _not_ using `XCUITest` as `automationName`):
```
/Library/Caches/com.apple.dt.instruments/*
```
For XCUITest-based tests:
```
$HOME/Library/Developer/Xcode/DerivedData/*
```

Before

Width:  |  Height:  |  Size: 216 KiB

After

Width:  |  Height:  |  Size: 216 KiB

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Before

Width:  |  Height:  |  Size: 2.6 MiB

After

Width:  |  Height:  |  Size: 2.6 MiB

Before

Width:  |  Height:  |  Size: 50 KiB

After

Width:  |  Height:  |  Size: 50 KiB

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

@@ -1,4 +1,4 @@
## Mobile Web on iOS 9.3 and below Real Devices: SafariLauncher
## SafariLauncher Setup Instructions
Running mobile web tests on iOS real devices with iOS 9.3 or below, using Instruments,
requires the introduction of a third-party app, [SafariLauncher](https://github.com/snevesbarros/SafariLauncher).
@@ -58,34 +58,34 @@ git clone https://github.com/snevesbarros/SafariLauncher.git
Once you have a local copy of the source code for the `SafariLauncher` app, open
[Xcode](https://developer.apple.com/xcode/) and then open the `SafariLauncher` project
![Opening SafariLauncher project](safari-launcher/opening.png)
![Opening SafariLauncher project](ios-uiautomation-safari-launcher-img/opening.png)
In the `SafariLauncher` target pane you will see an error, saying that there needs
to be a provisioning profile for this app
![No provisioning profile error](safari-launcher/no-provisioning-profile.png)
![No provisioning profile error](ios-uiautomation-safari-launcher-img/no-provisioning-profile.png)
In order to fix this, you first need to enter a "Bundle Identifier" for the app. The default
expected by Appium is `com.bytearc.SafariLauncher`, but this might not be available
for you to build. In that case, choose something else, and make note of it. Then
choose a "Team", and allow the provisioning profile to be created
![Fixing provisioning profile error](safari-launcher/changing-bundleid.png)
![Fixing provisioning profile error](ios-uiautomation-safari-launcher-img/changing-bundleid.png)
Finally, make sure your device is connected to the computer, and choose it as the
target
![Choosing device](safari-launcher/choosing-target.png)
![Choosing device](ios-uiautomation-safari-launcher-img/choosing-target.png)
And run the build and install actions to compile the app and push it onto your
device
![Running SafariLauncher](safari-launcher/running.png)
![Running SafariLauncher](ios-uiautomation-safari-launcher-img/running.png)
Now you have a working `SafariLauncher` on your device. The app itself is a plain
screen that will launch `Safari` at the click of a button
![SafariLauncher on device](safari-launcher/safarilauncher.png)
![SafariLauncher on device](ios-uiautomation-safari-launcher-img/safarilauncher.png)
The last step is only necessary if you chose a bundle identifier for the app that
is different from the default (`com.bytearc.SafariLauncher`). If you did, it is
+231
View File
@@ -0,0 +1,231 @@
## The UIAutomation Driver for iOS
> **Note**: This driver is _DEPRECATED_ and should not be used unless
> absolutely necessary. The information in this doc may not keep up to date
> with reality, and the driver will be removed in a future version of Appium.
> To begin iOS automation with Appium today, please use the [XCUITest
> Driver](/docs/en/drivers/ios-xcuitest.md) instead.
Appium's former method for iOS app automation was based on `UIAutomation`, an
Apple-provided framework that shipped with the iOS SDK until iOS 10, when it
was removed. `UIAutomation` was one of the tools included in Apple's
Instruments profiling system, and provided a JavaScript API that ran
synchronously in the context of a single app. The Appium UIAutomation driver
established an asynchronous, session-based WebDriver front end for this API.
Development of the UIAutomation driver is done at the
[appium-ios-driver](https://github.com/appium/appium-ios-driver) repo.
### Requirements and Support
(In addition to Appium's [general requirements](#TODO))
* Xcode 7 or lower.
* iOS simulators or devices with version 9.3 or lower.
* All versions of Appium ship with this driver.
* For correct functioning of the driver, see additional setup below.
### Usage
The way to start a session using the UIAutomation driver is to set the
`platformName` [capability](#TODO) in your [new session request](#TODO) to the
value of `iOS`. Of course, you must also include appropriate `platformVersion`,
`deviceName`, and `app` capabilities, at a minimum.
### Capabilities
The UIAutomation driver supports a number of standard [Appium
capabilities](/docs/en/writing-running-appium/caps.md), but has an additional
set of capabilities that work for this driver only (see the [iOS
section](/docs/en/writing-running-appium/caps.md#ios-only) of the
aforementioned doc).
To automate Safari instead of your own application, leave the `app` capability
empty and instead set the `browserName` capability to `Safari`.
### Commands
To see the various commands Appium supports, and specifically for information
on how the commands map to behaviors for the UIAutomation driver, see the [API
Reference](#TODO).
### Simulator Setup
(Note that due to limitations of Xcode and the iOS simulator, only one
simulator may be open, and automated, at any given time. For multiple simulator
support, you will need to upgrade to the [XCUITest driver](ios-xcuitest.md)).
1. To allow the iOS simulator to be automated by Instruments, you need to
modify the authorization database for the system. Appium provides an easy
way to do this by installing and running an authorization script:
```
npm install -g authorize-ios
sudo authorize-ios
```
1. By default, Instruments-based automation is limited by the inclusion of
a 1-second hard-coded delay between commands, implemented for obscure
reasons by Apple's engineers. There is a way around this limitation called
[instruments-without-delay](https://github.com/facebookarchive/instruments-without-delay)
(IWD). IWD ships with Appium for Xcode versions < 7. For 7.x and up, IWD
must be installed manually by the user in advance of using Appium. The way
to do this is as follows:
* Clone the [appium-ios-driver](https://github.com/appium/appium-ios-driver)
repository.
* Inside the repo, run the `xcode-iwd.sh` script included in the `bin` dir,
passing it several arguments: (1) the path to the Xcode app you are
using. (2) The path to the appium-instruments directory. For example:
```
sh ./bin/xcode-iwd.sh /Applications/Xcode.app /Users/me/appium-instruments/
```
1. For best results, launch each simulator you wish to use and ensure the following:
* The soft keyboard is enabled (Command+K in the Simulator app)
* UIAutomation is enabled in the Developer settings menu
* There is not more than one simulator with the same name in Xcode's
"Devices" organizer
### Real Device Setup
Running tests on real devices is considerably more complicated due to code
signing and additional workarounds to Apple limitations. The basic process for
a successful automation strategy using this driver are as follows:
1. Build your app with a Debug configuration, for the specific type of real
device you will run the test on, ensuring that the app is also signed for
running on your specific device. For example:
```
xcodebuild -sdk <iphoneos> -target <target_name> -configuration Debug \
CODE_SIGN_IDENTITY="iPhone Developer: Mister Smith" \
PROVISIONING_PROFILE="XXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX"
```
1. Install the built app (usually now located in a build directory specified in
Xcode) to your test device yourself, ensuring it exists on the device and
there are no signing issues. There are a number of methods for installing
apps onto devices. One is to just use Xcode itself. Another is to use the
`ideviceinstaller` tool provided as part of the `libimobiledevice` suite.
A third is to use [ios-deploy](https://npmjs.org/packages/ios-deploy).
Here's an example for `ideviceinstaller`:
```
# first install ideviceinstaller, using Homebrew (http://brew.sh)
brew install libimobiledevice
ideviceinstaller -u <UDID of your device> -i <path to your built app>
```
1. Use the bundle ID of your application as the value of the `app` capability.
1. Use the UDID of your device as the `udid` capability.
1. As above, ensure that UI Automation is enabled in the Developer settings.
Following these steps should ensure your success! If you're using newer
versions of Xcode (7.x, for example), you may wish to consult the [XCUITest
Driver Real Device Docs](/docs/en/drivers/ios-xcuitest-real-devices.md) as they
may contain some pertinent information as well.
### Real Device Hybrid / Web Testing
For hybrid and web testing, Appium requires the use of the Remote Debugging
Protocol to send JavaScript to execute inside a web view. For real iOS devices,
this protocol is encrypted and access must be facilitated using a 3rd-party
tool called
[ios-webkit-debug-proxy](https://github.com/google/ios-webkit-debug-proxy)
(IWDP). For information on installing and using IWDP, check out the [IWDP
doc](/docs/en/advanced-concepts/ios-webkit-debug-proxy.md).
For web testing, i.e., tests that run in the Safari browser, we have another
hurdle to jump. On real devices, apps that are not signed by the developer
cannot be instrumented with UIAutomation. Safari is one such app. Thus we have
a helper app called `SafariLauncher`, which _can_ be signed by the developer.
Its sole purpose upon launching is to turn around and launch Safari, which can
then be automated via the Remote Debugger in conjunction with IWDP.
For instructions on setting up SafariLauncher, check out the [SafariLauncher
doc](/docs/en/drivers/ios-uiautomation-safari-launcher.md).
### Files generated by iOS test runs
Testing on iOS generates files that can sometimes get large. These include
logs, temporary files, and derived data from Xcode runs. Generally the
following locations are where they are found, should they need to be deleted:
```
$HOME/Library/Logs/CoreSimulator/*
/Library/Caches/com.apple.dt.instruments/*
```
### Running iOS tests using Jenkins
First download the `jenkins-cli.jar` and verify that the Mac successfully
connects to Jenkins master. Ensure you've run the `authorize-ios` command
mentioned above.
```
wget https://jenkins.ci.cloudbees.com/jnlpJars/jenkins-cli.jar
java -jar jenkins-cli.jar \
-s https://team-appium.ci.cloudbees.com \
-i ~/.ssh/id_rsa \
on-premise-executor \
-fsroot ~/jenkins \
-labels osx \
-name mac_appium
```
Next define a LaunchAgent for Jenkins to launch automatically on login.
A LaunchDaemon will not work because daemons don't have GUI access. Make sure
the plist doesn't contain the `SessionCreate` or `User` key as that may prevent
tests from running. You'll see a `Failed to authorize rights` error if
misconfigured.
```
$ sudo nano /Library/LaunchAgents/com.jenkins.ci.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.jenkins.ci</string>
<key>ProgramArguments</key>
<array>
<string>java</string>
<string>-Djava.awt.headless=true</string>
<string>-jar</string>
<string>/Users/appium/jenkins/jenkins-cli.jar</string>
<string>-s</string>
<string>https://instructure.ci.cloudbees.com</string>
<string>on-premise-executor</string>
<string>-fsroot</string>
<string>/Users/appium/jenkins</string>
<string>-executors</string>
<string>1</string>
<string>-labels</string>
<string>mac</string>
<string>-name</string>
<string>mac_appium</string>
<string>-persistent</string>
</array>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>/Users/appium/jenkins/stdout.log</string>
<key>StandardErrorPath</key>
<string>/Users/appium/jenkins/error.log</string>
</dict>
</plist>
```
Finally set the owner, permissions, and then start the agent.
```
sudo chown root:wheel /Library/LaunchAgents/com.jenkins.ci.plist
sudo chmod 644 /Library/LaunchAgents/com.jenkins.ci.plist
launchctl load /Library/LaunchAgents/com.jenkins.ci.plist
launchctl start com.jenkins.ci
```
+10
View File
@@ -31,6 +31,13 @@ repo.
* For correct functioning of the driver, additional system libraries are
required (see the Setup sections below).
### Migrating from the UIAutomation Driver
If you are migrating to the XCUITest driver from Appium's old
[UIAutomation-based driver](/docs/en/drivers/ios-uiautomation.md), you may wish
to consult this [migration
guide](/docs/en/advanced-concepts/migrating-to-1-0.md).
### Usage
The way to start a session using the XCUITest driver is to include the
@@ -47,6 +54,9 @@ set of capabilities that modulate the behavior of the driver. These can be
found currently at the [appium-xcuitest-driver
README](https://github.com/appium/appium-xcuitest-driver#desired-capabilities).
To automate Safari instead of your own application, leave the `app` capability
empty and instead set the `browserName` capability to `Safari`.
### Commands
+1 -1
View File
@@ -80,7 +80,7 @@ Before you can run your tests against Safari on a real device you will need to:
* Have the **ios-webkit-debug-proxy** installed, running and listening on port 27753 (see the
[hybrid docs](/docs/en/advanced-concepts/hybrid.md#execution-against-a-real-ios-device) for instructions)
* Turn on **web inspector** on iOS device (**settings > safari > advanced**)
* Make sure that `SafariLauncher` will work (see the [SafariLauncher docs](safari-launcher.md) for instructions)
* Make sure that `SafariLauncher` will work (see the [SafariLauncher docs](/docs/en/drivers/ios-uiautomation-safari-launcher.md) for instructions)
### Running your test