Setting Apple's UI Automation Free with Appium

19
Setting Apple’s UIAutomation Free with Appium Dan Cuellar [email protected] Lead Software Engineer, Test Team

description

By Dan Cuellar, Zoosk

Transcript of Setting Apple's UI Automation Free with Appium

Page 1: Setting Apple's UI Automation Free with Appium

Setting Apple’s UIAutomation Free

with AppiumDan Cuellar

[email protected]

Lead Software Engineer, Test Team

Page 2: Setting Apple's UI Automation Free with Appium

Overview

The Problem

The SolutionRun UIAutomation From The Command LineBreak It Out Of JavascriptControl it in Real-Time

How to Code With Appium

Demo

Odds & Ends

Page 3: Setting Apple's UI Automation Free with Appium

The Problem

Page 4: Setting Apple's UI Automation Free with Appium

The Problem w/ UIAutomation

runs only in Instruments.app

must be written in Javascript

does not support realtime control

many useful js methods (e.g. HTTP requests) have been removed

difficult to build libraries and re-use code

cannot integrate w/ existing Selenium automation

requires adding http servers to your app’s source code

Page 5: Setting Apple's UI Automation Free with Appium

The Solution

It’s H

ack-ta

stic!

!!

Page 6: Setting Apple's UI Automation Free with Appium

Solving the Problem

need command line control

needs to run on the simulator and real devices

need to break out of javascript

need realtime control

should not require you to add code to your app

shoud not require the application source code

Page 7: Setting Apple's UI Automation Free with Appium

Command Line Control

/usr/bin/instruments -t templatePath (path to Automation.tracetemplate) (path to compiled ios application) -e UIASCRIPT (path to UIAutomation javascript test) -e UIARESULTSPATH (path where results will be saved) [-w device udid]

/usr/bin/xcodebuild (run inside project.xcodeproj) -sdk (sdk version) -target (build target) [-scheme (scheme)]TARGETED_DEVICE_FAMILY=1|2 (1=iPhone, 2=iPad)

Page 8: Setting Apple's UI Automation Free with Appium

Breaking Out Of Javascript

No HTTP Web Requests in UIAutomation JS

However…

host.performTaskWithPathArgumentsTimeout() can run all your favorite shell commands

so with friends like cat, curl, and python who needs Javascript and its HTTP web request methods

… and Don’t Forget the AppleScript (comes in handy when you need to dismiss OS permissions dialogs)

Page 9: Setting Apple's UI Automation Free with Appium

Making It Real-Time

Technique 1, file based communication Javascript loop looking for sequentially number files

in a predetermined folder for commandsHave your program write raw javascript to the fileRead the file using catRun the command using eval()Write the sequentially numbered response file using

whatever you like (I chose python)

Technique 2, setup a proxy web serviceCurl to ask if there’s a command you should runCurl back posting the result

Page 10: Setting Apple's UI Automation Free with Appium

Result

Now you can control UIAutomation from any language that can write files or make web requestsYou can reuse all that non javascript based (java, c#,

python, ruby, php) automation code you have for your selenium tests

Run tests that use a web browser and an iOS device at the same time

The possibilities are endless

Page 11: Setting Apple's UI Automation Free with Appium

Coding w/ Appium

Page 12: Setting Apple's UI Automation Free with Appium

Pre-Requisites

install Xcode

install Xcode Command Line Tools

Set up a ~/.appium file

[appium]username = an_osx_admin_usernamepassword = an_osx_admin_password

OPTIONAL

sudo easy_install pip

sudo pip install bottle (required for webdriver server)

sudo pip install selenium (required to code against the webdriver server)

Page 13: Setting Apple's UI Automation Free with Appium

Running Appium

git clone git://github.com/hugs/appium

To launch the UIAutomation javascript interpretterpython appium.py “/path/to/my.app”

To launch the webdriver serverPython server.py “/path/to/my.app”

Page 14: Setting Apple's UI Automation Free with Appium

Coding Appium like Selenium

from selenium import webdriver

command_url = “http://localhost:4723/wd/hub”iphone = webdriver.DesiredCapabilities.IPHONE

driver = webdriver.Remote(command_url, iphone)

fields = driver.find_elements_by_tag_name('textField’)fields[0].send_keys(3)fields[1].send_keys(4)

buttons = driver.find_elements_by_tag_name('button’)buttons[0].click()

Page 15: Setting Apple's UI Automation Free with Appium

Demo

Page 16: Setting Apple's UI Automation Free with Appium

Odds & Ends

Page 17: Setting Apple's UI Automation Free with Appium

Failed Prototypes

Applescript iOS Simulator AutomationDid not work on actual devicesSeemed to be highly sensitive to iOS and OS X

versionNot a reliable

Javascript Server Within UIAutomation I could not get a server booted up while running in

Instruments

Page 18: Setting Apple's UI Automation Free with Appium

Pitfalls

Bug in UIAutomation causes 1 second delay between commands I get around this by sending batches of commands

Noticed NIBs and XIBs are supported while storyboards are a more of a crapshoot

It’s tricky to make elements accessible in objective CSome controls (UISegmentedControl) are missing

supported accessibility methodsApplying a label to text will hinder your ability to

read the text in the control (you need to encapsulate it)

Page 19: Setting Apple's UI Automation Free with Appium

Resources

Appium Projecthttps://github.com/hugs/appium or

http://appium.io

Discussionhttps://groups.google.com/d/forum/appium-discuss