65 lines
2.6 KiB
JavaScript
65 lines
2.6 KiB
JavaScript
import { chromium } from 'playwright';
|
|
|
|
const BASE = 'http://localhost:9027';
|
|
|
|
(async () => {
|
|
const browser = await chromium.launch();
|
|
const ctx = await browser.newContext({ viewport: { width: 1440, height: 900 } });
|
|
const page = await ctx.newPage();
|
|
|
|
await page.goto(`${BASE}/view/mhzc/home`, { waitUntil: 'networkidle', timeout: 30000 });
|
|
await page.waitForSelector('.capability-section', { timeout: 20000 });
|
|
await page.evaluate(() => {
|
|
const el = document.getElementById('section-capability');
|
|
if (el) el.scrollIntoView({ behavior: 'instant', block: 'start' });
|
|
});
|
|
await page.waitForTimeout(800);
|
|
|
|
// 测试所有 6 个标签
|
|
const labels = ['碳核算平台', '碳交易平台', '碳认证机构', '碳金融服务', '碳技术咨询', '更多能力'];
|
|
const expectedAnchors = ['content-1', 'content-3', 'content-2', 'content-4', 'content-5', null];
|
|
|
|
for (let i = 0; i < labels.length; i++) {
|
|
await page.locator('.capability-card').nth(i).click();
|
|
await page.waitForFunction(() => location.href.includes('gxnlpt'), { timeout: 5000 });
|
|
await page.waitForTimeout(2500);
|
|
|
|
const data = await page.evaluate(() => {
|
|
const sideItems = document.querySelectorAll('.gxnlpt-side-item');
|
|
const active = Array.from(sideItems).map((el, idx) => ({
|
|
idx, text: el.textContent.trim(), active: el.classList.contains('is-active')
|
|
})).find(x => x.active);
|
|
const content1 = document.getElementById('content-1');
|
|
const content2 = document.getElementById('content-2');
|
|
const content3 = document.getElementById('content-3');
|
|
const content4 = document.getElementById('content-4');
|
|
const content5 = document.getElementById('content-5');
|
|
const rects = {};
|
|
for (const el of [content1, content2, content3, content4, content5]) {
|
|
if (el) rects[el.id] = Math.round(el.getBoundingClientRect().top);
|
|
}
|
|
return {
|
|
url: location.href,
|
|
scrollTop: document.querySelector('.content-wrap').scrollTop,
|
|
activeTab: active,
|
|
sectionTops: rects,
|
|
};
|
|
});
|
|
console.log(`[${labels[i]}]`, JSON.stringify(data));
|
|
|
|
// 回到首页
|
|
await page.goto(`${BASE}/view/mhzc/home`, { waitUntil: 'networkidle', timeout: 30000 });
|
|
await page.waitForSelector('.capability-section', { timeout: 20000 });
|
|
await page.evaluate(() => {
|
|
const el = document.getElementById('section-capability');
|
|
if (el) el.scrollIntoView({ behavior: 'instant', block: 'start' });
|
|
});
|
|
await page.waitForTimeout(800);
|
|
}
|
|
|
|
await browser.close();
|
|
})().catch((e) => {
|
|
console.error('TEST ERROR', e);
|
|
process.exit(1);
|
|
});
|