Created
October 30, 2023 17:54
-
-
Save kblok/025dd19d1aaad13175f8cdf6fd5d907a to your computer and use it in GitHub Desktop.
Navigate to storybook stories on playwright
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import {Page} from '@playwright/test'; | |
| import fs from 'fs'; | |
| import path from 'path'; | |
| export const STORIES_FILE = path.join( | |
| __dirname, | |
| '..', | |
| 'storybook-static', | |
| 'stories.json', | |
| ); | |
| export const loadStory = async (page: Page, storyID: string): Promise<void> => { | |
| if (!fs.existsSync(STORIES_FILE)) { | |
| console.error( | |
| '✘ Could not find storybook-static/stories.json. Try rebuilding with `npm run build:sb`', | |
| ); | |
| return; | |
| } | |
| const storiesManifest = JSON.parse(fs.readFileSync(STORIES_FILE, 'utf8')); | |
| // load specific story | |
| const storyMeta = storiesManifest.stories[storyID]; | |
| if (!storyMeta) { | |
| console.error( | |
| `✘ Could not find story ID "${storyID}". Try rebuilding with \`npm run build:sb\``, | |
| ); | |
| return; | |
| } | |
| const search = new URLSearchParams({viewMode: 'story', id: storyMeta.id}); | |
| await page.goto(`iframe.html?${search.toString()}`); | |
| // wait for page to finish rendering before starting test | |
| await page.waitForSelector('#root'); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment