Detox: typeText and clearText sometimes fail due to keyboard sync

Created on 8 Oct 2016  路  15Comments  路  Source: wix/Detox

We sometimes have sync problems with the keyboard not shown yet:

2016-10-08 01:47:39.567 example[38497:4275833] Detox Test Failed: Element matcher: (respondsToSelector(accessibilityIdentifier) && accessibilityID("UniqueId005")) Complete Error: Error Domain=com.google.earlgrey.ElementInteractionErrorDomain Code=1 "Failed to type string "", because keyboard was not shown on screen." UserInfo={NSLocalizedDescription=Failed to type string "", because keyboard was not shown on screen.}

Most helpful comment

I have always click on the input before type text on the tests like humans, not robots. And don't see any problems.

All 15 comments

Hopefully will be fixed with #37.

@talkol Shouldn't this target version 2, together with #37?

not sure, I think it's a different problem

@talkol @LeoNatan did any of you see failure in tests recently ?

Not that I can remember. @rotemmiz

I also have this problem.

I can find the element meaning

await expect(element(by.id('<testID>'))).toBeVisible()

works but when I try

await element(by.id('testID')).typeText(<someString>)

I get the above error with keyboard out of sync.

What error exactly are you getting ? Note that your computer keyboard layout must be on qwerty english for EarlGrey to be able to type the text.

    1) Enter phone number and tap on button


  0 passing (15s)
  1 failing

  1) FiestTest Enter phone number and tap on button:
     Error: An action failed. Please refer to the error trace below.
Exception with Action: {
  "Action Name" : "Type '6219'",
  "Element Matcher" : "(((respondsToSelector(accessibilityIdentifier) && accessibilityID('ValidatePage-txtField')) && !(kindOfClass('RCTScrollView'))) || (kindOfClass('UIScrollView') && ((kindOfClass('UIView') || respondsToSelector(accessibilityContainer)) && ancestorThatMatches(((respondsToSelector(accessibilityIdentifier) && accessibilityID('ValidatePage-txtField')) && kindOfClass('RCTScrollView'))))))"
}

Error Trace: [
  {
    "Description" : "Failed to type string '6219', because keyboard was not shown on screen.",
    "Error Domain" : "com.google.earlgrey.ElementInteractionErrorDomain",
    "Error Code" : "2",
    "File Name" : "GREYKeyboard.m",
    "Function Name" : "+[GREYKeyboard typeString:inFirstResponder:error:]",
    "Line" : "168"
  }
]

This can happen if you鈥檝e played around with CMD+H (soft keyboard) or CMD+SHIFT+H (hardware keyboard). Restore those to default and make sure that the keyboard appears on screen when making a text field a first responder. Or use replaceText.

I haven't really used the keys CMD+H or CMD+SHIFT+H in my simulations and when I use replaceTextinstead of typeText I get the following error:

[
    {
        "Description" : "Cannot perform action due to constraint(s) failure.",
        "Error Domain" : "com.google.earlgrey.ElementInteractionErrorDomain",
        "Error Code" : "1",
        "File Name" : "GREYBaseAction.m",
        "Function Name" : "-[GREYBaseAction satisfiesConstraintsForElement:error:]",
        "Line" : "66"
    }
]

For now I'm just using a sleep command like bellow to give me time to manually insert the string; but, this should not be a permanent solution...

function sleep (ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}

await sleep(milliseconds)
// what needs to happen after I manually enter the code

I don't remember toggling keyboard setting as @LeoNatan mentions. However, when I check Hardware/Keyboard in my simulator, I can see that SW keyboard is turned off.

It made sense to turn it on, and I could see the difference right away, when focusing on input field.

Running my test case after this change, it worked as I would expect.

Hardware -> Keyboard -> has three options:
1) Uses the Same Layout as MacOS
2) Connect Hardware Keyboard
3) Toggle Software Keyboard

The third one is greyed out and the second one doesn't seem to work.

I have always click on the input before type text on the tests like humans, not robots. And don't see any problems.

Thank you! That's exactly what I needed.
Problem solved.

Just going to chime in from detox 7.3.7, if I have Connect Hardware Keyboard enabled, my tests _usually_ fail, and if I disable it, the software keyboard always does the right thing. I did write a helper method to write to an input that does a tap() first, as recommended by @isnifer .

I'd prefer to have this setting enabled, since I usually run through the app manually to find where the next set of e2e tests should be, which always requires me to run my app through a login step.

Is this still an issue? I can toggle things for now, but it's just another step that I need to document for my dev team.

Hey @mrozbarry, it makes it hard for us to track progress of closed issues.
So if you have any progress regarding keyboard handling please open a new issue, or even better, if you want to offer a PR with bug fix or documentation we'll gladly accept it.

Was this page helpful?
0 / 5 - 0 ratings