nightwatchjs / nightwatch

Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack
https://nightwatchjs.org
MIT License
11.75k stars 1.3k forks source link

Behavior change of .setValue() between 3.6.0. and 3.6.3 #4212

Closed xuezhma closed 1 month ago

xuezhma commented 1 month ago

Hi, I noticed the behavior of .setValue() changed when my project bumped nightwatch from 3.6.0. to 3.6.3. I don't see the release notes mentioning any change related to .setValue().

The change I saw is: in 3.6.0, .setValue() was appending the value; in 3.6.3, .setValue() was replacing the value.Is the change a bug or a feature? Thank you

AutomatedTester commented 1 month ago

I can't see any changes that have happened in this area.

Please can you tell us what browser you were using? Is there an example site that we can reproduce this?

Are you using react, there is an edge case where the state management in react can cause problems with setting the value

garg3133 commented 1 month ago

If you look at the official doc for setValue, it was always meant to replace the contents of the input field by clearing them first. But due to some issue on WebDriver side, it wasn't working properly on some websites while it did on others.

So, we added a fallback for the clear command in https://github.com/nightwatchjs/nightwatch/pull/4035 to always clear the field by sending the required number of backspaces to the field if the WebDriver clear method does not work.

To append to the existing value in the field, you should use the sendKeys command.

While this change is already mentioned in the changelog for 3.6.1, maybe we should also highlight all the commands that it affects.

xuezhma commented 1 month ago

got it thank you. i personal like .setValue() clearing the old value better than appending to it. just wanted to confirm it is the expect behavior.

+1 it would be great to mention the impacted commands on the release notes