How To Automate Ios App Using Appium In Mac

Edit this Doc The UIAutomation Driver for iOS

Appium Python Course - Learn to automate iOS and Android mobile applications. We will be using Python + PyCharm + pytest in this series. Page Object Model based Test Automation Framework with realtime & opensource WordPress iOS and Android app. Detailed steps to setup mobile automation environment in your Mac. Open terminal go to nodemodules/appium-xcuitest-driver/WebDriverAgent (this path is relative to your appium installation). Run following commands Run following commands mkdir -p Resources/WebDriverAgent.bundle.

Note: This driver is DEPRECATED and should not be used unlessabsolutely necessary. The information in this doc may not keep up to datewith reality, and the driver will be removed in a future version of Appium.To begin iOS automation with Appium today, please use the XCUITestDriver instead.

Appium's former method for iOS app automation was based on UIAutomation, anApple-provided framework that shipped with the iOS SDK until iOS 10, when itwas removed. UIAutomation was one of the tools included in Apple'sInstruments profiling system, and provided a JavaScript API that ransynchronously in the context of a single app. The Appium UIAutomation driverestablished an asynchronous, session-based WebDriver front end for this API.

Development of the UIAutomation driver is done at theappium-ios-driver repo.

Requirements and Support

In addition to Appium's general requirements:

  • 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 theplatformNamecapability in your new session request to thevalue 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 Appiumcapabilities, but has an additionalset of capabilities that work for this driver only (see the iOSsection of theaforementioned doc).

To automate Safari instead of your own application, leave the app capabilityempty and instead set the browserName capability to Safari.

Commands

To see the various commands Appium supports, and specifically for informationon how the commands map to behaviors for the UIAutomation driver, see the APIReference.

Simulator Setup

(Note that due to limitations of Xcode and the iOS simulator, only onesimulator may be open, and automated, at any given time. For multiple simulatorsupport, you will need to upgrade to the XCUITest driver).

  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:

    sudo authorize-ios

  2. 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 (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 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/

  3. 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 codesigning and additional workarounds to Apple limitations. The basic process fora 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'

  2. 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. Here's an example for ideviceinstaller:

    ```

    brew install libimobiledeviceideviceinstaller -u

    Real Device Hybrid / Web Testing

    For hybrid and web testing, Appium requires the use of the Remote DebuggingProtocol 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-partytool, provided by Google, calledios-webkit-debug-proxy(IWDP). For information on installing and using IWDP within Appium, check outthe IWDP doc.

    For web testing, i.e., tests that run in the Safari browser, we have anotherhurdle to jump. On real devices, apps that are not signed by the developercannot be instrumented with UIAutomation. Safari is one such app. Thus we havea helper app called SafariLauncher, which can be signed by the developer.Its sole purpose upon launching is to turn around and launch Safari, which canthen be automated via the Remote Debugger in conjunction with IWDP. Unfortunatelyyou cannot, in this case, move into the native context and do any automation ofthe browser itself.

    For instructions on setting up SafariLauncher, check out the SafariLauncherdoc.

    Files generated by iOS test runs

    Testing on iOS generates files that can sometimes get large. These includelogs, temporary files, and derived data from Xcode runs. Generally thefollowing locations are where they are found, should they need to be deleted:

    Running iOS tests using Jenkins

    First download the jenkins-cli.jar and verify that the Mac successfullyconnects to Jenkins master. Ensure you've run the authorize-ios commandmentioned above.

    How to automate ios app using appium in mac download

    Next define a LaunchAgent for Jenkins to launch automatically on login.A LaunchDaemon will not work because daemons don't have GUI access. Make surethe plist doesn't contain the SessionCreate or User key as that may preventtests from running. You'll see a Failed to authorize rights error ifmisconfigured.

    Finally set the owner, permissions, and then start the agent.

    One of the great things about Appium is that it can be used for far more than mobile app automation. While iOS and Android remain the most popular use case for Appium, it is also possible to use Appium to automate a host of other platforms, including Windows and Mac desktop applications. In this article, we'll take a look at how to use Appium to automate Windows desktop apps.

    Automation of Windows apps is actually quite a special thing in the Appium world, since Microsoft itself supports this automation via the development of a tool called WinAppDriver. WinAppDriver is essentially an Appium-compatible automation interface, which Appium automatically includes if you specify the appropriate desired capabilities for your test.

    Windows Automation Setup

    Ios

    What do you need to run automated tests of native Windows apps? Well, it goes without saying that you need a Windows PC to host and run your applications, as well as running the Appium server that will perform the automation. (Your client script, of course, can run anywhere you like as long as it can connect to Appium running on Windows over the network.)

    Here's everything that I needed to do to get Appium set up to automate Windows apps:

    1. Navigate to 'Developer Settings' under 'System Settings', and turn on 'Developer Mode' (this is required for WinAppDriver to control the desktop).
    2. Install NodeJS.
    3. Start an Admin command prompt (type 'cmd' into the Start menu and then hit CTRL+SHIFT+ENTER to launch the command prompt in Admin mode).
    4. Use the NPM binary installed with Node to download the most recent version of Appium:
    5. Run Appium (ensuring I'm still in the Admin console!)

    At this point, my system is now ready to go, with an Appium server running on the default port of 4723. All that's left is to decide what to automate!

    Windows Automation Desired Capabilities

    Which capabilities are necessary for use with Windows app automation? Pretty much just the typical ones:

    • platformName should be set to Windows

    • platformVersion should be set to 10

    • deviceName should be set to WindowsPC

    • app should be set to the App ID of the app you want to test. For an app that you've created, the WinAppDriver docs state:

      You can find the Application Id of your application in the generated AppXvs.appxrecipe file under RegisteredUserModeAppID node. E.g. c24c8163-548e-4b84-a466-530178fc0580_scyf5npe3hv32!App

      For an app that you haven't created, like a built-in system app, I discovered a neat trick of opening up a PowerShell window and running the following command:

      This will list all the installed apps along with their App IDs. The app I chose to automate for this article was the built-in Weather app, which had the ID Microsoft.BingWeather_8wekyb3d8bbwe!App.

    How To Automate Ios App Using Appium In Mac Operating System

    (The WinAppDriver docs also list several other capabilities that might be useful for your purposes, so check them out too.)

    Ultimately, when put into Java client form, my capabilities look like:

    Finding UI Elements In Windows Apps

    How To Automate Ios App Using Appium In Mac Os

    I found the Weather app to be quite well-instrumented with automation-ready IDs and labels. After I was able to launch a session using the capabilities above, I ran driver.getPageSource() to have a look at the source XML. I found it to be quite useful, with plenty of sections like this, that clued me into the most helpful available attributes:

    How To Automate Ios App Using Appium In Mac Shortcut

    This is the representation of a ListItem element which shows a particular day of the week along with a little weather summary. We can see that the Name attribute has most of the information I might want, including the date, the high and low temperatures, and a weather forecast. I could easily find this element via the name locator strategy, or (as I ended up doing), using xpath.

    Other non-dynamic elements had the AutomationId attribute set, and for these elements, we can use the corresponding attribute as the selector for the accessibility id locator strategy.

    How To Automate Ios App Using Appium In Mac Download

    Writing a Test for a Windows App

    Once we know how to find elements, there's really not much more we need to know to write our test! The only wrinkle I discovered is that, unlike Appium's behavior with mobile apps, WinAppDriver does not reset the state of applications when a session starts. This is both a blessing and a curse. It meant I could manually open the Weather app and click through all the prompts and ads, then trust that the state would remain the same when I launched an automated test. But it also means that you can't necessarily assume the app will always be in the same state across different systems (say in a CI environment).

    Also, because I was running the test on the computer I was using, I of course had to stop work while the test was running, so as not to disturb it (WinAppDriver steals the mouse and moves it around just like a user would).

    Without further ado, I present my very useless test of the Weather app, which simply finds every day which is listed in the app, clicks on each one, and then prints out the weather forecast (along with sunrise/sunset) for that particular day. Again, it's not a true 'test' in the sense that I'm not making any verifications, but I am showcasing how easy it is to automate a Windows application using the Appium API.

    Are you already using Windows automation effectively? Let us know about it in the comments to this article! And as always you can check out the full code for this article on GitHub.