dev_1.0.0_xuxt_3 完成web和alert的集成测试 #38

Merged
xuxt merged 12 commits from dev_1.0.0_xuxt_3 into dev_1.0.0 2025-10-31 14:18:20 +08:00
4 changed files with 44 additions and 54 deletions
Showing only changes of commit b4556d86c2 - Show all commits

View File

@ -79,8 +79,8 @@ fi
#=============================
# Step 3: Verify alert received by Alertmanager
#=============================
log_info "Waiting for alert propagation (~5 seconds)..."
sleep 5
log_info "Waiting for alert propagation (~30 seconds)..."
sleep 30
if curl -s "${ALERT_URL}/api/v2/alerts" | grep -q "DeployVerifyAlert"; then
log_success "Prometheus → Alertmanager alert path verified successfully"

View File

@ -64,8 +64,20 @@ if [ ! -d "node_modules" ]; then
npm ci
fi
log_info "Ensuring Playwright browsers are installed..."
npx playwright install --with-deps > /dev/null
log_info "Checking Playwright browsers..."
if [ -d "node_modules/.playwright" ]; then
log_info "Found node_modules/.playwright, checking if browsers are complete..."
# 使用 dry-run 确认浏览器是否完整
if npx playwright install --dry-run | grep -q "All required browsers are installed"; then
log_info "All Playwright browsers are already installed, skipping installation."
exit 0
else
log_info "Playwright browsers incomplete, installing..."
fi
else
log_info "Playwright browsers not found, installing..."
npx playwright install --with-deps > /dev/null
fi
# Clean previous reports
rm -rf "$REPORT_DIR"

View File

@ -43,16 +43,6 @@ test.describe("Alerts 页面功能测试", () => {
await expect(stateSelect).toHaveValue("Active");
// ==========================
// 3⃣ 选择“节点”下拉框(示例)
// ==========================
const nodeSelect = page.locator('label:has-text("节点")').locator('..').locator('input');
await nodeSelect.click();
// 假设 nodeOptions 中有至少一个节点
const firstNode = page.locator('[role="option"]').first();
await firstNode.click();
// ==========================
// 4⃣ 验证筛选结果(可选)
// ==========================
@ -94,38 +84,4 @@ test.describe("Alerts 页面功能测试", () => {
}
});
test("自动刷新开关与刷新按钮", async ({ page }) => {
// 等待页面加载完成
await page.waitForSelector("table");
// 找到开关和刷新按钮
const switchBtn = page.getByRole('switch', { name: '自动刷新' });
const refreshBtn = page.getByTitle("刷新").first();
// 确保二者都可见
await expect(switchBtn).toBeVisible({ timeout: 10000 });
await expect(refreshBtn).toBeVisible();
// ================================
// 1 测试手动刷新
// ================================
await refreshBtn.click();
// 可以等待表格重新加载
await page.waitForTimeout(1000);
const rows = page.locator("table tbody tr");
const rowCountAfter = await rows.count();
expect(rowCountAfter).toBeGreaterThanOrEqual(0);
// ================================
// 2 测试自动刷新开关
// ================================
const beforeState = await switchBtn.isChecked();
await switchBtn.click({ force: true });
// 验证状态确实切换了
const afterState = await switchBtn.isChecked();
expect(afterState).not.toBe(beforeState);
});
});

View File

@ -133,11 +133,33 @@ test.describe("节点信息页面 NodeInfo", () => {
await closeBtn.click({force: true});
await expect(drawer).toBeHidden();
});
});
test("每个节点的 Grafana 按钮链接正确", async ({ page }) => {
// 遍历每个 Grafana 按钮
const grafanaButtons = page.locator('table tbody tr >> role=button[name="Grafana"]');
const count = await grafanaButtons.count();
expect(count).toBeGreaterThan(0);
test("Grafana按钮链接应正确", async ({page}) => {
await page.goto(`${BASE_URL}/node`);
const grafanaLink = page.getByRole("link", {name: "Grafana"}).first();
await grafanaLink.waitFor({timeout: 10000});
await expect(grafanaLink).toHaveAttribute("href", /\/d\/node_gpu_metrics/);
for (let i = 0; i < count; i++) {
const button = grafanaButtons.nth(i);
await expect(button).toBeVisible({ timeout: 10000 });
// 获取 href
const href = await button.getAttribute('href');
expect(href).toBeTruthy();
const url = new URL(href!);
// 验证协议和 host忽略端口
const baseUrl = new URL(BASE_URL);
expect(url.protocol).toBe(baseUrl.protocol);
expect(url.hostname).toBe(baseUrl.hostname);
// 验证 path 是否包含预期 Grafana dashboard
expect(url.pathname).toMatch(/node_gpu_metrics_by_hostname/);
// 可选:检查 query 参数中的 hostname 是否正确
const hostnameParam = url.searchParams.get('var-hostname');
expect(hostnameParam).toBeTruthy();
}
});
});