testing-playground icon indicating copy to clipboard operation
testing-playground copied to clipboard

Storybook extension/query through iframe support

Open lexanth opened this issue 4 years ago • 6 comments

Summary 💡

I've mainly come across this tool through the chrome extension, which is great!

It would be even better if it could support being used against storybook - our stories often match the components we're trying to render in unit tests, so it would hopefully be able to suggest very relevant selectors.

I suspect the issue is because storybook embeds the actual story (which is what I want to look at) in an iframe?

One option would be to build a storybook extension (although doing the selector mode from the chrome extension might be hard). Another would be to allow the root document to be specified for the chrome extension (e.g. I could set it to #storybook-preview-iframe and it would then run queries etc inside the storybook preview).

Examples 🌈

https://next--storybookjs.netlify.app/official-storybook/?path=/story/addons-a11y-basebutton--label is one of storybook's examples - with the chrome extension, you can't find anything inside the storybook preview.

Motivation 🔦

Our stories often match the components we're trying to render in unit tests, so it would hopefully be able to suggest very relevant selectors.

lexanth avatar Apr 15 '21 16:04 lexanth

Helpful workaround in the meantime that I just learned - you can append iframe.html into the URL (right before the ?) to navigate to the actual iFrame, where this extension will be able to pick things up 🙂

Using the example link: https://next--storybookjs.netlify.app/official-storybook/iframe.html?path=/story/addons-a11y-basebutton--label

Screen Shot 2021-05-12 at 10 03 43 AM

melanieseltzer avatar May 12 '21 17:05 melanieseltzer

Hi, it would be great to autodetect a few typical frameworks (something that stays maintainable) when an iframe is present, and consider the "screen" to be this iframe and not the whole screen. This mode could be optional (like if you are a developer of Storybook itself you might want to actually get the selector for the Storybook UI :)).

What would be required to consider an iframe as the "screen" on a technical standpoint? I could try to get help for crafting a PR.

I've raised attention to this point at Storybook, because the new testing capabilities of Storybook will make this use case more and more relevant in the incoming releases.

I haven't found much doc about testing an iframe either (only this ticket for Enzyme https://stackoverflow.com/questions/41447842/test-the-content-of-an-iframe-in-a-react-component-with-enzyme)

In the meantime much thanks for the workaround @melanieseltzer

eric-burel avatar Jul 12 '21 13:07 eric-burel

I don't think we need to support a few typical frameworks. What we need to support is the following:

  • support selecting and querying inside iframes
  • support setting an iframe as "base frame" (so that is seen as the root)

That would add support to frameworks like Cypress and Storybook out of the box.

smeijer avatar Jul 12 '21 14:07 smeijer

Unfortunately, I've been short on time lately. So if anyone is willing to take a stab at that, please do.

smeijer avatar Jul 12 '21 14:07 smeijer

Being able to reference elements in an iframe would be amazing. In addition to storybook, we'd use it for Stripe payment forms.

jeremyzilar avatar Sep 29 '21 16:09 jeremyzilar

Helpful workaround in the meantime that I just learned - you can append iframe.html into the URL (right before the ?) to navigate to the actual iFrame, where this extension will be able to pick things up 🙂

@melanieseltzer Thank you for sharing this! This is a great workaround.

ughitsaaron avatar May 05 '22 00:05 ughitsaaron