cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
47.01k stars 3.18k forks source link

dblclick seemingly not working as intended again #29706

Open ThomasMeschke opened 4 months ago

ThomasMeschke commented 4 months ago

Current behavior

I have an application that generates new DB elements and ensures that the "main name" is unique and no two elements can have the same name. When submitting the form via a manual double click, I can see two POST requests being sent, the validation fires and rejects the second POST with an error stating that this name already exists. When I try to reproduce this using cypress cy.get(the submit button).dblclick, only one request is being sent, therefore not reproducing the intended behavior.

Desired behavior

As already mentioned in #3224 this should behave the same as manually double-clicking.

Test code to reproduce

Will not help that much, but this is how it is built:

Cypress.Commands.add("navigateToPath", (path) => {
    cy.visit(path)
    cy.expectUrlToBe(path)
})

Cypress.Commands.add("clickButton", (element) => {
    cy.get(element).dblclick()
})

Cypress.Commands.add("typeTextIntoInput", (input_selector, text) => {
    cy.get(input_selector).clear().type(text)
})

Cypress.Commands.add("selectFilter", (element_selector, dropdown_value) => {
    cy.get(element_selector)
        .select(dropdown_value)
})

Cypress.Commands.add("toggleCheckbox", (element) => {
    cy.get(element).click()
})

cy.navigateToPath('...')
cy.clickButton('.classname')
cy.typeTextIntoInput('#textFieldId', text)
cy.typeTextIntoInput('#textFieldId', text)
cy.selectFilter('#selectId', 'option')
cy.toggleCheckbox(someCheckbox)

cy.clickButton('button[type="submit"]')

Cypress Version

13.8.1

Node version

20.12.1

Operating System

Windows 10.0.19045

Debug Logs

Would love to provide, but input is limited to 64k, debug output is 700k.

Other

No response

ThomasMeschke commented 4 months ago

Any information, notice, update on this one?

jennifer-shehane commented 4 months ago

@ThomasMeschke I'm not sure with the information given why this wouldn't behave the same as manually double clicking. We'll need more information to reproduce the situation to investigate the cause. Can you provide a way to reproduce?

ThomasMeschke commented 4 months ago

Well, here we go...

To reproduce this issue, you are going to need some setup allowing you to run a PHP backend to have some sort of round-trip.

To not clutter the ticket, I published the backend PHP here: https://onlinephp.io/c/9c7b12db-e612-4a08-82df-070f64f1f712 Abstract:

When the form is submitted via double click manually, the output reads "FooFoo", since the form gets submitted twice and thus the second "Foo" gets appended to the file, before it gets deleted in the first call's processing.

You can see me using this manually here: Manual

As you can see, one click leads to Foo while a double click leads to FooFoo. Note: when reproducing this I notice that Firefox already seem to prevent the double click submission of forms, since I could not get it to invoke the backend twice. But Chrome and Edge do, and since the have the bigger market share over Firefox, I'm focusing on them.

To reproduce the issue, I wrote a matching cypress spec you can find here: https://jsfiddle.net/0ryn4uo6/ Abstract:

You can see the spec fail here: Cypress

This also goes to show that really only one request is submitted when you open up the developer tools inside cypress... image

... while Chrome itself triggers two requests: image

If any further information is needed, let me know.

jennifer-shehane commented 4 months ago

@ThomasMeschke Thank you!