From a1b038e591e1bbfd4ab0bfd5d6c326276a834c36 Mon Sep 17 00:00:00 2001 From: kenji Date: Mon, 12 Nov 2018 21:33:19 +0100 Subject: [PATCH] Replace \n by a space when searching for texts --- CHANGELOG.md | 8 ++++++++ STKTestAppTests/STKSoloTests.swift | 18 ++++++++++++++++++ SwiftiumTestingKit/Info.plist | 2 +- SwiftiumTestingKit/STKSolo.swift | 21 +++++++++++++++------ 4 files changed, 42 insertions(+), 7 deletions(-) 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 }