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

Add <datalist> support to cy.select #445

Closed
chrisbreiding opened this issue Mar 2, 2017 · 4 comments
Closed

Add <datalist> support to cy.select #445

chrisbreiding opened this issue Mar 2, 2017 · 4 comments
Assignees
Labels
type: enhancement Requested enhancement of existing feature

Comments

@chrisbreiding
Copy link
Contributor

<datalist> elements are similar to <select> elements and it would be a natural extension of cy.select() to support them.

@chrisbreiding chrisbreiding added the type: enhancement Requested enhancement of existing feature label Mar 2, 2017
@chrisbreiding chrisbreiding self-assigned this Mar 2, 2017
@chrisbreiding
Copy link
Contributor Author

On second thought, <datalist> is only useful with an input, so it's easier and just as valuable to simply type in the value. Testing a <datalist> would basically be testing the browser's implementation, which doesn't make much sense.

@tamtam2008
Copy link

how can i select input datatalist in cypress, i've tried everything way i can but cypress's not same to be support it. Sorry for my bad english

@chrisbreiding
Copy link
Contributor Author

chrisbreiding commented Aug 8, 2018

This is a case where you don't need to do things exactly like a user would. So you don't need to open the datalist and 'select' an option to get it to work. If you want to test an input with a datalist, you generally want to test 2 things:

  • that the right options are in the datalist
  • what happens when one of those options is set as the input's value

So you can break it up similarly. If you have the following html:

  <input list="fruit" />
  <datalist id="fruit">
    <option>Apple</option>
    <option>Banana</option>
    <option>Cantaloupe</option>
  </datalist>

You can test it like this:

  cy.get('#fruit option').should('have.length', 3)
    .first().should('have.text', 'Apple')
    .next().should('have.text', 'Banana')
    // ... etc ...
  cy.get('input').type('Apple')

For testing the options, you query them directly and make assertions. For 'selecting' an option, you type it into the input.

Edited by @jennifer-shehane - replaced .second() in example with .next() for proper subject chaining.

@jennifer-shehane
Copy link
Member

I created a new issue in our docs to document datalist testing here: cypress-io/cypress-documentation#824. Our documentation is open source and contributions are welcome. 😄

I also updated @chrisbreiding example above to use .next() instead of .second since the subject would have changed to the first option at that command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Requested enhancement of existing feature
Projects
None yet
Development

No branches or pull requests

3 participants