Capture screenshots for React Storybook using Playwright
Перейти к файлу
siyadava-sindhu 4fc65da673
Bumping React & types/React to V18 (#64)
* Bumping React & types/React to V18

* updating bump version to 1.0.0 since it has major R18 upgrade

* moving react and types/react to devdeps&peerdeps

* fixing syntactical error
2024-03-19 21:07:11 +05:30
.github/workflows
.vscode
bin
src
.gitignore
CODE_OF_CONDUCT.md
LICENSE
README.md
SECURITY.md
SUPPORT.md
package-lock.json
package.json Bumping React & types/React to V18 (#64) 2024-03-19 21:07:11 +05:30
pageinit.back
tsconfig.json
yarn.lock

README.md

Storywright

Storywright is a tool to capture screenshots for React Storybook using Playwright.

How it works

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, , which can be added as a decorator in stories. For eg:

If we have a button component, , and a story around that component, Button.stories.tsx, then:

In Button.stories.tsx:

const StoryWrightDemo = (story) => 
    <StoryWright>
        {story()}
    </StoryWright>
}

export default {
    title: "Button",
    decorators: [StoryWrightDemo]
}

export const ButtonStory = () => <Button></Button>

Above code will take screenshot of the whole page where Button is rendered.

Testing Interactions

To test interactions, you can add Steps to each state to interact with the UI. This is useful for clicking buttons, filling out forms, and getting the UI into the proper visual state to test.

Here is an same example as above with interactions:

const StoryWrightDemo = (story) => 
    <StoryWright
        steps={new Steps()
        click('.btn')
        .snapshot('snapshot1')
        .end()}
    >
        {story()}
    </StoryWright>
}

export default {
    title: "Button",
    decorators: [StoryWrightDemo]
}

export const ButtonStory = () => <Button></Button>

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)