简体   繁体   中英

KIF: is there a way to get all the accessibility labels in a current screen?

I am using KIF for testing an iOS app, and I would like to know if there is a way to get all the accessibility labels in a current screen. I would like to get an array of strings where each element is the accessibility labels that this screen has.

This function can return all accessibilityLabel 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 the KIF test:

let labelArray = getAllAccessibilityLabelInWindows()
print("labelArray = \(labelArray)")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM