You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
3.8 KiB
99 lines
3.8 KiB
import { test, expect } from "@playwright/test";
|
|
import { E2E_ADMIN, FIXED_CAPTCHA } from "../fixtures/test-users";
|
|
|
|
test("诊断: 发送消息流程", async ({ page }) => {
|
|
const consoleMessages: string[] = [];
|
|
const pageErrors: string[] = [];
|
|
const networkRequests: string[] = [];
|
|
|
|
page.on("console", (msg) => {
|
|
consoleMessages.push(`[${msg.type()}] ${msg.text()}`);
|
|
});
|
|
page.on("pageerror", (err) => {
|
|
pageErrors.push(err.message);
|
|
});
|
|
page.on("request", (req) => {
|
|
if (req.url().includes("/api/")) {
|
|
networkRequests.push(`REQ ${req.method()} ${req.url()}`);
|
|
}
|
|
});
|
|
page.on("response", (res) => {
|
|
if (res.url().includes("/api/agents") || res.url().includes("/api/llm")) {
|
|
networkRequests.push(`RES ${res.status()} ${res.url()}`);
|
|
}
|
|
});
|
|
|
|
await page.goto("/auth/login");
|
|
await page.fill("#login-username", E2E_ADMIN.username);
|
|
await page.fill("#login-password", E2E_ADMIN.password);
|
|
await page.fill("#login-captcha", FIXED_CAPTCHA);
|
|
await page.click('button[type="submit"]');
|
|
await page.waitForURL("/chat/default", { timeout: 15000 });
|
|
await expect(page.locator(".agent-textarea")).toBeVisible({ timeout: 10000 });
|
|
await page.waitForTimeout(2000);
|
|
|
|
const configRes = await page.evaluate(async () => {
|
|
const r = await fetch("/api/config/me");
|
|
return { status: r.status, body: await r.json() };
|
|
});
|
|
console.log("=== /api/config/me ===", JSON.stringify(configRes));
|
|
|
|
const modelsRes = await page.evaluate(async () => {
|
|
const r = await fetch("/api/llm/models");
|
|
return { status: r.status, body: await r.json() };
|
|
});
|
|
console.log("=== /api/llm/models ===", JSON.stringify(modelsRes));
|
|
|
|
const sessionsRes = await page.evaluate(async () => {
|
|
const r = await fetch("/api/agents/default/sessions");
|
|
return { status: r.status, body: await r.json() };
|
|
});
|
|
console.log("=== /api/agents/default/sessions ===", JSON.stringify(sessionsRes));
|
|
|
|
const agentInfoRes = await page.evaluate(async () => {
|
|
const r = await fetch("/api/agents/default/info");
|
|
return { status: r.status, body: await r.json() };
|
|
});
|
|
console.log("=== /api/agents/default/info ===", JSON.stringify(agentInfoRes));
|
|
|
|
const newChatBtn = page.locator(".new-chat-btn").first();
|
|
if (await newChatBtn.isVisible()) {
|
|
await newChatBtn.click();
|
|
await page.waitForTimeout(1000);
|
|
}
|
|
|
|
console.log("=== Before send ===");
|
|
console.log("Console messages:", consoleMessages.slice(-10));
|
|
console.log("Page errors:", pageErrors);
|
|
console.log("Network requests:", networkRequests);
|
|
|
|
const testMessage = "你好,这是一条测试消息";
|
|
await page.fill(".agent-textarea", testMessage);
|
|
|
|
const btnSend = page.locator(".btn-send");
|
|
const isDisabled = await btnSend.isDisabled();
|
|
console.log(`Send button disabled: ${isDisabled}`);
|
|
|
|
await page.click(".btn-send");
|
|
|
|
await page.waitForTimeout(3000);
|
|
|
|
console.log("=== After send (3s) ===");
|
|
console.log("Console messages:", consoleMessages.slice(-20));
|
|
console.log("Page errors:", pageErrors);
|
|
console.log("Network requests (last 10):", networkRequests.slice(-10));
|
|
|
|
const userMessages = await page.locator(".agent-message.is-user .user-bubble").count();
|
|
const assistantMessages = await page.locator(".agent-message.is-assistant").count();
|
|
const allMessages = await page.locator(".agent-message").count();
|
|
console.log(`User messages: ${userMessages}, Assistant messages: ${assistantMessages}, All: ${allMessages}`);
|
|
|
|
const textareaValue = await page.locator(".agent-textarea").inputValue();
|
|
console.log(`Textarea value after send: "${textareaValue}"`);
|
|
|
|
const toastText = await page.locator(".toast, [class*='toast'], [class*='Toast']").count();
|
|
console.log(`Toast elements: ${toastText}`);
|
|
|
|
const bodyText = await page.locator("body").innerText();
|
|
console.log(`Body text (last 500 chars): ${bodyText.slice(-500)}`);
|
|
});
|
|
|