Sunspension / VKPinCodeView

VKPinCodeView is simple and elegant UI component for input PIN. You can easily customise appearance and get auto fill (OTP) iOS 12 feature right from the box.
MIT License
96 stars 25 forks source link

How to UI test it? #9

Closed ppamorim closed 4 years ago

ppamorim commented 4 years ago

Hi, I am trying to type a security PIN in an XCTestCase but I could not do it so far.

Tried these both below, no success:

app.descendants(matching: .any)["securityPinView"].textFields.element(boundBy: 0).typeText("1111")
app.textFields["securityPinView"].typeText("1111")

Being securityPinView the accessibilityIdentifier value.

Sunspension commented 4 years ago

@ppamorim I guess you need to simulate pressing buttons on the virtual keyboard.

ppamorim commented 4 years ago

@Sunspension What I did was to use this function to type the desired password:

private func typeKey(_ keyString: String) {
    let appKeys = app.keys
    let keysMapped = keyString.map { key in appKeys[String(key)] }
    for index in 0..<keysMapped.count {
        keysMapped[index].tap()
        if index == keysMapped.count - 1 {
            Thread.sleep(forTimeInterval: 0.5)
        }
    }
}

To use it just call like this:

typeKey("5555")