modify web test scripts
This commit is contained in:
parent
f51dbb400a
commit
b4556d86c2
@ -79,8 +79,8 @@ fi
|
|||||||
#=============================
|
#=============================
|
||||||
# Step 3: Verify alert received by Alertmanager
|
# Step 3: Verify alert received by Alertmanager
|
||||||
#=============================
|
#=============================
|
||||||
log_info "Waiting for alert propagation (~5 seconds)..."
|
log_info "Waiting for alert propagation (~30 seconds)..."
|
||||||
sleep 5
|
sleep 30
|
||||||
|
|
||||||
if curl -s "${ALERT_URL}/api/v2/alerts" | grep -q "DeployVerifyAlert"; then
|
if curl -s "${ALERT_URL}/api/v2/alerts" | grep -q "DeployVerifyAlert"; then
|
||||||
log_success "Prometheus → Alertmanager alert path verified successfully"
|
log_success "Prometheus → Alertmanager alert path verified successfully"
|
||||||
|
|||||||
@ -64,8 +64,20 @@ if [ ! -d "node_modules" ]; then
|
|||||||
npm ci
|
npm ci
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log_info "Ensuring Playwright browsers are installed..."
|
log_info "Checking Playwright browsers..."
|
||||||
npx playwright install --with-deps > /dev/null
|
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
|
# Clean previous reports
|
||||||
rm -rf "$REPORT_DIR"
|
rm -rf "$REPORT_DIR"
|
||||||
|
|||||||
@ -43,16 +43,6 @@ test.describe("Alerts 页面功能测试", () => {
|
|||||||
|
|
||||||
await expect(stateSelect).toHaveValue("Active");
|
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️⃣ 验证筛选结果(可选)
|
// 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);
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@ -133,11 +133,33 @@ test.describe("节点信息页面 NodeInfo", () => {
|
|||||||
await closeBtn.click({force: true});
|
await closeBtn.click({force: true});
|
||||||
await expect(drawer).toBeHidden();
|
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}) => {
|
for (let i = 0; i < count; i++) {
|
||||||
await page.goto(`${BASE_URL}/node`);
|
const button = grafanaButtons.nth(i);
|
||||||
const grafanaLink = page.getByRole("link", {name: "Grafana"}).first();
|
await expect(button).toBeVisible({ timeout: 10000 });
|
||||||
await grafanaLink.waitFor({timeout: 10000});
|
|
||||||
await expect(grafanaLink).toHaveAttribute("href", /\/d\/node_gpu_metrics/);
|
// 获取 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();
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user