Skip to content

Commit 4050c52

Browse files
Add 'waitFor' and deprecate 'await' (#152)
* Add 'waitFor' and deprecate 'await' * Update TABTestKit/Classes/Protocols/Element.swift Co-authored-by: Riccardo Cipolleschi <[email protected]> * [Project] Update CI yml file * [Project] Update CI yml file * Update ci.yml * [Project] Update podspec version * [Project] Update changelog * [Project] Update readme Co-authored-by: Riccardo Cipolleschi <[email protected]>
1 parent 77bdc69 commit 4050c52

File tree

15 files changed

+173
-52
lines changed

15 files changed

+173
-52
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
jobs:
1010
test_xcode10_ios12:
1111
name: Run tests on Xcode 10 and iOS 12
12-
runs-on: macOS-latest
12+
runs-on: macos-10.15
1313

1414
steps:
1515
- name: Checkout
@@ -54,17 +54,17 @@ jobs:
5454
steps:
5555
- name: Checkout
5656
uses: actions/checkout@v1
57-
- name: Set Xcode version to 12.1
58-
run: sudo xcode-select -switch /Applications/Xcode_12.1.app
57+
- name: Set Xcode version to 12.5
58+
run: sudo xcode-select -switch /Applications/Xcode_12.5.app
5959
- name: Build for testing
60-
run: xcodebuild build-for-testing -workspace Example/TABTestKit.xcworkspace -scheme TABTestKit-Example -destination 'platform=iOS Simulator,name=iPhone 11,OS=14.1'
61-
- name: Test on iPhone 11
62-
run: xcodebuild test-without-building -workspace Example/TABTestKit.xcworkspace -scheme TABTestKit-Example -destination 'platform=iOS Simulator,name=iPhone 11,OS=14.1'
60+
run: xcodebuild build-for-testing -workspace Example/TABTestKit.xcworkspace -scheme TABTestKit-Example -destination 'platform=iOS Simulator,name=iPhone 12,OS=14.5'
61+
- name: Test on iPhone 12
62+
run: xcodebuild test-without-building -workspace Example/TABTestKit.xcworkspace -scheme TABTestKit-Example -destination 'platform=iOS Simulator,name=iPhone 12,OS=14.5'
6363
- name: Archive tests results
6464
if: ${{ failure() }}
6565
uses: actions/upload-artifact@v2
6666
with:
67-
name: Test-TABTestKit-Xcode12.1-iOS14.xcresult
67+
name: Test-TABTestKit-Xcode12-iOS14.xcresult
6868
path: /Users/runner/Library/Developer/Xcode/DerivedData/*/Logs/Test/*.xcresult
6969

7070
build_spm:
@@ -78,14 +78,14 @@ jobs:
7878
run: sudo xcode-select -switch /Applications/Xcode_11.7.app
7979
- name: Build Swift Package Manager
8080
run: xcodebuild -workspace package.xcworkspace -scheme TABTestKit -destination 'platform=iOS Simulator,name=iPhone 11,OS=13.7'
81-
- name: Set Xcode version to 12.1
82-
run: sudo xcode-select -switch /Applications/Xcode_12.1.app
81+
- name: Set Xcode version to 12.5
82+
run: sudo xcode-select -switch /Applications/Xcode_12.5.app
8383
- name: Build Swift Package Manager
84-
run: xcodebuild -workspace package.xcworkspace -scheme TABTestKit -destination 'platform=iOS Simulator,name=iPhone 11,OS=14.1'
84+
run: xcodebuild -workspace package.xcworkspace -scheme TABTestKit -destination 'platform=iOS Simulator,name=iPhone 12,OS=14.5'
8585

8686
build_carthage:
8787
name: Ensure Carthage builds
88-
runs-on: macOS-latest
88+
runs-on: macos-10.15
8989

9090
steps:
9191
- name: Checkout
@@ -105,7 +105,7 @@ jobs:
105105

106106
build_cocoapods:
107107
name: Ensure Cocoapods builds
108-
runs-on: macOS-latest
108+
runs-on: macos-10.15
109109

110110
steps:
111111
- name: Checkout

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# CHANGELOG
22

3-
## Pending
3+
## 1.8.0
44

5+
- Obsoleted the `await` function in Swift 5.5 and added a `waitFor` function because using `await` in Swift 5.5 will lead to ambiguity errors with the `await` keyword. No code changes are required for clients, unless they're on Swift 5.5 and are calling the `await` function in their code. In that case, they will need to update it to `waitFor`.
56
- Upgraded GitHub actions:
67
- Added Xcode 12.1 as part of the job for validating SwiftPM, Carthage and Cocoapods
78
- Temporary allow Cocoapods to valid a library with warning for Xcode 12

README.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ struct ProfileScreen: Screen {
383383

384384
A `Screen` has one required property for you to implement, which is its `trait`. A
385385
`trait` can be any [Element](#elements) that consistently, and uniquely,
386-
identifies the screen, and is used to `await` for it to appear on-screen during tests when using [contexts](#contexts).
386+
identifies the screen, and is used to `await`/`waitFor` for it to appear on-screen during tests when using [contexts](#contexts).
387387

388388
#### Elements
389389

@@ -411,11 +411,19 @@ struct ProfileScreen: Screen {
411411
Once you've created your screen, you can use it in tests to interact with the elements:
412412

413413
```swift
414+
// If using Swift 5.4 or below
414415
let profileScreen = ProfileScreen()
415416
profileScreen.await() // Makes sure the screen is visible before going any further by waiting for its trait
416417
profileScreen.logOutButton.tap() // You can't call tap on an element that isn't `Tappable`, but `Button` is!
417418
```
418419

420+
```swift
421+
// If using Swift 5.5
422+
let profileScreen = ProfileScreen()
423+
profileScreen.waitFor() // Makes sure the screen is visible before going any further by waiting for its trait
424+
profileScreen.logOutButton.tap() // You can't call tap on an element that isn't `Tappable`, but `Button` is!
425+
```
426+
419427
All elements conform to the [`Element`](#element) protocol, which ensures that every element
420428
has a parent element (defaults to the `App`), underlying `type`, `index` (defaults to `0`),
421429
and has an optional ID.
@@ -822,9 +830,15 @@ you can use anywhere in your tests called `keyboard`.
822830
This is useful for a number of things, like checking if the keyboard is visible:
823831

824832
```swift
833+
// If using Swift 5.4 or below
825834
keyboard.await(.visible)
826835
```
827836

837+
```swift
838+
// If using Swift 5.5
839+
keyboard.waitFor(.visible)
840+
```
841+
828842
Checking if the current softare keyboard is the expected type:
829843

830844
```swift
@@ -1047,10 +1061,16 @@ You can, however, assert the states of the buttons, like checking if the buttons
10471061
enabled:
10481062

10491063
```swift
1064+
// If using Swift 5.4 or below
10501065
stepper.decrementButton.await(not: .enabled, timeout: 1) // Waits a max of 1 second for the button to be disabled
10511066
```
10521067

1053-
You can learn more about `await(not:)` and other `Element` methods in the
1068+
```swift
1069+
// If using Swift 5.5
1070+
stepper.decrementButton.waitFor(not: .enabled, timeout: 1) // Waits a max of 1 second for the button to be disabled
1071+
```
1072+
1073+
You can learn more about `await(not:)`/`waitFor(not:)` and other `Element` methods in the
10541074
documentation for [`Element`](#element).
10551075

10561076
#### SegmentedControl
@@ -1724,10 +1744,17 @@ that anything conforming to `Element` will have access to.
17241744
You can wait for the element to be (or not be) in a particular state:
17251745

17261746
```swift
1747+
// If using Swift 5.4 or below
17271748
button.await(.visible, .enabled, timeout: 10) // You can provide more than one state to wait for :)
17281749
button.await(not: .enabled, timeout: 10)
17291750
```
17301751

1752+
```swift
1753+
// If using Swift 5.5
1754+
button.waitFor(.visible, .enabled, timeout: 10) // You can provide more than one state to wait for :)
1755+
button.waitFor(not: .enabled, timeout: 10)
1756+
```
1757+
17311758
If the element doesn't become the expected state within the timeout, the test will fail.
17321759

17331760
If you're not using **TABTestKit** [contexts](#contexts), it is extremely advisable to

TABTestKit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'TABTestKit'
3-
s.version = '1.7.1'
3+
s.version = '1.8.0'
44
s.summary = 'Strongly typed Swift wrapper around XCTest / XCUI, enabling you to write BDD-style automation tests, without writing much code at all.'
55
s.homepage = 'https://github.com/theappbusiness/TABTestKit'
66
s.license = { :type => 'MIT', :file => 'LICENSE' }

TABTestKit/Classes/Contexts/InteractionContext.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,19 @@ public extension InteractionContext {
3535
}
3636

3737
func state(of element: Element, is states: ElementAttributes.State...) {
38-
states.forEach { element.await($0) }
38+
#if swift(>=5.5)
39+
states.forEach { element.waitFor($0) }
40+
#else
41+
states.forEach { element.await($0) }
42+
#endif
3943
}
4044

4145
func state(of element: Element, isNot states: ElementAttributes.State...) {
42-
states.forEach { element.await(not: $0) }
46+
#if swift(>=5.5)
47+
states.forEach { element.waitFor(not: $0) }
48+
#else
49+
states.forEach { element.await(not: $0) }
50+
#endif
4351
}
4452

4553
func scroll(_ element: Scrollable, _ direction: ElementAttributes.Direction, until otherElement: Element, is states: ElementAttributes.State..., maxTries: Int = 10) {

TABTestKit/Classes/Contexts/NavigationContext.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,22 @@ public extension NavigationContext {
2828
///
2929
/// - Parameter element: The element to await.
3030
func see(_ element: Element) {
31-
element.await(.exists, .visible)
31+
#if swift(>=5.5)
32+
element.waitFor(.exists, .visible)
33+
#else
34+
element.await(.exists, .visible)
35+
#endif
3236
}
3337

3438
/// Asserts that an element does not exist, by waiting for it to not exist.
3539
///
3640
/// - Parameter element: The element to await.
3741
func doNotSee(_ element: Element) {
38-
element.await(not: .exists)
42+
#if swift(>=5.5)
43+
element.waitFor(not: .exists)
44+
#else
45+
element.await(not: .exists)
46+
#endif
3947
}
4048

4149
/// Completes one or more things that knows how to complete itself.

TABTestKit/Classes/Elements/Keyboard.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ public struct Keyboard: Element {
3434
/// The current keyboard type.
3535
/// Attempting to access this before the keyboard is visible will fail the test.
3636
public var keyboardType: KeyboardType {
37-
await(.exists, .visible)
37+
#if swift(>=5.5)
38+
waitFor(.exists, .visible)
39+
#else
40+
await(.exists, .visible)
41+
#endif
3842
guard let type = KeyboardType.allCases.first(where: expectedKeysExist) else { XCTFatalFail("Unable to determine keyboard type") }
3943
return type
4044
}

TABTestKit/Classes/Elements/TabBar.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ public struct TabBar: Element {
4545
extension TabBar {
4646

4747
public var numberOfTabs: Int {
48-
await(.exists, .hittable)
48+
#if swift(>=5.5)
49+
waitFor(.exists, .hittable)
50+
#else
51+
await(.exists, .hittable)
52+
#endif
4953
return underlyingXCUIElement.buttons.count
5054
}
5155

TABTestKit/Classes/Protocols/Completable.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import Foundation
1313
///
1414
/// This works particularly well with NavigationContext.
1515
public protocol Completable {
16-
16+
1717
func await()
1818
func complete()
19-
19+
2020
}

TABTestKit/Classes/Protocols/Dismissable.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ public protocol Dismissable {
2222
public extension Element where Self: Dismissable {
2323

2424
func await() {
25-
await(.exists, .hittable)
25+
#if swift(>=5.5)
26+
waitFor(.exists, .hittable)
27+
#else
28+
await(.exists, .hittable)
29+
#endif
2630
}
2731

2832
}

0 commit comments

Comments
 (0)