Capture screenshots for React Storybook using Playwright
Перейти к файлу
Service Account 4dbc183eb7 New changes 2022-08-10 12:48:46 +05:30
.github/workflows Add prettier 2021-07-22 17:16:27 +02:00
.vscode Remove unwanted screenshot frames check and add default 1 sec wait to avoid css rendering issues (#37) 2021-12-22 16:05:36 +05:30
bin Storywright - Capture screenshot for storybook (#13) 2021-07-09 11:15:22 +05:30
src New changes 2022-08-10 12:48:46 +05:30
.gitignore Storywright - Capture screenshot for storybook (#13) 2021-07-09 11:15:22 +05:30
CODE_OF_CONDUCT.md Initial CODE_OF_CONDUCT.md commit 2021-04-10 05:15:15 -07:00
LICENSE Initial LICENSE commit 2021-04-10 05:15:16 -07:00
README.md New Changes 2022-02-04 12:17:48 +05:30
SECURITY.md Add prettier 2021-07-22 17:16:27 +02:00
SUPPORT.md Add prettier 2021-07-22 17:16:27 +02:00
package-lock.json Add Mutation observer (#41) 2022-01-10 17:39:44 +05:30
package.json Hacky fix to add timeout on testbutton click (#42) 2022-01-27 15:53:55 +05:30
pageinit.back Fix timeout calculation in page (#29) 2021-12-15 18:05:21 +05:30
tsconfig.json Storywright - Capture screenshot for storybook (#13) 2021-07-09 11:15:22 +05:30
yarn.lock Bump ansi-regex from 5.0.0 to 5.0.1 (#24) 2021-11-11 10:39:33 +01:00

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

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)