_tab2.mjs 1.3 KB

12345678910111213141516171819202122
  1. import { chromium } from 'playwright';
  2. const b = await chromium.launch({ executablePath: 'C:/Program Files/Google/Chrome/Application/chrome.exe' });
  3. const p = await (await b.newContext({ viewport: { width: 390, height: 844 } })).newPage();
  4. const clear = () => p.evaluate(() => document.querySelectorAll('vite-error-overlay').forEach(e=>e.remove()));
  5. await p.goto('http://localhost:4200/login', { waitUntil:'networkidle' });
  6. await clear(); await p.waitForTimeout(900);
  7. const ins = await p.locator('ui-input input, ui-m-field input').all();
  8. await ins[0].fill('13800138000'); await ins[1].fill('123456');
  9. await p.getByText('登 录', { exact:false }).first().click();
  10. await p.waitForTimeout(3000);
  11. for (const [name, path] of [['首页','/mobile/home'],['会话','/mobile/messages'],['工作台','/mobile/workbench']]) {
  12. await p.goto('http://localhost:4200'+path, { waitUntil:'networkidle' });
  13. await clear(); await p.waitForTimeout(1500);
  14. const r = await p.evaluate(() => {
  15. const btns = [...document.querySelectorAll('ui-m-tabbar button')];
  16. const active = btns.findIndex(b => b.className.includes('text-primary'));
  17. return { labels: btns.map(b=>b.textContent.trim().replace(/\d+/g,'').trim()), activeIdx: active };
  18. });
  19. console.log(`${name.padEnd(6)} 激活Tab=${r.activeIdx >= 0 ? r.labels[r.activeIdx] : '无'} (期望: ${name})`);
  20. }
  21. await b.close();