Skip to content

Commit

Permalink
chore: fix scrollToBottom for screenshots (#1911)
Browse files Browse the repository at this point in the history
* chore: fix scrollToBottom for screenshots

* chore: increase sleep by 1s
  • Loading branch information
markphelps committed Jul 27, 2023
1 parent 929bdc3 commit b7cc760
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
13 changes: 10 additions & 3 deletions ui/screenshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ const screenshot = async (page, name) => {
await page.screenshot({ path: 'screenshots/' + name });
};

const scrollToBottom = async (page) => {
await sleep(1000);
await page.evaluate(() => {
window.scrollTo(0, document.body.scrollHeight);
});
};

const sleep = (delay) => new Promise((resolve) => setTimeout(resolve, delay));

const capture = async function (folder, name, fn, opts = {}) {
Expand Down Expand Up @@ -43,17 +50,17 @@ const capture = async function (folder, name, fn, opts = {}) {
const browser = await chromium.launch({ headless: true });
const context = await browser.newContext({
viewport: { width: 1440, height: 900 },
deviceScaleFactor: 3,
deviceScaleFactor: 3
});
const page = await context.newPage();

await page.goto(fliptAddr);
await fn(page);
await sleep(3000);
await sleep(4000);
await screenshot(page, `${folder}/${name}.png`);

await context.close();
await browser.close();
};

module.exports = { capture, sleep, screenshot };
module.exports = { capture, sleep, screenshot, scrollToBottom };
7 changes: 2 additions & 5 deletions ui/screenshot/concepts/constraints.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
const { capture } = require('../../screenshot.js');
const { capture, scrollToBottom } = require('../../screenshot.js');

(async () => {
await capture('concepts', 'constraints', async (page) => {
await page.getByRole('link', { name: 'Segments' }).click();
await page.getByRole('link', { name: 'new-users' }).click();
await page.evaluate(() =>
// scroll to bottom of page to show all constraints
window.scrollTo(0, document.documentElement.scrollHeight)
);
await scrollToBottom(page);
});
})();
7 changes: 2 additions & 5 deletions ui/screenshot/concepts/rollouts.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
const { capture } = require('../../screenshot.js');
const { capture, scrollToBottom } = require('../../screenshot.js');

(async () => {
await capture('concepts', 'rollouts', async (page) => {
await page.getByRole('link', { name: 'new-contact-page' }).click();
await page.evaluate(() =>
// scroll to bottom of page to show all rollouts
window.scrollTo(0, document.documentElement.scrollHeight)
);
await scrollToBottom(page);
});
})();
7 changes: 2 additions & 5 deletions ui/screenshot/concepts/variants.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
const { capture } = require('../../screenshot.js');
const { capture, scrollToBottom } = require('../../screenshot.js');

(async () => {
await capture('concepts', 'variants', async (page) => {
await page.getByRole('link', { name: 'colorscheme' }).click();
await page.evaluate(() =>
// scroll to bottom of page to show all variants
window.scrollTo(0, document.documentElement.scrollHeight)
);
await scrollToBottom(page);
});
})();

0 comments on commit b7cc760

Please sign in to comment.