Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.clear() isn't really an alias for .type('{selectall}{backspace}') #8447

Assignees
Labels
pkg/driver This is due to an issue in the packages/driver directory type: bug type: unexpected behavior User expected result, but got another

Comments

@gustaferiksson
Copy link

The .clear() command isn't an alias to .type('{selectall}{backspace}') since it doesn't behave the same. Since cypress 3.5 it's possible to type in any DOM element and if a typeable element gains focus during .type() then cypress continues in that one. So if you .get() a parent element of a typeable one, then .clear() should work because it's supposed to be an alias to .type('{selectall}{backspace}') as stated in the docs.

cy.clear() failed because it requires a valid clearable element.

The element cleared was:

  > <div id="search-input-wrap" class="on">...</div>

A clearable element matches one of the following selectors:
  'a[href]'
  'area[href]'
  'input'
  'select'
  'textarea'
  'button'
  'iframe'
  '[tabindex]'
  '[contenteditable]'

Current behavior:

.clear() doesn't have the same behavior as .type('{selectall}{backspace}')

Desired behavior:

.clear() to behave exactly like .type('{selectall}{backspace}')

Test code to reproduce

  // Passes
  it('test .type({selectall}{backspace})', () => {
    cy.visit('https://docs.cypress.io/api/commands/clear.html#Syntax')

    cy.get('#search-input-wrap').type('clear this')

    cy.get('#search-input-wrap').type('{selectall}{backspace}').type('test')
  })


  // Fails
  it('test .clear()', () => {
    cy.visit('https://docs.cypress.io/api/commands/clear.html#Syntax')

    cy.get('#search-input-wrap').type('clear this')

    cy.get('#search-input-wrap').clear().type('test')
  })

Versions

Tested on cypress 5.0 but most likely every version since 3.5

@sainthkh sainthkh added stage: ready for work The issue is reproducible and in scope type: bug type: unexpected behavior User expected result, but got another pkg/driver This is due to an issue in the packages/driver directory labels Jan 11, 2021
@sainthkh
Copy link
Contributor

Confirmed that the given case shows the bug.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Mar 2, 2021

The code for this is done in cypress-io/cypress#14498, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Mar 15, 2021

Released in 6.7.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v6.7.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Mar 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.