Created
April 21, 2017 03:02
-
-
Save wh1pch81n/dcdcd73a316e1aca1034409f458da8f6 to your computer and use it in GitHub Desktop.
A quick class that could aid in finding a view with a specific identifier. Meant to be used in XCTest unit tests. Might be able to get around the limitations of UI Testing i.e. TableViews with 40000 rows.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Finder<VIEW_TYPE: UIView> { | |
var foundView: VIEW_TYPE? | |
public func findView(with identifier: String) throws { | |
foundView = findView(with: identifier, parent: UIApplication.shared.keyWindow!) | |
if foundView == nil { | |
throw NSError() | |
} | |
} | |
private func findView(with identifier: String, parent: UIView) -> VIEW_TYPE? { | |
if parent.accessibilityIdentifier == identifier { | |
return parent as? VIEW_TYPE | |
} | |
var v: VIEW_TYPE? | |
for view in parent.subviews { | |
if let _v = findView(with: identifier, parent: view) { | |
v = _v | |
break | |
} | |
} | |
return v | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment