仰望星辰工作室

miaopanel

miaopanel/ scripts/ui-create-go.mjs 1.9 KB · 46 行 原始文件
1// End-to-end: create a Go site through the dialog (binary picker + port).
2import { chromium } from 'playwright'
3
4const base = process.argv[2]
5const password = process.argv[3]
6const out = process.argv[4] || '.'
7
8const browser = await chromium.launch()
9const page = await browser.newPage({ viewport: { width: 1440, height: 1000 }, deviceScaleFactor: 2 })
10const errors = []
11page.on('pageerror', (e) => errors.push('pageerror: ' + e.message))
12page.on('console', (m) => {
13 if (m.type() === 'error') errors.push('console: ' + m.text())
14})
15
16await page.goto(base + '/', { waitUntil: 'networkidle' })
17await page.fill('input[autocomplete="username"]', 'admin')
18await page.fill('input[type="password"]', password)
19await page.click('button[type="submit"]')
20await page.waitForTimeout(2000)
21await page.getByRole('button', { name: '网站' }).click()
22await page.waitForTimeout(400)
23await page.getByRole('button', { name: '新建站点' }).click()
24await page.getByRole('button', { name: 'Go 应用' }).click()
25await page.waitForTimeout(300)
26
27await page.fill('textarea', 'uitest.go')
28await page.getByRole('button', { name: '浏览' }).first().click()
29await page.waitForTimeout(600)
30await page.locator('.dir-row', { hasText: 'uitest' }).first().click()
31await page.waitForTimeout(800)
32await page.locator('.dir-row.exec').first().click()
33await page.waitForTimeout(400)
34await page.getByPlaceholder('留空自动分配').fill('8080')
35await page.screenshot({ path: `${out}/ui-create-go-filled.png` })
36
37await page.getByRole('button', { name: '创建站点' }).click()
38await page.waitForTimeout(3500)
39await page.screenshot({ path: `${out}/ui-create-go-result.png` })
40
41const toast = await page.locator('.toast').innerText().catch(() => '(no toast)')
42const modal = await page.locator('.create-modal').count()
43const row = await page.getByText('uitest', { exact: false }).count()
44console.log(JSON.stringify({ toast, modalStillOpen: modal > 0, rowMatches: row, errors }, null, 2))
45
46await browser.close()