-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathoverflow-586-shots.spec.ts
More file actions
50 lines (42 loc) · 1.78 KB
/
Copy pathoverflow-586-shots.spec.ts
File metadata and controls
50 lines (42 loc) · 1.78 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
import { test } from '@playwright/test'
import { loginAsStudent } from '../utils/auth'
import { BASE, LOCALE } from '../utils/constants'
/**
* Screenshot capture for issue #586. Run with SHOT_LABEL=before (untouched code)
* and again with SHOT_LABEL=after (with the fix) to produce a matching pair.
*/
const LABEL = process.env.SHOT_LABEL || 'before'
const OUT = process.env.SHOT_DIR || 'docs/qa'
const SHOTS = [
{ name: 'student-dashboard', path: `/${LOCALE}/dashboard/student`, width: 768 },
{ name: 'student-dashboard', path: `/${LOCALE}/dashboard/student`, width: 820 },
{ name: 'student-courses', path: `/${LOCALE}/dashboard/student/courses`, width: 768 },
]
test('capture #586 shots', async ({ page }) => {
test.setTimeout(180_000)
await loginAsStudent(page)
for (const shot of SHOTS) {
await page.setViewportSize({ width: shot.width, height: 900 })
await page.goto(`${BASE}${shot.path}`)
await page.waitForLoadState('networkidle').catch(() => {})
await page.waitForTimeout(1200)
// Scroll fully right so the shot shows the overflow rather than hiding it.
const metrics = await page.evaluate(() => {
const doc = document.documentElement
return { client: doc.clientWidth, scroll: doc.scrollWidth }
})
console.log(
`${shot.name}@${shot.width} client=${metrics.client} scroll=${metrics.scroll} overflow=${metrics.scroll - metrics.client}`
)
await page.screenshot({
path: `${OUT}/586-${LABEL}-${shot.name}-${shot.width}.png`,
})
if (metrics.scroll > metrics.client) {
await page.evaluate(() => window.scrollTo(document.documentElement.scrollWidth, 0))
await page.waitForTimeout(400)
await page.screenshot({
path: `${OUT}/586-${LABEL}-${shot.name}-${shot.width}-scrolled-right.png`,
})
}
}
})