UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have...

242
© 2015 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple. UI Testing in Xcode Wil Turner Developer Tools Brooke Callahan Developer Tools #WWDC15 Developer Tools Session 406

Transcript of UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have...

Page 1: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

© 2015 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.

UI Testing in Xcode

Wil Turner Developer ToolsBrooke Callahan Developer Tools

#WWDC15Developer Tools

Session 406

Page 2: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Overview

Page 3: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Overview

UI testing

Page 4: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Overview

UI testing• Find and interact with UI elements

Page 5: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Overview

UI testing• Find and interact with UI elements• Validate UI properties and state

Page 6: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Overview

UI testing• Find and interact with UI elements• Validate UI properties and state

UI recording

Page 7: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Overview

UI testing• Find and interact with UI elements• Validate UI properties and state

UI recordingTest reports

Page 8: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Core Technologies

Page 9: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Core Technologies

XCTest

Page 10: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Core Technologies

+

AccessibilityXCTest

Page 11: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCTestXcode’s testing framework

Page 12: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCTestXcode’s testing framework

Test case subclasses

Page 13: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCTestXcode’s testing framework

Test case subclassesTest methods

Page 14: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCTestXcode’s testing framework

Test case subclassesTest methodsAssertions

Page 15: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCTestXcode’s testing framework

Test case subclassesTest methodsAssertionsIntegrated with Xcode

Page 16: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCTestXcode’s testing framework

Test case subclassesTest methodsAssertionsIntegrated with XcodeCI via Xcode Server and xcodebuild

Page 17: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCTestXcode’s testing framework

Test case subclassesTest methodsAssertionsIntegrated with XcodeCI via Xcode Server and xcodebuildSwift and Objective-C

Page 18: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Testing Matrix

Unit UI

Correctness

Performance

Page 19: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Testing Matrix

Unit UI

Correctness

Performance

Page 20: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Testing Matrix

Unit UI

Correctness

Performance

Page 21: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Core Technologies

+

AccessibilityXCTest

Page 22: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Accessibility

Page 23: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Accessibility

Rich semantic data about UI

Page 24: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Accessibility

Rich semantic data about UIUIKit and AppKit integration

Page 25: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Accessibility

Rich semantic data about UIUIKit and AppKit integrationAPIs for fine tuning

Page 26: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Accessibility

Rich semantic data about UIUIKit and AppKit integrationAPIs for fine tuning

UI tests interact with the app the way a user does

Page 27: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Requirements

Page 28: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Requirements

UI testing depends on new OS features

Page 29: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Requirements

UI testing depends on new OS features• iOS 9

Page 30: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Requirements

UI testing depends on new OS features• iOS 9• OS X 10.11

Page 31: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Requirements

UI testing depends on new OS features• iOS 9• OS X 10.11

Privacy protection

Page 32: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Requirements

UI testing depends on new OS features• iOS 9• OS X 10.11

Privacy protection• iOS devices

Page 33: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Requirements

UI testing depends on new OS features• iOS 9• OS X 10.11

Privacy protection• iOS devices

- Enabled for development

Page 34: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Requirements

UI testing depends on new OS features• iOS 9• OS X 10.11

Privacy protection• iOS devices

- Enabled for development- Connected to a trusted host running Xcode

Page 35: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Requirements

UI testing depends on new OS features• iOS 9• OS X 10.11

Privacy protection• iOS devices

- Enabled for development- Connected to a trusted host running Xcode

• OS X must grant permission to Xcode Helper

Page 36: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Requirements

UI testing depends on new OS features• iOS 9• OS X 10.11

Privacy protection• iOS devices

- Enabled for development- Connected to a trusted host running Xcode

• OS X must grant permission to Xcode Helper- Prompted on first run

Page 37: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Getting Started

Page 38: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Getting Started

Xcode target type

Page 39: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Getting Started

Xcode target type

Page 40: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Getting Started

APIsXcode target type

Page 41: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Getting Started

APIsUI recording

Xcode target type

Page 42: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

UI Testing Xcode Targets

Page 43: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

UI Testing Xcode Targets

UI tests have special requirements

Page 44: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

UI Testing Xcode Targets

UI tests have special requirements• Execute in a separate process

Page 45: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

UI Testing Xcode Targets

UI tests have special requirements• Execute in a separate process• Permission to use Accessibility

Page 46: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

UI Testing Xcode Targets

UI tests have special requirements• Execute in a separate process• Permission to use Accessibility

New Xcode target templates

Page 47: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

UI Testing Xcode Targets

UI tests have special requirements• Execute in a separate process• Permission to use Accessibility

New Xcode target templates• Cocoa Touch UI Testing Bundle (iOS)• Cocoa UI Testing Bundle (OS X)

Page 48: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

UI Testing Xcode Targets

UI tests have special requirements• Execute in a separate process• Permission to use Accessibility

New Xcode target templates• Cocoa Touch UI Testing Bundle (iOS)• Cocoa UI Testing Bundle (OS X)

“Target to be Tested” setting

Page 49: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

APIs

Page 50: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

APIs

Three new classes

Page 51: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

APIs

Three new classes• XCUIApplication

Page 52: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

APIs

Three new classes• XCUIApplication• XCUIElement

Page 53: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

APIs

Three new classes• XCUIApplication• XCUIElement• XCUIElementQuery

Page 54: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

UI Recording

Page 55: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

UI Recording

Interact with your app

Page 56: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

UI Recording

Interact with your appRecording generates the code

Page 57: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

UI Recording

Interact with your appRecording generates the code• Create new tests

Page 58: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

UI Recording

Interact with your appRecording generates the code• Create new tests• Expand existing tests

Page 59: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

DemoGetting started with UI testing

Page 60: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

What Did You See?

Page 61: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

What Did You See?

Adding a UI testing target

Page 62: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

What Did You See?

Adding a UI testing targetUsing recording

Page 63: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

What Did You See?

Adding a UI testing targetUsing recording• Finding UI elements

Page 64: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

What Did You See?

Adding a UI testing targetUsing recording• Finding UI elements • Synthesizing user events

Page 65: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

What Did You See?

Adding a UI testing targetUsing recording• Finding UI elements • Synthesizing user events

Adding validation with XCTAssert

Page 66: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

UI Testing API

Page 67: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

UI Testing API

Page 68: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

UI Testing API

XCUIApplication

Page 69: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

UI Testing API

XCUIApplication

XCUIElement

Page 70: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

UI Testing API

XCUIApplication

XCUIElement XCUIElementQuery

Page 71: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

ExampleTesting 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)

Page 72: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

ExampleTesting 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)

Page 73: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

ExampleTesting 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)

Page 74: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

ExampleTesting 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)

Page 75: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

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

Page 76: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

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

Page 77: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

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

Page 78: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

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

Page 79: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

ExampleTesting 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)

Page 80: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCUIApplication

Page 81: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCUIApplication

Proxy for the tested application

Page 82: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCUIApplication

Proxy for the tested application• Tests run in a separate process

Page 83: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCUIApplication

Proxy for the tested application• Tests run in a separate process

Launch

Page 84: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCUIApplication

Proxy for the tested application• Tests run in a separate process

Launch• Always spawns a new process

Page 85: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCUIApplication

Proxy for the tested application• Tests run in a separate process

Launch• Always spawns a new process• Implicitly terminates any preexisting instance

Page 86: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCUIApplication

Proxy for the tested application• Tests run in a separate process

Launch• Always spawns a new process• Implicitly terminates any preexisting instance

Starting point for finding elements

Page 87: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCUIElement

Page 88: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCUIElement

Proxy for elements in application

Page 89: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCUIElement

Proxy for elements in applicationTypes

Page 90: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCUIElement

Proxy for elements in applicationTypes• Button, Cell, Window, etc.

Page 91: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCUIElement

Proxy for elements in applicationTypes• Button, Cell, Window, etc.

Identifiers

Page 92: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCUIElement

Proxy for elements in applicationTypes• Button, Cell, Window, etc.

Identifiers• Accessibility identifier, label, title, etc.

Page 93: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCUIElement

Proxy for elements in applicationTypes• Button, Cell, Window, etc.

Identifiers• Accessibility identifier, label, title, etc.

Most elements are found by combining type and identifier

Page 94: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Element Hierarchy

Page 95: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Element Hierarchy

Application is the root of a tree of elements

Page 96: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Element Hierarchy

Application is the root of a tree of elements

Application

Navigation Bar

View

“Add” Button

Title Label

Table

Cell

“Tech Toys” Label

“Today” Label

“Groceries” Label

Cell

Cell

Page 97: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Element Hierarchy

Application is the root of a tree of elements

Application

Navigation Bar

View

“Add” Button

Title Label

Table

Cell

“Tech Toys” Label

“Today” Label

“Groceries” Label

Cell

Cell

Page 98: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Element Hierarchy

Application is the root of a tree of elements

Application

Navigation Bar

View

“Add” Button

Title Label

Table

Cell

“Tech Toys” Label

“Today” Label

“Groceries” Label

Cell

Cell

Page 99: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Element Hierarchy

Application is the root of a tree of elements

Application

Navigation Bar

View

“Add” Button

Title Label

Table

Cell

“Tech Toys” Label

“Today” Label

“Groceries” Label

Cell

Cell

Page 100: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Element Hierarchy

Application is the root of a tree of elementsUsed by queries with type and identifiers

Application

Navigation Bar

View

“Add” Button

Title Label

Table

Cell

“Tech Toys” Label

“Today” Label

“Groceries” Label

Cell

Cell

Page 101: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Element Uniqueness

Page 102: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Element Uniqueness

Every XCUIElement is backed by a query

Page 103: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Element Uniqueness

Every XCUIElement is backed by a queryQuery must resolve to exactly one match

Page 104: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Element Uniqueness

Every XCUIElement is backed by a queryQuery must resolve to exactly one match• No matches or multiple matches cause test failure

Page 105: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Element Uniqueness

Every XCUIElement is backed by a queryQuery must resolve to exactly one match• No matches or multiple matches cause test failure• Failure raised when element resolves query

Page 106: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Element Uniqueness

Every XCUIElement is backed by a queryQuery must resolve to exactly one match• No matches or multiple matches cause test failure• Failure raised when element resolves query

Exception

Page 107: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Element Uniqueness

Every XCUIElement is backed by a queryQuery must resolve to exactly one match• No matches or multiple matches cause test failure• Failure raised when element resolves query

Exception• exists property

Page 108: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Event Synthesis

Page 109: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Event Synthesis

Simulate user interaction on elements

Page 110: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Event Synthesis

Simulate user interaction on elementsAPIs are platform-specific

Page 111: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Event Synthesis

Simulate user interaction on elementsAPIs are platform-specificbutton.click() // OS X

Page 112: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Event Synthesis

Simulate user interaction on elementsAPIs are platform-specificbutton.click() // OS Xbutton.tap() // iOS

Page 113: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Event Synthesis

Simulate user interaction on elementsAPIs are platform-specificbutton.click() // OS Xbutton.tap() // iOStextField.typeText(“Hello, World!”) // iOS & OS X

Page 114: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCUIElementQueryAPI for specifying elements

Page 115: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCUIElementQueryAPI for specifying elements

Queries resolve to collections of accessible elements

Page 116: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCUIElementQueryAPI for specifying elements

Queries resolve to collections of accessible elements• Number of matches: count

Page 117: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCUIElementQueryAPI for specifying elements

Queries resolve to collections of accessible elements• Number of matches: count• Specify by identifier: subscripting

Page 118: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCUIElementQueryAPI for specifying elements

Queries resolve to collections of accessible elements• Number of matches: count• Specify by identifier: subscripting• Specify by index: elementAtIndex()

Page 119: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCUIElementQueryHow do queries work?

Page 120: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCUIElementQueryHow do queries work?

Relationships

Page 121: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCUIElementQueryHow do queries work?

RelationshipsFiltering

Page 122: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCUIElementQueryExpressing relationships

Application

Navigation Bar

View

“Add” Button

Title Label

Table

Cell

“Tech Toys” Label

“Today” Label

“Groceries” Label

Cell

Cell

Page 123: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCUIElementQueryExpressing relationships

Descendants

Application

Navigation Bar

View

“Add” Button

Title Label

Table

Cell

“Tech Toys” Label

“Today” Label

“Groceries” Label

Cell

Cell

View

Table

Cell

“Tech ToysLabel

“Today” Label

“Groceries” Label

Cell

Cell

Page 124: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCUIElementQueryExpressing relationships

DescendantsChildren

Application

Navigation Bar

View

“Add” Button

Title Label

Table

Cell

“Tech Toys” Label

“Today” Label

“Groceries” Label

Cell

Cell

Page 125: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCUIElementQueryExpressing relationships

DescendantsChildren

Application

Navigation Bar

View

“Add” Button

Title Label

Table

Cell

“Tech Toys” Label

“Today” Label

“Groceries” Label

Cell

Cell

Table

Cell

Cell

Cell

Page 126: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCUIElementQueryExpressing relationships

DescendantsChildrenContainment

Application

Navigation Bar

View

“Add” Button

Title Label

Table

Cell

“Tech Toys” Label

“Today” Label

“Groceries” Label

Cell

Cell

Page 127: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCUIElementQueryExpressing relationships

DescendantsChildrenContainment

Application

Navigation Bar

View

“Add” Button

Title Label

Table

Cell

“Tech Toys” Label

“Today” Label

“Groceries” Label

Cell

Cell

Cell

“Groceries” Label

Page 128: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCUIElementQueryFiltering

Page 129: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCUIElementQueryFiltering

Element type• Button, table, menu, etc.

Page 130: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCUIElementQueryFiltering

Element type• Button, table, menu, etc.

Identifiers• Accessibility identifier, label, title, etc.

Page 131: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCUIElementQueryFiltering

Element type• Button, table, menu, etc.

Identifiers• Accessibility identifier, label, title, etc.

Predicates• Value, partial matching, etc.

Page 132: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Combining Relationships and FilteringdescendantsMatchingType()

Page 133: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Most common query

Combining Relationships and FilteringdescendantsMatchingType()

Page 134: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Most common query

let allButtons = app.

Combining Relationships and FilteringdescendantsMatchingType()

descendantsMatchingType(.Button)

Page 135: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Most common query

let allButtons = app.

let allCellsInTable = table.

Combining Relationships and FilteringdescendantsMatchingType()

descendantsMatchingType(.Button)

descendantsMatchingType(.Cell)

Page 136: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Most common query

let allButtons = app.

let allCellsInTable = table.

let allMenuItemsInMenu = menu.

Combining Relationships and FilteringdescendantsMatchingType()

descendantsMatchingType(.Button)

descendantsMatchingType(.Cell)

descendantsMatchingType(.MenuItem)

Page 137: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

descendantsMatchingType()

So common, we provide convenience API for each type

let allButtons = app.

let allCellsInTable = table.

let allMenuItemsInMenu = menu.

descendantsMatchingType(.Button)

descendantsMatchingType(.Cell)

descendantsMatchingType(.MenuItem)

Combining Relationships and Filtering

Page 138: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

descendantsMatchingType()

So common, we provide convenience API for each type

let allButtons = app.

let allCellsInTable = table.

let allMenuItemsInMenu = menu.

descendantsMatchingType(.Button)

descendantsMatchingType(.Cell)

descendantsMatchingType(.MenuItem)

Combining Relationships and Filtering

Page 139: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

descendantsMatchingType()

So common, we provide convenience API for each type

let allButtons = app.

let allCellsInTable = table.

let allMenuItemsInMenu = menu.

buttons

descendantsMatchingType(.Cell)

descendantsMatchingType(.MenuItem)

Combining Relationships and Filtering

Page 140: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

descendantsMatchingType()

So common, we provide convenience API for each type

let allButtons = app.

let allCellsInTable = table.

let allMenuItemsInMenu = menu.

buttons

descendantsMatchingType(.Cell)

descendantsMatchingType(.MenuItem)

Combining Relationships and Filtering

Page 141: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

descendantsMatchingType()

So common, we provide convenience API for each type

let allButtons = app.

let allCellsInTable = table.

let allMenuItemsInMenu = menu.

buttons

cells

descendantsMatchingType(.MenuItem)

Combining Relationships and Filtering

Page 142: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

descendantsMatchingType()

So common, we provide convenience API for each type

let allButtons = app.

let allCellsInTable = table.

let allMenuItemsInMenu = menu.

buttons

cells

descendantsMatchingType(.MenuItem)

Combining Relationships and Filtering

Page 143: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

descendantsMatchingType()

So common, we provide convenience API for each type

let allButtons = app.

let allCellsInTable = table.

let allMenuItemsInMenu = menu.

buttons

cells

menuItems

Combining Relationships and Filtering

Page 144: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Combining Relationships and FilteringchildrenMatchingType()

Page 145: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Combining Relationships and FilteringchildrenMatchingType()

Differentiates between any descendant and a direct child relationship

Page 146: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Combining Relationships and FilteringchildrenMatchingType()

Differentiates between any descendant and a direct child relationship

let allButtons = app.buttons // descendantsMatchingType(.Button)

Page 147: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Combining Relationships and FilteringchildrenMatchingType()

Differentiates between any descendant and a direct child relationship

let allButtons = app.buttons // descendantsMatchingType(.Button)

let childButtons = navBar.childrenMatchingType(.Button)

Page 148: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

containingType()Combining Relationships and Filtering

Page 149: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

containingType()Combining Relationships and Filtering

Find elements by describing their descendants

Page 150: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

containingType()Table

Cell

“Tech Toys” Label

“Today” Label

“Groceries” Label

Cell

Cell

Combining Relationships and Filtering

Find elements by describing their descendants

Page 151: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

containingType()Table

Cell

“Tech Toys” Label

“Today” Label

“Groceries” Label

Cell

Cell

Cell

Combining Relationships and Filtering

Find elements by describing their descendants

Page 152: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

containingType()

let cellQuery = cells.containingType(.StaticText, identifier:”Groceries”)

Table

Cell

“Tech Toys” Label

“Today” Label

“Groceries” Label

Cell

Cell

Cell

“Groceries” Label

Combining Relationships and Filtering

Find elements by describing their descendants

Page 153: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

containingType()

let cellQuery = cells.containingType(.StaticText, identifier:”Groceries”)

Table

Cell

“Tech Toys” Label

“Today” Label

“Groceries” Label

Cell

Cell

Cell

“Groceries” Label

Predicate variant also available

Combining Relationships and Filtering

Find elements by describing their descendants

Page 154: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

XCUIElementQueryCombining relationships and filtering

descendantsMatchingType() childrenMatchingType() containingType()

Page 155: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Combining Queries

Page 156: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Combining Queries

Queries can be “chained” together

Page 157: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Combining Queries

Queries can be “chained” togetherOutput of each query is the input of the next query

Page 158: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Combining Queries

Queries can be “chained” togetherOutput of each query is the input of the next query

Application

Navigation Bar

View

“Add” Button

Title Label

Table

Cell

“Tech Toys” Label

“Today” Label

“Groceries” Label

Cell

Cell

Page 159: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Combining Queries

Queries can be “chained” togetherOutput of each query is the input of the next query

Application

Navigation Bar

View

“Add” Button

Title Label

Table

Cell

“Tech Toys” Label

“Today” Label

“Groceries” Label

Cell

Cell

let labelsInTable = app

Application

Page 160: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Combining Queries

Queries can be “chained” togetherOutput of each query is the input of the next query

Application

Navigation Bar

View

“Add” Button

Title Label

Table

Cell

“Tech Toys” Label

“Today” Label

“Groceries” Label

Cell

Cell

let labelsInTable = app.tables

Application

Application

Page 161: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Combining Queries

Queries can be “chained” togetherOutput of each query is the input of the next query

Application

Navigation Bar

View

“Add” Button

Title Label

Table

Cell

“Tech Toys” Label

“Today” Label

“Groceries” Label

Cell

Cell

let labelsInTable = app.tables.staticTexts

Application

Application

Application

Application

Application

Page 162: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Getting Elements from Queries

Page 163: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Getting Elements from Queries

Subscripting table.staticTexts[“Groceries”]

Page 164: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Getting Elements from Queries

Subscripting table.staticTexts

Index table.staticTexts

[“Groceries”]

.elementAtIndex(0)

Page 165: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Getting Elements from Queries

Subscripting table.staticTexts

Index table.staticTexts

Unique app.navigationBars

[“Groceries”]

.elementAtIndex(0)

.element

Page 166: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Evaluating Queries

Page 167: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Evaluating Queries

Queries are evaluated on demand

Page 168: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Evaluating Queries

Queries are evaluated on demandXCUIElement• Synthesizing events• Reading property values

Page 169: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Evaluating Queries

Queries are evaluated on demandXCUIElement• Synthesizing events• Reading property values

XCUIElementQuery• Getting number of matches (.count)• Getting all matches (.allElementsBoundByAccessibilityElement)

Page 170: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Evaluating Queries

Queries are evaluated on demandXCUIElement• Synthesizing events• Reading property values

XCUIElementQuery• Getting number of matches (.count)• Getting all matches (.allElementsBoundByAccessibilityElement)

Re-evaluated when UI changes

Page 171: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Queries and ElementsSimilar to URLs

Page 172: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Queries and ElementsSimilar to URLs

Creating a URL does not fetch a resource

Page 173: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Queries and ElementsSimilar to URLs

Creating a URL does not fetch a resource• URL could be invalid, error raised when requested

Page 174: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Queries and ElementsSimilar to URLs

Creating a URL does not fetch a resource• URL could be invalid, error raised when requested

Queries and elements

Page 175: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Queries and ElementsSimilar to URLs

Creating a URL does not fetch a resource• URL could be invalid, error raised when requested

Queries and elements• Just a specification for accessible elements in the tested application

Page 176: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Queries and ElementsSimilar to URLs

Creating a URL does not fetch a resource• URL could be invalid, error raised when requested

Queries and elements• Just a specification for accessible elements in the tested application• Not resolved until needed

Page 177: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

API Recap

XCUIApplication

XCUIElement XCUIElementQuery

Page 178: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Accessibility and UI Testing

Page 179: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Accessibility and UI Testing

Page 180: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Accessibility and UI Testing

Accessibility data makes UI testing possible

Page 181: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Accessibility and UI Testing

Accessibility data makes UI testing possibleTe

stab

ility

Quality of Accessibility Data

Page 182: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Accessibility and UI TestingDebugging tips

Page 183: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Accessibility and UI Testing

Not accessible

Debugging tips

Page 184: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Accessibility and UI Testing

Not accessible• Custom view subclasses

Debugging tips

Page 185: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Accessibility and UI Testing

Not accessible• Custom view subclasses• Layers, sprites, and other graphics objects

Debugging tips

Page 186: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Accessibility and UI Testing

Not accessible• Custom view subclasses• Layers, sprites, and other graphics objects

Poor accessibility data

Debugging tips

Page 187: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Accessibility and UI Testing

Not accessible• Custom view subclasses• Layers, sprites, and other graphics objects

Poor accessibility dataTools

Debugging tips

Page 188: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Accessibility and UI Testing

Not accessible• Custom view subclasses• Layers, sprites, and other graphics objects

Poor accessibility dataTools• UI recording

Debugging tips

Page 189: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Accessibility and UI Testing

Not accessible• Custom view subclasses• Layers, sprites, and other graphics objects

Poor accessibility dataTools• UI recording• Accessibility inspectors

Debugging tips

Page 190: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Accessibility and UI TestingImproving data

Page 191: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Accessibility and UI Testing

Interface Builder inspector

Improving data

Page 192: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Accessibility and UI Testing

Interface Builder inspector

Improving data

Page 193: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Accessibility and UI Testing

Interface Builder inspectorAPI

Improving data

Page 194: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Accessibility and UI Testing

Interface Builder inspectorAPI• UIAccessibility (iOS)• NSAccessibility (OS X)

Improving data

Page 195: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Demo

Page 196: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

What Did You See?

Page 197: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

What Did You See?

Advanced UI testing

Page 198: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

What Did You See?

Advanced UI testingCorrecting queries

Page 199: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

What Did You See?

Advanced UI testingCorrecting queriesLooping over elements

Page 200: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

What Did You See?

Advanced UI testingCorrecting queriesLooping over elementsImproving accessibility

Page 201: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Test ReportsUI Refresh

Page 202: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Test Reports

Page 203: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Test Reports

Show results for all tests

Page 204: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Test Reports

Show results for all tests• Pass/fail

Page 205: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Test Reports

Show results for all tests• Pass/fail• Failure reason

Page 206: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Test Reports

Show results for all tests• Pass/fail• Failure reason• Performance metrics

Page 207: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Test Reports

Show results for all tests• Pass/fail• Failure reason• Performance metrics

Same UI in Xcode and in Xcode Server

Page 208: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Test Reports

Show results for all tests• Pass/fail• Failure reason• Performance metrics

Same UI in Xcode and in Xcode ServerPer-device results for Xcode Server

Page 209: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Test ReportsUI testing additions

Page 210: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Test ReportsUI testing additions

New data

Page 211: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Test ReportsUI testing additions

New dataScreenshots

Page 212: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Test ReportsUI testing additions

New dataScreenshotsNested activities

Page 213: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Test ReportsNested activities

Page 214: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Test Reports

UI testing APIs have several steps

Nested activities

Page 215: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Test Reports

UI testing APIs have several stepsTyping into a textfield

Nested activities

Page 216: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Test Reports

UI testing APIs have several stepsTyping into a textfield• Wait for the app to idle

Nested activities

Page 217: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Test Reports

UI testing APIs have several stepsTyping into a textfield• Wait for the app to idle• Evaluate the textfield query

Nested activities

Page 218: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Test Reports

UI testing APIs have several stepsTyping into a textfield• Wait for the app to idle• Evaluate the textfield query• Synthesize the text input

Nested activities

Page 219: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Test Reports

UI testing APIs have several stepsTyping into a textfield• Wait for the app to idle• Evaluate the textfield query• Synthesize the text input• Wait for the app to idle

Nested activities

Page 220: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Test Reports

UI testing APIs have several stepsTyping into a textfield• Wait for the app to idle• Evaluate the textfield query• Synthesize the text input• Wait for the app to idle

QuickLook for screenshots

Nested activities

Page 221: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Test Reports

UI testing APIs have several stepsTyping into a textfield• Wait for the app to idle• Evaluate the textfield query• Synthesize the text input• Wait for the app to idle

QuickLook for screenshots

Nested activities

Page 222: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

When to Use UI Testing

Page 223: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Using UI Testing

Page 224: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Using UI Testing

Complements unit testing

Page 225: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Using UI Testing

Complements unit testingUnit testing more precisely pinpoints failures

Page 226: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Using UI Testing

Complements unit testingUnit testing more precisely pinpoints failuresUI testing covers broader aspects of functionality

Page 227: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Using UI Testing

Complements unit testingUnit testing more precisely pinpoints failuresUI testing covers broader aspects of functionalityFind the right blend of UI tests and unit tests for your project

Page 228: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Candidates for UI Testing

Page 229: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Candidates for UI Testing

Demo sequences

Page 230: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Candidates for UI Testing

Demo sequencesCommon workflows

Page 231: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Candidates for UI Testing

Demo sequencesCommon workflowsCustom views

Page 232: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Candidates for UI Testing

Demo sequencesCommon workflowsCustom viewsDocument creation, saving, and opening

Page 233: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Summary

Page 234: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Summary

UI testing

Page 235: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Summary

UI testing• Find and interact with UI elements

Page 236: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Summary

UI testing• Find and interact with UI elements• Validate UI properties and state

Page 237: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Summary

UI testing• Find and interact with UI elements• Validate UI properties and state

UI recording

Page 238: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Summary

UI testing• Find and interact with UI elements• Validate UI properties and state

UI recordingTest reports

Page 239: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

More Information

Testing in Xcode Documentationhttp://developer.apple.com/testing

Accessibility for Developers Documentationhttp://developer.apple.com/accessibility

Apple Developer Forumshttp://developer.apple.com/forums

Stefan LesserDeveloper Tools [email protected]

Page 240: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Related Sessions

iOS Accessibility Pacific Heights Tuesday 9:00 AM

Continuous Integration and Code Coverage in Xcode Presidio Thursday 10:00 AM

Page 241: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility

Labs

Testing and Continuous Integration Developer Tools Lab B Wednesday 1:30 PM

Testing and Continuous Integration Developer Tools Lab B Thursday 1:30 PM

Page 242: UI Testing in Xcode - Apple Inc. › videos › wwdc › ...UI Testing Xcode Targets UI tests have special requirements • Execute in a separate process • Permission to use Accessibility