Skip to content

Commit a1b038e

Browse files
committed
Replace \n by a space when searching for texts
1 parent 9b0751f commit a1b038e

File tree

4 files changed

+42
-7
lines changed

4 files changed

+42
-7
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1010

1111
### Removed
1212

13+
## [0.1.6](https://github.com/openium/SwiftiumTestingKit/compare/latest...HEAD)
14+
### Added
15+
16+
### Changed
17+
Fixed search for text containing \n
18+
19+
### Removed
20+
1321
## [0.1.5](https://github.com/openium/SwiftiumTestingKit/compare/latest...HEAD)
1422
### Added
1523

STKTestAppTests/STKSoloTests.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,24 @@ class STKSoloTests: XCTestCase {
3838
XCTAssertTrue(foundTestText)
3939
}
4040

41+
func testWaitForText_shouldFindWhitespacedLabelTest() {
42+
// Given
43+
let texts = ["Some \n text", "Some \t text"]
44+
var foundTestTexts = [String: Bool]()
45+
sut.showViewControllerInCleanWindow(viewController)
46+
47+
// When
48+
for text in texts {
49+
viewController.topLabel.text = text
50+
51+
foundTestTexts[text] = sut.waitFor(text: text)
52+
}
53+
54+
// Expect
55+
XCTAssertTrue(foundTestTexts[texts[0]] ?? false)
56+
XCTAssertTrue(foundTestTexts[texts[1]] ?? false)
57+
}
58+
4159
func testWaitForText_shouldFindLabelTestUsingPrefix() {
4260
// Given
4361
sut.showViewControllerInCleanWindow(viewController)

SwiftiumTestingKit/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>0.1.5</string>
18+
<string>0.1.6</string>
1919
<key>CFBundleVersion</key>
2020
<string>$(CURRENT_PROJECT_VERSION)</string>
2121
</dict>

SwiftiumTestingKit/STKSolo.swift

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,23 +110,31 @@ public class STKSolo: NSObject {
110110
return element
111111
}
112112

113+
public func accessibilityCleaned(text: String) -> String {
114+
return text.replacingOccurrences(of: "\n", with: " ")
115+
}
116+
113117
public func waitFor(text: String) -> Bool {
114-
let element = waitForAccessibilityElement { $0.accessibilityLabel == text }
118+
let cleanedText = accessibilityCleaned(text: text)
119+
let element = waitForAccessibilityElement { $0.accessibilityLabel == cleanedText }
115120
return element != nil
116121
}
117122

118123
public func waitFor(textWithPrefix prefix: String) -> Bool {
119-
let element = waitForAccessibilityElement { $0.accessibilityLabel?.hasPrefix(prefix) ?? false }
124+
let cleanedText = accessibilityCleaned(text: prefix)
125+
let element = waitForAccessibilityElement { $0.accessibilityLabel?.hasPrefix(cleanedText) ?? false }
120126
return element != nil
121127
}
122128

123129
public func waitFor(textWithSuffix suffix: String) -> Bool {
124-
let element = waitForAccessibilityElement { $0.accessibilityLabel?.hasSuffix(suffix) ?? false }
130+
let cleanedText = accessibilityCleaned(text: suffix)
131+
let element = waitForAccessibilityElement { $0.accessibilityLabel?.hasSuffix(cleanedText) ?? false }
125132
return element != nil
126133
}
127134

128135
public func waitFor(tappableText: String, andTapIt: Bool) -> Bool {
129-
let element = waitForAccessibilityElement { $0.accessibilityLabel == tappableText }
136+
let cleanedText = accessibilityCleaned(text: tappableText)
137+
let element = waitForAccessibilityElement { $0.accessibilityLabel == cleanedText }
130138
if let element = element {
131139
if let view = try? UIAccessibilityElement.viewContaining(element, tappable: true) {
132140
testActor.tap(element, in: view)
@@ -139,10 +147,11 @@ public class STKSolo: NSObject {
139147

140148
public func waitFor(textToBecomeInvalid: String) -> Bool {
141149
var textBecameInvalid = false
142-
let element = waitForAccessibilityElement { $0.accessibilityLabel == textToBecomeInvalid }
150+
let cleanedText = accessibilityCleaned(text: textToBecomeInvalid)
151+
let element = waitForAccessibilityElement { $0.accessibilityLabel == cleanedText }
143152
if element != nil {
144153
lastExceptions.removeAll()
145-
testActor.waitForAbsenceOfView(withAccessibilityLabel: textToBecomeInvalid)
154+
testActor.waitForAbsenceOfView(withAccessibilityLabel: cleanedText)
146155
if lastExceptions.isEmpty {
147156
textBecameInvalid = true
148157
}

0 commit comments

Comments
 (0)