cypress: cy.click() on React Select v1 component doesn't show the drop down
- Operating System: macOS Sierra
- Cypress Version: 0.19.4
- Browser Version: Electron 53
Is this a Feature or Bug?
Bug
Current behavior:
cy.click() on an react select component not showing the dropdown options.
Desired behavior:
cy.click() on an react select component shows the dropdown options.
How to reproduce:
A demo repo is created to reproduce the issue.
https://github.com/bencao/react-select-cypress
The test file is located at cypress/integration/react_select_spec.js
Test code:
describe('Weird behavior when testing React Select', function() {
it('fails on Electron 53 and Canary 61, but passes on Chrome 59', function() {
cy
.visit('http://jedwatson.github.io/react-select/')
.get('div.Select-control:first')
.click()
.get('.Select-option:contains(Victoria)')
.click();
});
});
Additional Info (images, stack traces, etc)
$ cypress run [12:55:58]
Started video recording: /Users/zcao/Documents/workspace/react-select-cypress/cypress/videos/79qp6.mp4
(Tests Starting)
Weird behavior when testing React Select
1) fails on Electron 53 and Canary 61, but passes on Chrome 59
0 passing (6s)
1 failing
1) Weird behavior when testing React Select fails on Electron 53 and Canary 61, but passes on Chrome 59:
CypressError: Timed out retrying: Expected to find element: '.Select-option:contains(Victoria)', but never found it.
at Object.cypressErr (http://jedwatson.github.io/__cypress/static/js/cypress.js:5729:15)
at Object.throwErr (http://jedwatson.github.io/__cypress/static/js/cypress.js:5694:22)
at Object.throwErrByPath (http://jedwatson.github.io/__cypress/static/js/cypress.js:5721:21)
at $Cy._retry (http://jedwatson.github.io/__cypress/static/js/cypress.js:12954:26)
at http://jedwatson.github.io/__cypress/static/js/cypress.js:8122:28
at tryCatcher (http://jedwatson.github.io/__cypress/static/js/vendor.js:46490:31)
at Promise._settlePromiseFromHandler (http://jedwatson.github.io/__cypress/static/js/vendor.js:44625:31)
at Promise._settlePromiseAt (http://jedwatson.github.io/__cypress/static/js/vendor.js:44701:18)
at Promise._settlePromises (http://jedwatson.github.io/__cypress/static/js/vendor.js:44817:14)
at Async._drainQueue (http://jedwatson.github.io/__cypress/static/js/vendor.js:42184:16)
at Async._drainQueues (http://jedwatson.github.io/__cypress/static/js/vendor.js:42194:10)
at MutationObserver.Async.drainQueues (http://jedwatson.github.io/__cypress/static/js/vendor.js:42022:14)
(Tests Finished)
- Tests: 1
- Passes: 0
- Failures: 1
- Pending: 0
- Duration: 5 seconds
- Screenshots: 1
- Video Recorded: true
- Cypress Version: 0.19.4
(Screenshots)
- /Users/zcao/Documents/workspace/react-select-cypress/cypress/screenshots/Weird behavior when testing React Select -- fails on Electron 53 and Canary 61 but passes on Chrome 59.png (1280x720)
(Video)
- Started processing: Compressing to 32 CRF
- Finished processing: /Users/zcao/Documents/workspace/react-select-cypress/cypress/videos/79qp6.mp4 (0 seconds)
(All Done)
FAIL: 1
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 30 (16 by maintainers)
This is what i do to interact with React Select components:
Thanks a lot for sharing. I found that I needed to make some adjustments – maybe because I’m using React Select v2.0.0, which was just released:
(It seems like some class names have been changed.)
I used the ID I set on the input as a selector:
@dziamid The trick does work! The key is to type on ‘input’ element. A simplified version:
This fix will go out in the next release. I’ll be opening a new issue describing it and linking it here. There were a few edge cases surrounding focus events that we are getting nailed down. It will likely fix other issues two. There were two separate but related problems going on which made it difficult to track down.
I modified this to find the input by label instead of id, and also added a delay before selecting the option as my input involves an async call. Hopefully someone find’s it useful. Using
react-select@3.0.4
@yhoiseth fixes for react-select v2.0 will be in this PR #2982 The issue associated with v2 is #1486 , so feel free to drop a comment on there
It also works if you type a string with an empty space
Works for headed mode (Chrome 67) and headless mode (Chrome 59) Cypress 3.0.2
The problem is not resolved yet. It’s actually originating from
react-select
and I wonder if cypress can actually work around the issue there without solving the root cause itself. The problem is that react-select dropdown won’t open when the window is not focused. For example, even when you use the full gui browser but you open devtools and your window focus is on devtools instead of the app window, it still won’t open.The
input
solution that was suggested above indeed works, but obviously only for input enabled react-select. No input still causes problems. We currently worked around this by running--browser chrome --headed
(unfortunately, since it’s not ideal).