diff --git a/CHANGELOG.md b/CHANGELOG.md
index 73da0d8..78fcd14 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,14 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Removed
+## [0.1.6](https://github.com/openium/SwiftiumTestingKit/compare/latest...HEAD)
+### Added
+
+### Changed
+Fixed search for text containing \n
+
+### Removed
+
## [0.1.5](https://github.com/openium/SwiftiumTestingKit/compare/latest...HEAD)
### Added
diff --git a/STKTestAppTests/STKSoloTests.swift b/STKTestAppTests/STKSoloTests.swift
index 633a496..b8792e8 100644
--- a/STKTestAppTests/STKSoloTests.swift
+++ b/STKTestAppTests/STKSoloTests.swift
@@ -38,6 +38,24 @@ class STKSoloTests: XCTestCase {
XCTAssertTrue(foundTestText)
}
+ func testWaitForText_shouldFindWhitespacedLabelTest() {
+ // Given
+ let texts = ["Some \n text", "Some \t text"]
+ var foundTestTexts = [String: Bool]()
+ sut.showViewControllerInCleanWindow(viewController)
+
+ // When
+ for text in texts {
+ viewController.topLabel.text = text
+
+ foundTestTexts[text] = sut.waitFor(text: text)
+ }
+
+ // Expect
+ XCTAssertTrue(foundTestTexts[texts[0]] ?? false)
+ XCTAssertTrue(foundTestTexts[texts[1]] ?? false)
+ }
+
func testWaitForText_shouldFindLabelTestUsingPrefix() {
// Given
sut.showViewControllerInCleanWindow(viewController)
diff --git a/SwiftiumTestingKit/Info.plist b/SwiftiumTestingKit/Info.plist
index 988df68..c7dc30b 100644
--- a/SwiftiumTestingKit/Info.plist
+++ b/SwiftiumTestingKit/Info.plist
@@ -15,7 +15,7 @@
CFBundlePackageType
FMWK
CFBundleShortVersionString
- 0.1.5
+ 0.1.6
CFBundleVersion
$(CURRENT_PROJECT_VERSION)
diff --git a/SwiftiumTestingKit/STKSolo.swift b/SwiftiumTestingKit/STKSolo.swift
index b458213..c615375 100644
--- a/SwiftiumTestingKit/STKSolo.swift
+++ b/SwiftiumTestingKit/STKSolo.swift
@@ -110,23 +110,31 @@ public class STKSolo: NSObject {
return element
}
+ public func accessibilityCleaned(text: String) -> String {
+ return text.replacingOccurrences(of: "\n", with: " ")
+ }
+
public func waitFor(text: String) -> Bool {
- let element = waitForAccessibilityElement { $0.accessibilityLabel == text }
+ let cleanedText = accessibilityCleaned(text: text)
+ let element = waitForAccessibilityElement { $0.accessibilityLabel == cleanedText }
return element != nil
}
public func waitFor(textWithPrefix prefix: String) -> Bool {
- let element = waitForAccessibilityElement { $0.accessibilityLabel?.hasPrefix(prefix) ?? false }
+ let cleanedText = accessibilityCleaned(text: prefix)
+ let element = waitForAccessibilityElement { $0.accessibilityLabel?.hasPrefix(cleanedText) ?? false }
return element != nil
}
public func waitFor(textWithSuffix suffix: String) -> Bool {
- let element = waitForAccessibilityElement { $0.accessibilityLabel?.hasSuffix(suffix) ?? false }
+ let cleanedText = accessibilityCleaned(text: suffix)
+ let element = waitForAccessibilityElement { $0.accessibilityLabel?.hasSuffix(cleanedText) ?? false }
return element != nil
}
public func waitFor(tappableText: String, andTapIt: Bool) -> Bool {
- let element = waitForAccessibilityElement { $0.accessibilityLabel == tappableText }
+ let cleanedText = accessibilityCleaned(text: tappableText)
+ let element = waitForAccessibilityElement { $0.accessibilityLabel == cleanedText }
if let element = element {
if let view = try? UIAccessibilityElement.viewContaining(element, tappable: true) {
testActor.tap(element, in: view)
@@ -139,10 +147,11 @@ public class STKSolo: NSObject {
public func waitFor(textToBecomeInvalid: String) -> Bool {
var textBecameInvalid = false
- let element = waitForAccessibilityElement { $0.accessibilityLabel == textToBecomeInvalid }
+ let cleanedText = accessibilityCleaned(text: textToBecomeInvalid)
+ let element = waitForAccessibilityElement { $0.accessibilityLabel == cleanedText }
if element != nil {
lastExceptions.removeAll()
- testActor.waitForAbsenceOfView(withAccessibilityLabel: textToBecomeInvalid)
+ testActor.waitForAbsenceOfView(withAccessibilityLabel: cleanedText)
if lastExceptions.isEmpty {
textBecameInvalid = true
}