tttstudios / react-native-otp-input

Tiny Javascript library which provides an elegant UI for user to input one time passcode.
MIT License
522 stars 239 forks source link

How to populate the otp input with Appium in iOS #103

Open TeodoraD opened 3 years ago

TeodoraD commented 3 years ago

The testing for the app should be automated with Appium. OTPInputView is located but when trying to use sendKeys to populate the input the following error is shown: Call to 'sendKeys' failed [element.sendKeys("1")] Error response status: 12, InvalidElementState - An element command could not be completed because the element is in an invalid state (e.g. attempting to click a disabled element). Selenium error: Error Domain=com.facebook.WebDriverAgent Code=1 "'Other' is not ready for a text input. Neither the accessibility element itself nor its accessible descendants have the input focus" UserInfo={NSLocalizedDescription='Other' is not ready for a text input. Neither the accessibility element itself nor its accessible descendants have the input focus}

Screen Shot 2020-10-06 at 18 18 49

In Android, it is possible to locate the separate pins of the input and populate it. But they are not shown for ios.

alezoffoli commented 3 years ago

hi @TeodoraD, did you find any workaround for this?

TeodoraD commented 3 years ago

Hi, @alezoffoli I didn't. But if I am honest I had not worked on this for a long time. Still, it will be good if there is some solution to this.

abumalick commented 3 years ago

We could do it with detox by selecting the testID textInput https://github.com/tttstudios/react-native-otp-input/blob/master/index.tsx#L193

await element(by.id('textInput')).atIndex(0).typeText('123456')

I believe it is a matter of selecting the correct element to fill.

abumalick commented 3 years ago

Please note that there is multiple inputs with this testID, in detox we were getting an array of inputs (it is why you see the atIndex(0), we select the first input). When filling the first input with the full code, this library is smart enough to handle it correctly.