
Getting started with XCUITest

Hi,

I'm Shoban
Consultant


BabuShoban

in/BabuShoban

@BabuShoban
Agenda
-
What is XCUITest?
-
Downsides
-
My first Test
-
XCUITest API’s
-
Waiting Strategy
-
Gestures
-
Parallels
-
CI Integration
-
Q & A

What is XCUITest?




Swift

Why XCUITest?

Cons
XCTest vs XCUITest



My First XCUITest
import XCTest
class MyFirstTestcase: XCTestCase {
let app = XCUIApplication()
override func setUp() {
super.setUp()
continueAfterFailure = false
app.launch()
}
func testExample() throws {
app.staticTexts["View Schedule"].tap()
app.buttons["Finish Game"].tap()
XCTAssert(app.alerts["You won!"].exists)
app.alerts["You won!"].buttons["Awesome!"].tap()
}
override func tearDown() {
app.terminate()
}
}
Demo

XCUITest API's
XCUIApplication
XCUIElement
XCUIElementQuery

Execution Workflow
XCUIApplication
XCUIElementQuery
XCUIElement
XCUIElementQuery
XCUIApplication
Launch App
Find Elements on Screen
Interact elements on Screen
Assert expectation
Kill App
API Demo
Waiting Strategy
XCUIElement.waitForExistence(timeout:)
XCTestCase.expectation(for:evaluatedWith:handler:)
XCTestCase.waitForExpectations(timeout:handler:)
Thread.sleep(forTimeInterval:)
expectation(
for: NSPredicate(format: "exists == true"),
evaluatedWith: app.buttons["identifier"],
handler: .none
)
waitForExpectations(timeout: 5)

Gestures
tap()
doubleTap()
twoFingerTap()
tap(withNumberOfTaps:numberOfTouches:)
press(forDuration)
swipeLeft(), swipeRight(), swipeUp(), swipeDown()
pinch(withScale:velocity:)
rotate(_: withVelocity:)
adjust(toPickerWheelValue: 1)
adjust(toNormalizedSliderPosition: 0.5)
Parallel Testing with XCUITest
CI Integration

+

