Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Automate All The Things!

Automate All The Things!

Adding automated user interface testing to your iOS project.

Avatar for Tim Bugai

Tim Bugai

April 29, 2013
Tweet

More Decks by Tim Bugai

Other Decks in Technology

Transcript

  1. var target = UIATarget.localTarget(); var app = target.frontMostApp(); var window

    = app.mainWindow(); target.logElementTree(); Wednesday, May 1, 13
  2. var target = UIATarget.localTarget(); var app = target.frontMostApp(); var window

    = app.mainWindow(); target.logElementTree(); Wednesday, May 1, 13
  3. var target = UIATarget.localTarget(); var app = target.frontMostApp(); var window

    = app.mainWindow(); target.logElementTree(); Wednesday, May 1, 13
  4. var target = UIATarget.localTarget(); var app = target.frontMostApp(); var window

    = app.mainWindow(); var table = window.tableViews()[0]; var cells = table.cells(); var testName = "Mark of Item"; UIALogger.logStart(testName); var cell = cells.firstWithName("Milk") if (cell.isValid()) { cell.tap(); } else { UIALogger.logFail(testName); } cell = cells.firstWithName("Milk-Acquired"); if (cell.isValid()) { UIALogger.logPass(testName); } else { UIALogger.logFail(testName); } Wednesday, May 1, 13
  5. Accessibility Labels Do NOT set them on a container element

    unless you know what you are doing! Wednesday, May 1, 13
  6. target = UIATarget.localTarget() app = target.frontMostApp() window = app.mainWindow() table

    = window.tableViews()[0] cells = table.cells() testName = "Mark of Item" UIALogger.logStart(testName) cell = cells.firstWithName("Milk") if cell.isValid() cell.tap() else UIALogger.logFail(testName) cell = cells.firstWithName("Milk-Acquired") if cell.isValid() UIALogger.logPass(testName) else UIALogger.logFail(testName) Coffeescript Wednesday, May 1, 13
  7. test "Mark off item", (target, app) -> table = app.mainWindow().tableViews()[0]

    cells = table.cells() cell = cells.firstWithName("Milk") assertNotNull(cell) cell.tap() cell = cells.firstWithName("Milk-Acquired") assertNotNull(cell) Wednesday, May 1, 13
  8. Device Rotation #github "alexvollmer/tuneup_js/tuneup.js" test "Add a new item", (target,

    app) -> target.setDeviceOrientation(UIA_DEVICE_ORIENTATION_PORTRAIT) table = app.mainWindow().tableViews()[0] cells = table.cells() assertEquals 3, cells.length target.setDeviceOrientation(UIA_DEVICE_ORIENTATION_LANDSCAPELEFT) app.keyboard().typeString("Cheese\n") target.setDeviceOrientation(UIA_DEVICE_ORIENTATION_PORTRAIT) assertEquals 4, table.cells().length assertNotNull table.cells()["Cheese"] Wednesday, May 1, 13
  9. Device Rotation #github "alexvollmer/tuneup_js/tuneup.js" test "Add a new item", (target,

    app) -> target.setDeviceOrientation(UIA_DEVICE_ORIENTATION_PORTRAIT) table = app.mainWindow().tableViews()[0] cells = table.cells() assertEquals 3, cells.length target.setDeviceOrientation(UIA_DEVICE_ORIENTATION_LANDSCAPELEFT) app.keyboard().typeString("Cheese\n") target.setDeviceOrientation(UIA_DEVICE_ORIENTATION_PORTRAIT) assertEquals 4, table.cells().length assertNotNull table.cells()["Cheese"] Wednesday, May 1, 13
  10. Swipe Gesture #github "alexvollmer/tuneup_js/tuneup.js" test "delete an item", (target, app)

    -> target.setDeviceOrientation(UIA_DEVICE_ORIENTATION_PORTRAIT) table = app.mainWindow().tableViews()[0] cell = table.cells().firstWithName('Eggs') assertNotNull cell cell.dragInsideWithOptions({startOffset:{x:0.0, y:0.1}, endOffset:{x:0.5, y:0.1}, duration:0.25}) deleteButton = table.cells().firstWithName('Eggs').buttons()[0] assertNotNull deleteButton deleteButton.tap() assertEquals 2, table.cells().length assertNull table.cells().firstWithName("Eggs") Wednesday, May 1, 13
  11. Cons •Apple uses it •Documentation is lacking •CoreData is hard

    •Can’t mock interfaces Pros •Apple uses it Wednesday, May 1, 13
  12. Travis CI Open Source Rakefile require 'rubygems' require 'xcodebuild' require

    'bwoken/tasks' XcodeBuild::Tasks::BuildTask.new do |t| t.configuration = "Debug" t.sdk = "iphonesimulator" t.formatter = XcodeBuild::Formatters::ProgressFormatter.new end Wednesday, May 1, 13