iOS UI Testing in Xcode
Mark Chang

markchang@kkbox.com
Test Corner
About Me
• Mark Chang

• Testing Engineer in the KKBOX Inc.

• One of contributors in the “Testing with KK” blog.
Overview
• Record and Playback

• Test script (Swift or Objective-C)

• Running UI automation testing in iOS

• Code coverage and test reports
Demo 1

UI Recording - Record and Playback

YouTube Link
How does UI automation work ?
Locate the element
Operate the element
Verify the element
Example
Testing the Add button
// application:
let app = XCUIApplication()
app.launch()
// element and query:
let addButton = app.buttons[“Add”]
addButton.tap()
// assertion:
XCTAssertEqual(app.tables.cells.count, 1)
Example
Testing the Add button
// application:
let app = XCUIApplication()
app.launch()
// element and query:
let addButton = app.buttons[“Add”]
addButton.tap()
// assertion:
XCTAssertEqual(app.tables.cells.count, 1)
Example
Testing the Add button
// application:
let app = XCUIApplication()
app.launch()
// element and query:
let addButton = app.buttons[“Add”]
addButton.tap()
// assertion:
XCTAssertEqual(app.tables.cells.count, 1)
Example
Testing the Add button
// application:
let app = XCUIApplication()
app.launch()
// element and query:
let addButton = app.buttons[“Add”]
addButton.tap()
// assertion:
XCTAssertEqual(app.tables.cells.count, 1)
Example
// application:
let app = XCUIApplication()
app.launch()
// element and query:
let addButton = app.buttons[“Add”]
addButton.tap()
// assertion:
XCTAssertEqual(app.tables.cells.count, 1)
Testing the Add button
Example
// application:
let app = XCUIApplication()
app.launch()
// element and query:
let addButton = app.buttons[“Add”]
addButton.tap()
// assertion:
XCTAssertEqual(app.tables.cells.count, 1)
Testing the Add button
Example
// application:
let app = XCUIApplication()
app.launch()
// element and query:
let addButton = app.buttons[“Add”]
addButton.tap()
// assertion:
XCTAssertEqual(app.tables.cells.count, 1)
Testing the Add button
Example
// application:
let app = XCUIApplication()
app.launch()
// element and query:
let addButton = app.buttons[“Add”]
addButton.tap()
// assertion:
XCTAssertEqual(app.tables.cells.count, 1)
Testing the Add button
Example
Testing the Add button
// application:
let app = XCUIApplication()
app.launch()
// element and query:
let addButton = app.buttons[“Add”]
addButton.tap()
// assertion:
XCTAssertEqual(app.tables.cells.count, 1)
Demo 2

Code coverage and test reports

YouTube Link
For more information please visit
Any Questions ?
Reference
• 使⽤ Xcode 執⾏ UI ⾃動化測試 _ 科科和測試

• https://kkboxsqa.wordpress.com/2015/11/09/%E4%BD%BF%E7%94%A8-xcode-%E5%9F%B7%E8%A1%8C-ui-%E8%87%AA%E5%8B%95%E5%8C%96%E6%B8%AC%E8%A9%A6/

• 使⽤ Xcode Server 持續整合建置 _ 科科和測試

• https://kkboxsqa.wordpress.com/2015/12/10/xcode-server-continuous-integration/

• UI Testing in Xcode - WWDC 2015 - Videos - Apple Developer

• https://developer.apple.com/videos/play/wwdc2015-406/

• UI Testing in Xcode 7 · masilotti.com

• http://masilotti.com/ui-testing-xcode-7/

• Xcode 7 UI testing, a first look

• http://www.mokacoding.com/blog/xcode-7-ui-testing/

• How do I test this with UI Testing?

• https://github.com/joemasilotti/UI-Testing-Cheat-Sheet


iOS UI Testing in Xcode

  • 1.
    iOS UI Testingin Xcode Mark Chang markchang@kkbox.com Test Corner
  • 2.
    About Me • MarkChang • Testing Engineer in the KKBOX Inc. • One of contributors in the “Testing with KK” blog.
  • 3.
    Overview • Record andPlayback • Test script (Swift or Objective-C) • Running UI automation testing in iOS • Code coverage and test reports
  • 4.
    Demo 1 UI Recording- Record and Playback YouTube Link
  • 5.
    How does UIautomation work ?
  • 6.
    Locate the element Operatethe element Verify the element
  • 7.
    Example Testing the Addbutton // application: let app = XCUIApplication() app.launch() // element and query: let addButton = app.buttons[“Add”] addButton.tap() // assertion: XCTAssertEqual(app.tables.cells.count, 1)
  • 8.
    Example Testing the Addbutton // application: let app = XCUIApplication() app.launch() // element and query: let addButton = app.buttons[“Add”] addButton.tap() // assertion: XCTAssertEqual(app.tables.cells.count, 1)
  • 9.
    Example Testing the Addbutton // application: let app = XCUIApplication() app.launch() // element and query: let addButton = app.buttons[“Add”] addButton.tap() // assertion: XCTAssertEqual(app.tables.cells.count, 1)
  • 10.
    Example Testing the Addbutton // application: let app = XCUIApplication() app.launch() // element and query: let addButton = app.buttons[“Add”] addButton.tap() // assertion: XCTAssertEqual(app.tables.cells.count, 1)
  • 11.
    Example // application: let app= XCUIApplication() app.launch() // element and query: let addButton = app.buttons[“Add”] addButton.tap() // assertion: XCTAssertEqual(app.tables.cells.count, 1) Testing the Add button
  • 12.
    Example // application: let app= XCUIApplication() app.launch() // element and query: let addButton = app.buttons[“Add”] addButton.tap() // assertion: XCTAssertEqual(app.tables.cells.count, 1) Testing the Add button
  • 13.
    Example // application: let app= XCUIApplication() app.launch() // element and query: let addButton = app.buttons[“Add”] addButton.tap() // assertion: XCTAssertEqual(app.tables.cells.count, 1) Testing the Add button
  • 14.
    Example // application: let app= XCUIApplication() app.launch() // element and query: let addButton = app.buttons[“Add”] addButton.tap() // assertion: XCTAssertEqual(app.tables.cells.count, 1) Testing the Add button
  • 15.
    Example Testing the Addbutton // application: let app = XCUIApplication() app.launch() // element and query: let addButton = app.buttons[“Add”] addButton.tap() // assertion: XCTAssertEqual(app.tables.cells.count, 1)
  • 16.
    Demo 2 Code coverageand test reports YouTube Link
  • 17.
    For more informationplease visit Any Questions ?
  • 18.
    Reference • 使⽤ Xcode執⾏ UI ⾃動化測試 _ 科科和測試 • https://kkboxsqa.wordpress.com/2015/11/09/%E4%BD%BF%E7%94%A8-xcode-%E5%9F%B7%E8%A1%8C-ui-%E8%87%AA%E5%8B%95%E5%8C%96%E6%B8%AC%E8%A9%A6/ • 使⽤ Xcode Server 持續整合建置 _ 科科和測試 • https://kkboxsqa.wordpress.com/2015/12/10/xcode-server-continuous-integration/ • UI Testing in Xcode - WWDC 2015 - Videos - Apple Developer • https://developer.apple.com/videos/play/wwdc2015-406/ • UI Testing in Xcode 7 · masilotti.com • http://masilotti.com/ui-testing-xcode-7/ • Xcode 7 UI testing, a first look • http://www.mokacoding.com/blog/xcode-7-ui-testing/ • How do I test this with UI Testing? • https://github.com/joemasilotti/UI-Testing-Cheat-Sheet