I'm running a series of tests on a login page including all of the usual suspects (missing username/password, wrong username/password, etc.) I've found that instead of overriding the previous value in the textbox when a test uses setValue it's appending the value to the existing value.
My tests:
module.exports = {
"Bad Password": function (browser) {
browser
.url("http://localhost")
.waitForElementVisible('body', 5000)
.setValue('input[name=UserName]', 'user')
.setValue('input[name=Password]', 'bob')
.click('#Login')
.pause(5000)
.assert.containsText('div[role=input]', 'The Username or password provided is incorrect.')
.click('a.x-btn-noicon')
},
"Bad Username": function (browser) {
browser
.setValue('input[name=UserName]', 'steve')
.setValue('input[name=Password]', 'bob')
.click('#Login')
.pause(5000)
.assert.containsText('div[role=input]', 'The Username or password provided is incorrect.')
.click('a.x-btn-noicon')
.end();
}
};
[Abbreviated for simplicity]
Not sure if this is the intended functionality or not. If so is there a method to clear an input?
Sorry for the delay and thanks for sending the pull request. I think the setValue command should clear the value first without having to call clearValue explicitly so I'll update it. But having clearValue as a separate command is also useful.
We might want to consider renaming the current setValue to addValue (for clarity), because the functionality is still useful.
In the mean time, I've created the following custom command that I assume would be the new setValue function:
exports.command = function(cssSelector, newValue){
this.clearValue(cssSelector);
this.setValue(cssSelector, newValue);
return this;
};
You might be right. This seems to be low in priority right now so I will close it.
(just passing by)
Since you are going to rename it and it actually sends keystrokes to the element, I suggest to be sendKeys()
https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/value
I just hit this bug, so, clearValue before setValue?
Faced the same problem, is the update in pipeline?
@montogeek better late than never - yes, just clear the value first.
I agree that the current behavior of setValue is misleading.
We should have sendKeys, clearValue, and setValue, which is just a macro for clearValue + sendKeys.
Can we re-open this? setValue is very misleading
Yup... just wasted a lot of time thinking setValue well... set the value.
Just ran into this issue as well. Doesn't make sense that set is actually append...
Agree with rest, this change would be greatly appreciated. (especially since clearValue doesn't work for some reason, and no answers on google forum).
I am a newbie on NW, and wasted hours on it until I noticed it is "append", hope could improve it.
Just came across this. For me setValue still appends the value.
The product is awesome but this wording is misleading. clearValue also seems not to work.
Inserting Jscript to force clear the cell works but it's a bit gross.
Use any js you like. The below works if you like.
client.execute(function() {
聽 document.querySelector('TARGET_HERE').value = '';
});
Strange that this issue is still open. Just ran into the same issue a few minutes ago and it's pretty annoying. +1 for rename inclusive a clear-function or change in behaviour.
As a new user, you would think setValue will...set the value, while in fact it just append it.
Is there any specific difficulties that prevent the creation of such an append function?
Given the number of comments here, perhaps it's time to reopen and correct that bug? :
You might be right. This seems to be low in priority right now so I will close it.
I encountered the same problem, in my case input is limited to 2 letters and already prefilled and it doesn't set value at all, it's very misleading that setValue doesn't not replace but append value.
This is a bug and not a low priority one as the function name is very misleading and causes headaches as can be seen by so many complains. Please reopen the issue.
Came across exactly the same problem, setValue() is incorrectly named and clearValue() doesn't work properly...
+1, just hit this
+1 Just hit this as well. Are people using a click or a custom command to work around this in all current implementions?
My bandaid fix:
// commands/setVal.js:
exports.command = function(sel, val){
// Fix for setValue() not clearing value first.
// https://github.com/nightwatchjs/nightwatch/issues/4
this.clearValue(sel);
this.setValue(sel, val);
this.execute(function(){});
return this;
};
It is just sad that the best javascript browser testing framework exists in 2017 is an abandon-ware. I've pretty much tried all of them, all of them were either buggy or near impossible once you dig deeper beyond the test world examples (save for cypress which is in private beta). PS. Please don't reply to this rant, don't want to turn this issue into something else.
+1 faced the same problem. such a let down. seems sloppy to name it that way.
Maybe it's time to reopen the issue? it's been a long time.
In all honestly, I'm about to build major product testing on nightwatch. Is it actually abandonware?
It does seem vastly more easy to use than it's competitors.
However this issues has been around for THREE AND A HALF YEARS!
To make set actually do a set, or to provide some other method that does what it needs to do?
Having to write "clear(sel).set(sel)" for every variable in my application does not pass the straight-face test.
This issue has deeply shaken my faith in the viability of this tool as a stable dev/test platform.
Please let me know if it is safe to build here or not.
If the author believes such an important issue with an easy fix and so many people complaining is "low in priority right now so I will close it" and never responds is not an indication of abandon-ware then I don't know what is. As mentioned above, this is still the best js test framework out of all the ones I tried more than a simple "hello world" testing. So use it knowing the author won't fix stuff nor give a damn or use something else. It's that simple.
@jason-henriksen this issue will be addressed in the next major release (1.0), which is currently in progress.
@fuzzthink I'm glad to hear you thing it's still he best js test framework and I can assure you that I do give a damn.
I'm very relieved to hear that it's still under active development.
I send a tiny bit of money to MobX each month on OpenCollective. I'd be willing to help support nightwatch in the same way. I bet a number of others would kick in too if there were regular status reports and progress on tasks. Have you considered a contribution platform like OpenCollective or Patreon? After all, nothing helps prioritize a project like a tiny bit of a cash flow...
Actually we are on OpenCollective: https://opencollective.com/nightwatch, but currently only accepting sponsorships.
Challenge:
fix this issue + accept small monthly donations = I'll sign up for $5/month
(sorry, I can't drop a full $100 all at once)
I would back Nightwatch on Patreon.
anyone still interested in backing Nightwatch on OpenCollective?
I still haven鈥檛 fixed the setValue, but maybe you want to back Nightwatch either way?
The issue still exists for me
I also have this issue when setting values. Is it being looked at?
Our team is running into this problem now. setValue is appending the value instead of setting a new value. We tried to use clearValue before then but it is not working for us either. The value is not being cleared.
The command provided by @fuzzthink works perfectly for me - thanks!
Most helpful comment
Just ran into this issue as well. Doesn't make sense that
setis actuallyappend...