ProductPromotion
Logo

Swift

made by https://0x3d.site

GitHub - joemasilotti/UI-Testing-Cheat-Sheet: How do I test this with UI Testing?
How do I test this with UI Testing? Contribute to joemasilotti/UI-Testing-Cheat-Sheet development by creating an account on GitHub.
Visit Site

GitHub - joemasilotti/UI-Testing-Cheat-Sheet: How do I test this with UI Testing?

GitHub - joemasilotti/UI-Testing-Cheat-Sheet: How do I test this with UI Testing?

UI Testing Cheat Sheet

This repository is complementary code for my post, UI Testing Cheat Sheet and Examples. The post goes into more detail with example images for most examples.

The included project highlights working code with a simple Test Host. This was last updated for Swift 5 on Xcode 11.4.1.

Contents

Basic Functionality

Testing if an element exists

XCTAssert(app.staticTexts["Welcome"].exists)

Testing if text with an ellipsis exists

A full text match will find an element even if the displayed text has an ellipsis due to truncation.

let longNameCell = app.staticTexts["Adolph Blaine Charles David Earl Frederick Gerald Hubert Irvin John Kenneth Lloyd Martin Nero Oliver Paul Quincy Randolph Sherman Thomas Uncas Victor William Xerxes Yancy Wolfeschlegelsteinhausenbergerdorff, Senior"]
XCTAssert(longNameCell.exists) // displayed text is "Adolph Blaine Charles David Earl Freder..."

Waiting for an element to appear

"Waiting" is now built into XCTest.

let goLabel = app.staticTexts["Go!"]
XCTAssertFalse(goLabel.exists)

app.buttons["Ready, set..."].tap()
XCTAssert(goLabel.waitForExistence(timeout: 5))

Interacting with System Controls

Tapping buttons

Identify buttons by their accessibility label.

app.buttons["Add"].tap()

Typing text

First make sure the text field has focus by tapping on it.

let textField = app.textFields["Username"]
textField.tap()
textField.typeText("joemasilotti")

Dismissing alerts

app.alerts["Alert Title"].buttons["Button Title"].tap()

Dismissing action sheets

app.sheets["Sheet Title"].buttons["Button Title"].tap()

Handling system alerts

Present a location services authorization dialog to the user and dismiss it with the following code.

Before presenting the alert add a UI Interruption Handler. When this fires, dismiss with the "Allow" button.

addUIInterruptionMonitor(withDescription: "Location Services") { (alert) -> Bool in
  alert.buttons["Allow"].tap()
  return true
}

app.buttons["Request Location"].tap()
app.tap() // need to interact with the app again for the handler to fire

Sliding sliders

This will slide the value of the slider to 70%.

app.sliders.element.adjust(toNormalizedSliderPosition: 0.7)

Interacting with pickers

A picker with one wheel:

app.pickerWheels.element.adjust(toPickerWheelValue: "Picker Wheel Item Title")

A picker with multiple wheels. Make sure to set the accessibility delegate so the framework can identify the different wheels.

let firstPredicate = NSPredicate(format: "label BEGINSWITH 'First Picker'")
let firstPicker = app.pickerWheels.element(matching: firstPredicate)
firstPicker.adjust(toPickerWheelValue: "first value")

let secondPredicate = NSPredicate(format: "label BEGINSWITH 'Second Picker'")
let secondPicker = app.pickerWheels.element(matching: secondPredicate)
secondPicker.adjust(toPickerWheelValue: "second value")

Tapping links in web views

app.links["Tweet this"].tap()

Interactions

Verifying the current controller's title

XCTAssert(app.navigationBars["Details"].exists)

Reordering table cells

If you have a UITableViewCell with default style and set the text to "Title", the reorder control's accessibility label becomes "Reorder Title".

Using this we can drag one reorder control to another, essentially reordering the cells.

let topButton = app.buttons["Reorder Top Cell"]
let bottomButton = app.buttons["Reorder Bottom Cell"]
bottomButton.press(forDuration: 0.5, thenDragTo: topButton)

XCTAssertLessThanOrEqual(bottomButton.frame.maxY, topButton.frame.minY)

Pull to refresh

Create a XCUICoordinate from the first cell in your table and another one with a dy of six. Then drag the first coordinate to the second.

let firstCell = app.staticTexts["Adrienne"]
let start = firstCell.coordinate(withNormalizedOffset: (CGVectorMake(0, 0))
let finish = firstCell.coordinate(withNormalizedOffset: (CGVectorMake(0, 10))
start.press(forDuration: 0, thenDragTo: finish)

Pushing and popping view controllers

Test if a view controller was pushed onto the navigation stack.

app.buttons["More Info"].tap()
XCTAssert(app.navigationBars["Volleyball?"].exists)

Pop a view controller by tapping the back button in the navigation bar and assert that the title in the navigation bar has changed.

app.navigationBars.buttons.elementBoundByIndex(0).tap()
XCTAssert(app.navigationBars["Volley"].exists)

More Resources
to explore the angular.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here ๐Ÿ”.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory