geb / issues

Repository for Geb's issue tracker
12 stars 4 forks source link

input.value('newValue') appends 'newValue' to a previous value on Chrome instead of replacing it #392

Closed robaca closed 9 years ago

robaca commented 9 years ago

With the chrome driver, if I call input.value('newValue')on a text input field that already has a default value, the newValueis appended to that default, instead of replacing it.

erdi commented 9 years ago

The value should be first cleared and then set: https://github.com/geb/geb/blob/master/module/geb-core/src/main/groovy/geb/navigator/NonEmptyNavigator.groovy#L668. If it's not then it's a driver implementation issue. Also, does it happen always or only sometimes?

erdi commented 9 years ago

Closing due to no response from OP.

MartinX3 commented 6 years ago

Same error here with the firefoxdriver & chromedriver. I execute the test with intellij.

$("input[aria-label='Login']").value(Keys.chord(Keys.CONTROL, "A") + Keys.BACK_SPACE) Doesnt clear the input field, only select every text inside it.

$("input[aria-label='Login']").value("geb_mmayer") Appends the value to the old value

But if I execute the code lines by hand, it works.

erdi commented 6 years ago

Sorry Martin, but you will have to provide a failing test for me to look at because I’m unable to reproduce and thus cannot investigate. You can either provide a self contained sample project exhibiting the behaviour or a PR to Geb with a failing test. I can explain how to write and execute tests targeting certain browsers via BrowserStack or SauceLabs within Geb’s codebase if you’re interested.

On Sun, 26 Aug 2018 at 18:59, Martin Dünkelmann notifications@github.com wrote:

Same error here with the firefoxdriver & chromedriver. I execute the test with intellij.

$("input[aria-label='Login']").value(Keys.chord(Keys.CONTROL, "A") + Keys.BACK_SPACE) Doesnt clear the input field, only select every text inside it.

$("input[aria-label='Login']").value("geb_mmayer") Appends the value to the old value

But if I execute the code lines by hand, it works.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/geb/issues/issues/392#issuecomment-416056937, or mute the thread https://github.com/notifications/unsubscribe-auth/AAMii4ulj8ERJslX8S9KXDL-hECSJXlLks5uUuH3gaJpZM4FhKQM .

MartinX3 commented 6 years ago

Thank you for your response!

Hmm, that's hard to answer. It is a fullstack software project for my company. The Frontend is based on VueJS and Vuetify (GUI Elements). The data is requested via the FetchAPI on the Backend (Spring Boot Rest Application).

I don't know if this happens because of the use of the fetch API. I also need to use "Thread.sleep(number)" to avoid race conditions in some tests. (Test thinks that the dom elements I want doesn't exist. Or crash, if it want to access them, while they are generated.)

Do you have an idea how to provide a test? Which thinks it should include? It is not easy for me to understand, why this happen or how to debug this weird behavior.

At the moment, I wrote a workaround. I test if the value is appended, and if that not happen, I reapply the entire value again and make an assertion on this (if-statement).

erdi commented 6 years ago

I appreciate that you’re observing the issue within a wider project but I will not have access to it so I won’t be able to investigate. That’s why I asked for a standalone sample. Another reason for my request is that we’d want to isolate the issue as much as possible to ensure that the issue is indeed within Geb and not caused by some interference from the tools you’re using.

I don’t know if using FetchAPI has anything tomdomwith what you’re seeing. It’s possible that it does if it means that your aplication is js heavy and full of asynchronous js application. One thing I can say though is that explicitly using Thread.sleep() in your Geb code is pretty much always a bad idea.

To provide a test you’d need to clone Geb’s repo, run ./gradlew idea, open the generated ipr file in IntelliJ and add the test within the geb-core module. Have a look at what other tests in that module use as the base class and how they use the html() method taking a closure to bootstrap the html needed for the test. Finally annotate your test class with @CrossBrowser, create a free BrowserStack account and then run your test using GEB_BROWSERTSTACK_ACCOUNT= GEB_BROWSERTSTACK_AUTHKEY= ./gradlew :module:geb-core:chromeWindowsTest --tests=fully.qualified.name.of.YourSpec. Note that the command I provided is for *nix operating systems.

On Mon, 27 Aug 2018 at 20:38, Martin Dünkelmann notifications@github.com wrote:

Thank you for your response!

Hmm, that's hard to answer. It is a fullstack software project for my company. The Frontend is based on VueJS and Vuetify (GUI Elements). The data is requested via the FetchAPI on the Backend (Spring Boot Rest Application).

I don't know if this happens because of the use of the fetch API. I also need to use "Thread.sleep(number)" to avoid race conditions in some tests. (Test thinks that the dom elements I want doesn't exist. Or crash, if it want to access them, while they are generated.)

Do you have an idea how to provide a test?

At the moment, I wrote a workaround. I test if the value is appended, and if that not happen, I reapply the entire value again and make an assertion on this (if-statement).

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/geb/issues/issues/392#issuecomment-416342928, or mute the thread https://github.com/notifications/unsubscribe-auth/AAMii8rESuOIHVGMWb5fRlg1VeORTkYfks5uVEqYgaJpZM4FhKQM .

MartinX3 commented 6 years ago

Thank you very much for your response. But I give up using it. I get a Driver Callback Exception while using it in Jenkins/Kubernetes. If I use Selenium Driver directly and write the path to the chromedriver binary, I get an IO Exceoption, that gradle doesn't find the file/folder.

Weird stuff.

mkutz commented 5 years ago

I investigated the issue lately and I can reproduce @MartinX3's observation. As you suspected @erdi, the root of this is in the driver for Chrome according to this comment.

I also found out that this issue only affects inputs with auto-completion enabled (was suggested somewhere I can't remember). So most login forms are not affected.

For those who –like me– need a solution right now: It is possible to extend the TextInput module like this:

class AutocompleteTextInput extends TextInput {

    private static final boolean MACOS = System.getProperty("os.name").toLowerCase().indexOf("mac") >= 0
    private static final String CLEAR_CHORD = Keys.chord(MACOS ? Keys.COMMAND : Keys.CONTROL, "a", Keys.DELETE)

    @Override
    void setText(String text) {
        this << CLEAR_CHORD
        super.setText(text)
    }
}

Just use this module for the affected text inputs and the text will be cleared just like in other browser while it will still work on those. This is basically the same solution @MartinX3 suggested, but will also work on MacOS.

I'll create a self-contained example to illustrate this and allow further investigation.

erdi commented 5 years ago

Thanks for sharing your findings. For what it's worth, your workaround can be made slightly more idiomatic by writing it this way:

@Override
void setText(String text) {
    this << CLEAR_CHORD
    super.setText(text)
}

(see the "Sending keystrokes" section of the manual)

mkutz commented 5 years ago

Thanks. I updated the code above.

MartinX3 commented 5 years ago

Nice

Also this helped me in nightwishJS https://github.com/nightwatchjs/nightwatch/issues/1592#issuecomment-476737627