Skip to content

Commit ff11cd0

Browse files
committed
Add tap(withNormalizedOffset:) and CGVector extensions
1 parent 1a1babf commit ff11cd0

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Utilities for easier interaction with XCUITest methods.
2727
- `tapWhenReady()`
2828
- `waitForInteractivity()`
2929
- `slowTypeText("text")`
30+
- `tap(withNormalizedOffset: .center)`
3031

3132
- `XCUIApplication` extensions:
3233
- Accessing other apps:
@@ -42,7 +43,13 @@ Utilities for easier interaction with XCUITest methods.
4243
- `assertHasCount(2)`
4344
- `assertNotExists()`
4445

45-
All of the above have optional message as last parameter that can be used to configure what is displayed if assertion fails. For example: `element.assertExists("My element should be visible")`.
46+
- `CGVector` extensions:
47+
- Normalized offsets:
48+
- `topLeft`, `top`, `topRight`
49+
- `left`, `center`, `right`
50+
- `bottomLeft`, `bottom`, `bottomRight`
51+
52+
All of the above assertion functions have optional message as last parameter that can be used to configure what is displayed if assertion fails. For example: `element.assertExists("My element should be visible")`.
4653

4754
## Example
4855

@@ -52,7 +59,7 @@ Note that some of the buttons are identified by enum case instead of raw string.
5259

5360
```swift
5461
func testOpenClosePremiumScreen() throws {
55-
try launch(configuration: .init(premiumUnlocked: false)) // TODO: Add tip about helper launch configurations
62+
try launch(configuration: .init(premiumUnlocked: false))
5663

5764
app.buttons[.toggleBottomSheetButton].tap()
5865
app.buttons["Unlock Premium"].tapWhenReady()
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import Foundation
2+
3+
extension CGVector {
4+
/// Normalized offset to view's top left coordinate.
5+
public static let topLeft: CGVector = CGVector(dx: 0, dy: 0)
6+
7+
/// Normalized offset to view's top center coordinate.
8+
public static let top: CGVector = CGVector(dx: 0.5, dy: 0)
9+
10+
/// Normalized offset to view's top right coordinate.
11+
public static let topRight: CGVector = CGVector(dx: 1, dy: 0)
12+
13+
/// Normalized offset to view's center left coordinate.
14+
public static let left: CGVector = CGVector(dx: 0, dy: 0.5)
15+
16+
/// Normalized offset to view's center coordinate.
17+
public static let center: CGVector = CGVector(dx: 0.5, dy: 0.5)
18+
19+
/// Normalized offset to view's center right coordinate.
20+
public static let right: CGVector = CGVector(dx: 1, dy: 0.5)
21+
22+
/// Normalized offset to view's bottom left coordinate.
23+
public static let bottomLeft: CGVector = CGVector(dx: 0, dy: 1)
24+
25+
/// Normalized offset to view's bottom center coordinate.
26+
public static let bottom: CGVector = CGVector(dx: 0.5, dy: 1)
27+
28+
/// Normalized offset to view's bottom right coordinate.
29+
public static let bottomRight: CGVector = CGVector(dx: 1, dy: 1)
30+
}

Sources/XCAppTest/XCUIElement+Actions.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,14 @@ extension XCUIElement {
6060
}
6161
return self
6262
}
63+
64+
/// Taps the element at normalized offset from its origin.
65+
///
66+
/// - Parameter normalizedOffset: The normalized offset.
67+
/// - Returns: Unmodified UI element.
68+
@discardableResult
69+
public func tap(withNormalizedOffset normalizedOffset: CGVector) -> Self {
70+
self.coordinate(withNormalizedOffset: normalizedOffset).tap()
71+
return self
72+
}
6373
}

0 commit comments

Comments
 (0)