It's actually not possible to write multiple tests using the same element and using the typeText action.
This test and this one (which is actually the same, but duplicated) fail and throw the following output :
3 passing (20s)
1 failing
1) Expectations .toBeVisible() should have a visible "Add" button when a text is filled in the input field:
Error: An action failed. Please refer to the error trace below.
Exception with Action: {
"Action Name" : "Type 'Item'",
"Element Matcher" : "(((respondsToSelector(accessibilityIdentifier) && accessibilityID('inputAdder')) && !(kindOfClass('RCTScrollView'))) || (kindOfClass('UIScrollView') && ((kindOfClass('UIView') || respondsToSelector(accessibilityContainer)) && ancestorThatMatches(((respondsToSelector(accessibilityIdentifier) && accessibilityID('inputAdder')) && kindOfClass('RCTScrollView'))))))"
}
Error Trace: [
{
"Description" : "Failed to type string 'Item', 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" : "172"
}
]
What's weird is that typeText is working in a single test. For example, and in the same project, on master branch, this test is working well.
As a workaround solution
I'm actually using the
await device.launchApp({ newInstance: true });
instead of
await device.reloadReactNative();
but it doesn't seem to be a proper solution.
From the wix original code source
I've just forked Detox and tried by running a failing e2e test right here :
https://github.com/mfrachet/detox/commit/12fbe88c3946945f8418232ecb8f798eec387744
same error occured
$ git clone https://github.com/mfrachet/detox-example && cd detox-example
$ git checkout bug/multiple-type-text
md5-ed31422d87891c60c6bc8618067f9fb9
$ npm i
md5-ed31422d87891c60c6bc8618067f9fb9
$ detox build && detox test
For more details, refer to the test suite ./e2e/tests/todo.expectations.js and the po (or matchers) ./e2e/pageObjects/todo.matchers.js
Hey @mfrachet , I'm trying to understand what you're trying to achieve in your test , the structure of your tests is a bit odd to me, do I'd be happy if you can explain a bit.
Anyway, the forked test does not prove typeText is not working since the test app only shows Type Working!!! if the string passcode is typed.
onChangeTypeText(text) {
this.setState({
typeText: text
});
if (text == 'passcode') {
this.setState({
greeting: 'Type Working'
});
}
}
Regarding waitFor, please try not using it, it's there only for failsafe reasons, Detox should sync with your app, so it only matches and commits and actions when the app is idle.
Hey, @mfrachet just add await inputAdder.tap(); before the second typeText(). That's it, cause your error is Failed to type string 'Item', because keyboard was not shown on screen.
Thank you for the answer, it seems to fix the problem. Is that a wanted behaviour to .tap() before typeText() ?
@mfrachet, when you are writing e2e-tests, think like a human, not test framework.
If you are a user, you need to tap on the input before type text.
If you will write your test correct (it's important) you will not see any problems.
I've rewrited locally your test like
describe('.toBeVisible()', () => {
it('should have a visible "Add" button when a text is filled in the input field', async () => {
await expect(inputAdder).toBeVisible();
await inputAdder.tap()
await inputAdder.typeText('Item');
await expect(touchableAdder).toBeVisible();
});
it('should have a visible "Add" button when a text is filled in the input field', async () => {
await expect(inputAdder).toBeVisible();
await inputAdder.tap()
await inputAdder.typeText('Item');
await expect(touchableAdder).toBeVisible();
});
});
You will not see any problems
Okay, I don't use to write E2E tests for mobile and seem to forgot this .tap() aspect every time :p
I close the issue, thanks for your help guys :D
Actually .typeText() does a tap internally. So writing a test without first tapping would be correct detox code.
I think it is a detox bug that it doesn't do it anymore when using typeText() more than once in a test.
Most helpful comment
@mfrachet, when you are writing e2e-tests, think like a human, not test framework.
If you are a user, you need to tap on the input before type text.
If you will write your test correct (it's important) you will not see any problems.
I've rewrited locally your test like
You will not see any problems