CodeceptJS: I.clearField and I.fillField not working as expected.
What are you trying to achieve?
Replace text in field using I.fillField or clearing text with I.clearField.
What do you get instead?
If the field has the following text already in it: “hello” and I try to replace with “world” I get “helloworld”. If I try to use I.clearField the text in the field does not change.
Provide console output if related. Use
--verbose
mode for more details.
No errors thrown.
Provide test source code if related
I.clearField(selectors.name);
I.fillField(selectors.name, name);
Details
- CodeceptJS version: 6.2
- NodeJS Version: v7.8.0
- Operating System: MacOS Sierra v10.12.4
- Nightmare version: 2.10.0
- Nightmare Upload version: 0.1.1
- Configuration file:
{
"output": "./output",
"helpers": {
"nightmare": {
"url": "http://localhost:1079",
"restart": true,
"show": true,
"typeInterval": 5,
"windowSize": "1440x1024"
}
},
"include": {
"I": "./e2e-tests/steps/steps.js"
},
"mocha": {
"reporterOptions": {
"reportDir": "output"
}
},
"bootstrap": false,
"teardown": null,
"hooks": [],
"tests": "./e2e-tests/tests/**/*_test.js",
"timeout": 10000,
"name": "testing"
}
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 4
- Comments: 16 (1 by maintainers)
You can use this custom step, works perfectly:
Add to steps_file.js:
@jmitchell89 is correct, that this affects react projects, as I’ve also observed. I created a custom helper, which solves the problem. Add this to your
custom_steps.js
(or whatever you named it) file:Then you can do for example:
I am having the exact same issue on webdriver.io
Sorry about not responding back, I managed to figure out the issue, and I thought others should know about it too. It only appears in apps using react and is an issue with nightmare. A work around is to create a helper that has a clearField function that calls:
this.helpers.nightmare.browser.type(locator, '\u0008\u0008......');
\u0008
is the backspace key. I also tried to force onChange to get called after the input’s value is cleared. However I couldn’t get that solution to work sadly.It’s an ugly workaround but it does solve the issue.