云
4 天以前 2c3df98c784bd825b6c2faab508e20fe4f2c3966
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
54
55
56
57
58
59
60
61
62
63
64
65
/** 浮标展开诊断:判断「点浮标恢复面板」失败是前端 bug 还是测试选择器问题 */
const { chromium } = require('playwright');
 
const BASE = 'http://127.0.0.1:5666';
const UUID = 'ae1229655a3e48d7b4bc842e3e74e15c';
 
(async () => {
  const browser = await chromium.launch({ headless: true });
  const page = await browser.newPage({ viewport: { width: 1600, height: 900 } });
  await page.addInitScript(() => {
    Object.defineProperty(window, 'showSaveFilePicker', { value: undefined, configurable: true });
  });
 
  await page.goto(`${BASE}/auth/login`, { waitUntil: 'domcontentloaded' });
  await page.locator('input[name=username]').waitFor({ timeout: 60_000 });
  await page.locator('input[name=username]').fill('admin');
  await page.locator('input[name=password]').fill('admin123');
  await page.locator('button:has-text("登录")').last().click();
  await page.waitForURL((u) => !u.pathname.includes('/auth/login'), { timeout: 60_000 });
 
  await page.goto(`${BASE}/bagcode/bag-code`, { waitUntil: 'domcontentloaded' });
  await page.getByRole('button', { name: '导出二维码' }).first().waitFor({ timeout: 60_000 });
  await page.getByPlaceholder('请输入生成组编号').fill(UUID);
  const searchBtn = page.locator('button').filter({ hasText: /搜\s*索/ });
  await searchBtn.first().click();
  await page.waitForTimeout(3000);
  await page.getByRole('button', { name: '导出二维码' }).first().click();
  await page.locator('text=正在生成二维码').waitFor({ timeout: 90_000 });
  console.log('面板已出现');
 
  // 点隐藏
  const hideBtn = page.locator('button').filter({ hasText: /隐\s*藏/ });
  console.log('隐藏按钮数:', await hideBtn.count());
  await hideBtn.first().click();
  await page.waitForTimeout(1500);
 
  // 找出所有含「二维码导出」的 div,打印层级与位置
  const cands = page.locator('div').filter({ hasText: /二维码导出/ });
  const n = await cands.count();
  console.log('\n含「二维码导出」的 div 数量:', n);
  for (let i = 0; i < n; i++) {
    const el = cands.nth(i);
    const info = await el.evaluate((node) => ({
      cls: node.className?.toString().slice(0, 70),
      text: (node.innerText || '').replace(/\s+/g, ' ').slice(0, 40),
      depth: (() => { let d = 0, p = node; while (p.parentElement) { d++; p = p.parentElement; } return d; })(),
    }));
    console.log(`  [${i}] depth=${info.depth} cls="${info.cls}" text="${info.text}"`);
  }
 
  const pill = cands.last();
  console.log('\n拟点击 last() 元素,其 class:', await pill.evaluate((n) => n.className?.toString().slice(0, 70)));
  await pill.click();
  await page.waitForTimeout(2000);
 
  const bodyText = await page.locator('body').innerText();
  console.log('\n点击后:');
  console.log('  body 含「正在生成二维码」:', bodyText.includes('正在生成二维码'));
  console.log('  body 含「二维码导出」:', bodyText.includes('二维码导出'));
  console.log('  隐藏按钮是否还在:', await page.locator('button').filter({ hasText: /隐\s*藏/ }).count());
  const m = bodyText.match(/正在生成(\d+\s*\/\s*\d+)/);
  console.log('  进度文本:', m ? m[0] : '(未找到)');
 
  await browser.close();
})();