Storybook setup.
Storywright is a tool to capture screenshots for React Storybook using Playwright.
Storywright works alongside Storybook to produce screenshots of the stories. In addition, it has capability to interact with the stories by clicking, hovering, waiting and many more actions.
Storywright exposes a React component,
If we have a button component, , and a story around that component, Button.stories.tsx, then:
In Button.stories.tsx:
``bash
const StoryWrightDemo = (story) =>
{story()}
}
export default {
title: "Button",
decorators: [StoryWrightDemo]
}
export const ButtonStory = () =>
`
Above code will take screenshot of the whole page where
Here is an same example as above with interactions:
`bash
const StoryWrightDemo = (story) =>
click('.btn')
.snapshot('snapshot1')
.end()}
>
{story()}
}
export default {
title: "Button",
decorators: [StoryWrightDemo]
}
export const ButtonStory = () =>
`
Following methods are currently available:
- click(selector: string)snapshot(filename: string)
- hover(selector: string)
- mouseUp(selector: string)
- mouseDown(selector: string)
- setValue(selector: string, value: string)
- keys(selector: string, keys: string)
- focus(selector: string)
- executeScript(code: string)
- wait(selector: string)
- waitForNotFound(selector: string)
- click(selector)
- waitForTimeout(millisecs: number)`
-