-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlayout-test.js
More file actions
53 lines (42 loc) · 1.61 KB
/
layout-test.js
File metadata and controls
53 lines (42 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const { chromium } = require('@playwright/test');
(async () => {
const browser = await chromium.launch();
const page = await browser.newPage();
// 로컬 개발 서버로 이동
await page.goto('http://localhost:3000');
// 페이지가 완전히 로드될 때까지 기다림
await page.waitForLoadState('networkidle');
const viewports = [
{ width: 1280, height: 800, name: '1280x800' },
{ width: 1440, height: 900, name: '1440x900' },
{ width: 1920, height: 1080, name: '1920x1080' }
];
for (const viewport of viewports) {
console.log(`Testing viewport: ${viewport.name}`);
// 뷰포트 설정
await page.setViewportSize({ width: viewport.width, height: viewport.height });
// 레이아웃이 적용될 시간을 줌
await page.waitForTimeout(1000);
// 메인 콘텐츠의 여백을 측정
const mainElement = await page.locator('main').first();
const boundingBox = await mainElement.boundingBox();
const paddingLeft = await mainElement.evaluate(el =>
parseInt(window.getComputedStyle(el).paddingLeft)
);
const paddingRight = await mainElement.evaluate(el =>
parseInt(window.getComputedStyle(el).paddingRight)
);
console.log(`Viewport: ${viewport.name}`);
console.log(`Main element width: ${boundingBox.width}px`);
console.log(`Padding left: ${paddingLeft}px`);
console.log(`Padding right: ${paddingRight}px`);
console.log('---');
// 스크린샷 촬영
await page.screenshot({
path: `layout-${viewport.name}.png`,
fullPage: false
});
}
await browser.close();
console.log('Screenshots saved!');
})();