KIF: is there a way to get all the accessibility labels on the current screen?
1 answer
This function can return all the availability of the Label in the view:
func getAllAccessibilityLabel(_ viewRoot: UIView) -> [String]! {
var array = [String]()
for view in viewRoot.subviews {
if let lbl = view.accessibilityLabel {
array += [lbl]
}
array += getAllAccessibilityLabel(view)
}
return array
}
func getAllAccessibilityLabelInWindows() -> [String]! {
var labelArray = [String]()
for window in UIApplication.shared.windows {
labelArray += self.getAllAccessibilityLabel(window)
}
return labelArray
}
And call it in your KIF test:
let labelArray = getAllAccessibilityLabelInWindows()
print("labelArray = \(labelArray)")
+2
source to share