Skip to content

Instantly share code, notes, and snippets.

@bartekpacia
Last active October 14, 2022 07:04
Show Gist options
  • Save bartekpacia/8cea37646bc6197a4bbdf6fbcbb5b83e to your computer and use it in GitHub Desktop.
Save bartekpacia/8cea37646bc6197a4bbdf6fbcbb5b83e to your computer and use it in GitHub Desktop.
Exploring what's possible with NSPredicate.
import XCTest
final class LandmarksUITests: XCTestCase {
let app = XCUIApplication()
override func setUpWithError() throws {
continueAfterFailure = false
app.launch()
}
func testNormal() throws {
let element = app.descendants(matching: .any)["Turtle Rock"]
element.firstMatch.tap()
}
func testPredicates() throws {
let element = app.descendants(matching: .any).matching(NSPredicate(format: "label == 'Turtle Rock'"))
element.firstMatch.tap()
}
func testTextFieldNormal() throws {
let element = app.textFields["username"]
element.firstMatch.tap()
element.firstMatch.typeText("hello")
}
func testStaticTextPredicate() throws {
let element = app.descendants(matching: .any).element(matching: (NSPredicate(format: "label == 'Turtle Rock'")))
element.firstMatch.tap()
}
func testTextFieldNormal2() throws {
let element = app.descendants(matching: .any).element(matching: (NSPredicate(format: "placeholderValue == 'username'")))
element.firstMatch.tap()
element.firstMatch.typeText("hello")
}
func testTextFieldNormal3() throws {
// see https://developer.apple.com/documentation/xctest/xcuielementtype/xcuielementtypetextfield
let element = app.descendants(matching: .any).element(matching: (NSPredicate(format: "elementType == 49")))
element.firstMatch.tap()
element.firstMatch.typeText("hello")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment