Skip to content

Commit

Permalink
fix locator
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp committed Nov 25, 2024
1 parent b943bf5 commit 31fec90
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default function AppNavbar() {
Dashboard
</Typography>
</Stack>
<ColorModeIconDropdown data-screenshot="" />
<ColorModeIconDropdown />
<MenuButton aria-label="menu" onClick={toggleDrawer(true)}>
<MenuRoundedIcon />
</MenuButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default function AppNavbar() {
Dashboard
</Typography>
</Stack>
<ColorModeIconDropdown data-screenshot="" />
<ColorModeIconDropdown />
<MenuButton aria-label="menu" onClick={toggleDrawer(true)}>
<MenuRoundedIcon />
</MenuButton>
Expand Down
16 changes: 10 additions & 6 deletions docs/scripts/generateTemplateScreenshots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,43 +79,47 @@ const names = new Set(process.argv.slice(2));
(file) => `/${project}/getting-started/templates/${file.replace(/\.(js|tsx)$/, '/')}`,
);

async function toggleMode() {
await page.locator('css=[data-screenshot="toggle-mode"]').locator('visible=true').click();
}

async function captureDarkMode(outputPath: string) {
const btn = await page.$('[data-screenshot="toggle-mode"]');
if (btn) {
if ((await btn.getAttribute('aria-haspopup')) === 'true') {
await page.click('[data-screenshot="toggle-mode"]');
await toggleMode();
await page.getByRole('menuitem').filter({ hasText: /dark/i }).click();
await page.waitForLoadState('networkidle'); // changing to dark mode might trigger image loading
await sleep(100); // give time for image decoding, resizing, rendering

await page.screenshot({ path: outputPath, animations: 'disabled' });

await page.click('[data-screenshot="toggle-mode"]');
await toggleMode();
await page
.getByRole('menuitem')
.filter({ hasText: /system/i })
.click(); // switch back to light
} else if ((await btn.getAttribute('aria-haspopup')) === 'listbox') {
await page.click('[data-screenshot="toggle-mode"]');
await toggleMode();
await page.getByRole('option').filter({ hasText: /dark/i }).click();
await page.waitForLoadState('networkidle'); // changing to dark mode might trigger image loading
await sleep(100); // give time for image decoding, resizing, rendering

await page.screenshot({ path: outputPath, animations: 'disabled' });

await page.click('[data-screenshot="toggle-mode"]');
await toggleMode();
await page
.getByRole('option')
.filter({ hasText: /system/i })
.click(); // switch back to light
} else {
await page.click('[data-screenshot="toggle-mode"]');
await toggleMode();
await page.waitForLoadState('networkidle'); // changing to dark mode might trigger image loading
await sleep(100); // give time for image decoding, resizing, rendering

await page.screenshot({ path: outputPath, animations: 'disabled' });

await page.click('[data-screenshot="toggle-mode"]'); // switch back to light
await toggleMode(); // switch back to light
}
}
}
Expand Down

0 comments on commit 31fec90

Please sign in to comment.