@@ -29,27 +29,33 @@ npm ls -g @playwright/cli 2>/dev/null || npm install -g @playwright/cli@latest
29292 . ** Start the component's Storybook dev server:**
3030
3131 ``` bash
32- # Use the stories package directly — much faster than the full VR tests app
33- yarn nx run react-< component> -stories:start &
32+ yarn nx run react-< component> :start &
3433 ```
3534
36- Wait for Storybook to be ready on port 6006. Check with:
35+ The port is ** dynamic** — parse it from the Storybook startup output. Look for the ` Local: ` line
36+ (e.g. ` Local: http://localhost:61582/ ` ). Extract the port and store it in a variable:
3737
3838 ``` bash
39- curl -s -o /dev/null -w " %{http_code}" http://localhost:6006 2> /dev/null
39+ # Wait for Storybook to print its URL, then extract the port
40+ # Or poll common ports until one responds:
41+ for port in 6006 61582 $( seq 6007 6020) ; do
42+ STATUS=$( curl -s -o /dev/null -w " %{http_code}" http://localhost:$port 2> /dev/null)
43+ if [ " $STATUS " = " 200" ]; then SB_PORT=$port ; break ; fi
44+ done
45+ echo " Storybook on port $SB_PORT "
4046 ```
4147
42483 . ** Open the page with playwright-cli:**
4349
4450 ``` bash
45- playwright-cli open " http://localhost:6006 "
51+ playwright-cli open " http://localhost:$SB_PORT "
4652 ```
4753
48544 . ** Navigate to the specific story iframe** and capture a screenshot.
4955 Use the iframe URL for a clean render without Storybook chrome:
5056
5157 ``` bash
52- playwright-cli goto " http://localhost:6006 /iframe.html?id=components-<component> -<component>--default&viewMode=story"
58+ playwright-cli goto " http://localhost:$SB_PORT /iframe.html?id=components-<component>--default&viewMode=story"
5359 playwright-cli screenshot --filename=/tmp/visual-test-$ARGUMENTS .png
5460 ```
5561
@@ -68,23 +74,23 @@ npm ls -g @playwright/cli 2>/dev/null || npm install -g @playwright/cli@latest
68748 . ** Clean up** when done:
6975 ``` bash
7076 playwright-cli close
71- # Kill the storybook process
72- kill %1 2> /dev/null
77+ # Kill storybook by port
78+ lsof -i : $SB_PORT -t 2> /dev/null | xargs kill 2> /dev/null
7379 ```
7480
7581## Story ID Pattern
7682
77- Story IDs follow the pattern ` <category>-<subcategory>-< component>--<story> ` :
83+ Story IDs follow the pattern ` <category>-<component>--<story> ` :
7884
7985```
8086# Default story for Button
81- components-button-button- -default
87+ components-button--default
8288
8389# Appearance variant
84- components-button-button- -appearance
90+ components-button--appearance
8591
8692# Default story for Menu
87- components-menu-menu- -default
93+ components-menu--default
8894```
8995
9096To discover exact story IDs, open the Storybook sidebar and use ` snapshot ` to find navigation links,
@@ -93,11 +99,11 @@ or check the story file's `export default { title: '...' }` metadata.
9399## Iframe URL Format
94100
95101```
96- # Local storybook
97- http://localhost:6006 /iframe.html?id=components-button -button--default&viewMode=story
102+ # Local storybook (replace $SB_PORT with the actual port)
103+ http://localhost:$SB_PORT /iframe.html?id=components-button--default&viewMode=story
98104
99105# Dark theme
100- http://localhost:6006 /iframe.html?id=components-button -button--default&viewMode=story&globals=theme:webDarkTheme
106+ http://localhost:$SB_PORT /iframe.html?id=components-button--default&viewMode=story&globals=theme:webDarkTheme
101107```
102108
103109The ` /iframe.html ` URL gives a clean render without Storybook chrome — always prefer this for screenshots.
0 commit comments