question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Setting testID for e2e testing

See original GitHub issue

Hi there, thanks a lot for this great component.

I was wondering if you’re planning to include support for setting testID’s some time? I need this for my Cypress e2e tests.

Also just in case you weren’t aware, this component seems to work great on web too using React Native Web!

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
hoaphantn7604commented, Jun 12, 2022

hi @markymc , I have updated in the latest version 2.0.0.

0reactions
markymccommented, Sep 13, 2022

@waldenermonteiro try this:

 <Dropdown
    testID="opponent picker"
    labelField="username"
    valueField="id"
    data={opponentPickerValues} // Shape includes {username: 'some-username'}
    itemTestIDField="username" // this is the key from the above shape, similar to labelField
    ...
/>

Then (I’m using Cypress):

Cypress.Commands.add('selectPickerValue', (pickerTestID, value) => {
  cy.getTestID(pickerTestID).click();

  // These are needed to get the FlatList to load all the items so the target can be clicked
  // This was quick and hacky, and can be improved
  cy.getTestID(pickerTestID + ' flatlist').scrollTo('bottom');
  cy.wait(200);
  cy.getTestID(pickerTestID + ' flatlist').scrollTo('bottom');
  cy.wait(200);
  cy.getTestID(pickerTestID + ' flatlist').scrollTo('bottom');

  cy.getTestID(value).click();
});

cy.selectPickerValue('opponent picker', 'some-username');
cy.getTestID('opponent picker').contains('some-username');
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why you shouldn't use ids in E2E testing | Autify Blog
This article is about the best practices of locating element on E2E automated testing.
Read more >
e2e testing using testID and customStyles #197 - GitHub
I'm trying to use React Native Testing Library such that I can find a MenuOption by it's testID, click on that option, and...
Read more >
Write E2E tests - Mattermost Developers
Use camelCase when assigning data-testid or element ID. Watch out for potential breaking changes in the snapshot of the unit testing. Run make...
Read more >
Playwright for End to End Tests - Rhythm & Binary
Arrange (setup your data); Act (exercise your code); Assert (verify that what you did is what you expected). To run your Playwright tests,...
Read more >
What is the data-testid attribute in testing? - Educative.io
data-testid is an attribute used to identify a DOM node for testing purposes. It should be used as a handler to the test...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found