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

[with public example] Not able to find react component #141

Open
thediveo opened this issue Feb 7, 2021 · 4 comments
Open

[with public example] Not able to find react component #141

thediveo opened this issue Feb 7, 2021 · 4 comments

Comments

@thediveo
Copy link

thediveo commented Feb 7, 2021

Hi Abhinaba,

this is my first contact with cypress-react-selector (and Cypress), so please bear with me especially in case of stupid mistakes.

I've also fallen victim to the dreaded cy.then() timed out after waiting 4100ms when trying to locate a component using cypress-react-selector. Searching for some time, I came across issue #58. At the end of that issue you're asking for a proper code example. Hoping that a public Github project exhibiting that problem qualifies as "proper code example" (of course, for a sufficient definition of "example) I'm opening this new issue.

From what I've read when it comes to not finding components it looks like that often happens in more complex situations. In my case this is the React UI to a Linux diagnosis service for discovering so-called "namespaces" which is one of the mechanisms building the foundations for (not only) containers (such as Docker containers).

To (hopefully) reproduce my issue, first clone the public Github thediveo/lxkns repo and check out branch "feature/test-webui"

git clone --branch feature/test-webui https://github.com/thediveo/lxkn

Please note that you do not need to build the containerized backend service, so simply skip that step and just start the frontend development server and Cypress...

Please start the web UI frontend development server on port 3030. When navigating to localhost:3030 you should be greeted with an app bar with hamburger menu button as well as a few more toolbar buttons.

(cd webui/lxkns && yarn start)

And finally fire up Cypress, then select the lxkns.spec.ts integration test ... and watch it burn in cy.react('Refresher')... 😢

(cd webui/lxkns && yarn cypress)

The root gets properly detected as far as I could cross-check by using a non-existing root selector. I don't know if that might be of any relevance: the Refresher component lives inside a <header> element which in turn is inside the <div id="root">.

@thediveo
Copy link
Author

thediveo commented Feb 7, 2021

May this be related to the fact that the Refresher component returns <>...</>?

Using getReact() seems to be able to successfully locate the Refresher component RESQ node, but now I'm stuck with how to get a DOM element from there so I can click on it:

cy.getReact('Refresher').nthNode(0).getReact('IconButton').click()

@abhinaba-ghosh
Copy link
Owner

abhinaba-ghosh commented Feb 7, 2021

Hi @thediveo , Today I am away from the keys. However, I just got some time to reply from my mobile. Will take a deep look this week.

Although, let me clarify the fact that .getReact() returns RESQ node, where .react() returns DOM node. RESQ node is helpful for determining runtime react properties, not for interacting with DOM elements. So to be able to click the element, convert the getReact calls to react calls like:

cy.react(Refresher).eq(0).react('IconButton').click()

Let me know if that works.May be you have already tried it.

@thediveo
Copy link
Author

thediveo commented Feb 7, 2021

Thank you for your quick response, enjoy your time off the keys! Unfortunately, cy.react('Refresher').eq(0).react('IconButton').click() fails to locate the Refresher component, I suspect because that component returns a <> pseudo component with several children inside?

@abhinaba-ghosh
Copy link
Owner

Possibly the usual suspect. I will pull down your branch and will have a deep look. Thanks for the detailed information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants