Skip to content

Commit 5424ce9

Browse files
committed
Add tapWhenReady
1 parent 2ee3261 commit 5424ce9

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Utilities for easier interaction with XCUITest methods.
77
- `XCUIElement` extensions:
88
- Checking existence of elements:
99
- `assertExists()`
10+
- `assertExists(waitForAppToIdle: true)`
1011
- `assertNotExists()`
1112
- Checking interactivity of elements:
1213
- `assertIsHittable()`
@@ -22,9 +23,9 @@ Utilities for easier interaction with XCUITest methods.
2223
- Checking traits of elements:
2324
- `assertIsSelected()`
2425
- `assertIsNotSelected()`
25-
- Waiting for interactivity:
26+
- Performing actions:
27+
- `tapWhenReady()`
2628
- `waitForInteractivity()`
27-
- `assertExists(waitForAppToIdle: true)`
2829
- `XCUIApplication` extensions:
2930
- Accessing other apps:
3031
- `XCUIApplication.safari`
@@ -51,7 +52,7 @@ func testOpenClosePremiumScreen() throws {
5152
try launch(configuration: .init(premiumUnlocked: false)) // TODO: Add tip about helper launch configurations
5253

5354
app.buttons[.toggleBottomSheetButton].tap()
54-
app.buttons["Unlock Premium"].waitForInteractivity().tap()
55+
app.buttons["Unlock Premium"].tapWhenReady()
5556
assertPremiumScreenIsVisible()
5657
app.buttons[.unlockFeaturesButton].assertIsEnabled().assertContainsText("Lifetime access")
5758
app.buttons["Restore Purchase"].assertIsEnabled()

Sources/XCAppTest/XCUIElement+App.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ extension XCUIElement {
306306
return self
307307
}
308308

309-
// MARK: - Waiting for interactivity
309+
// MARK: - Performing actions
310310

311311
/// Waits for the element to exist, be hittable and enabled.
312312
///
@@ -325,4 +325,22 @@ extension XCUIElement {
325325
assertIsInteractive(message(), file: file, line: line)
326326
return self
327327
}
328+
329+
/// Waits for the element to exist and become interactive, then taps on it.
330+
///
331+
/// - Parameters:
332+
/// - message: An optional description of a failure.
333+
/// - file: The file where the failure occurs. The default is the filename of the test case where you call this function.
334+
/// - line: The line number where the failure occurs. The default is the line number where you call this function.
335+
/// - Returns: Unmodified UI element.
336+
@discardableResult
337+
public func tapWhenReady(
338+
_ message: @autoclosure () -> String? = nil,
339+
file: StaticString = #file,
340+
line: UInt = #line
341+
) -> Self {
342+
waitForInteractivity(message(), file: file, line: line)
343+
tap()
344+
return self
345+
}
328346
}

0 commit comments

Comments
 (0)