Skip to content

Commit

Permalink
Replace \n by a space when searching for texts
Browse files Browse the repository at this point in the history
  • Loading branch information
kenji21 committed Nov 12, 2018
1 parent 9b0751f commit a1b038e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 18 additions & 0 deletions STKTestAppTests/STKSoloTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion SwiftiumTestingKit/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.1.5</string>
<string>0.1.6</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
</dict>
Expand Down
21 changes: 15 additions & 6 deletions SwiftiumTestingKit/STKSolo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
Expand Down

0 comments on commit a1b038e

Please sign in to comment.