chatbot-template/tests/pages/chat.ts

72 lines
1.6 KiB
TypeScript
Raw Normal View History

import type { Page } from "@playwright/test";
const MODEL_BUTTON_REGEX = /Kimi|Codestral|Mistral|DeepSeek|GPT|Grok/i;
2025-03-09 21:02:19 -07:00
export class ChatPage {
page: Page;
constructor(page: Page) {
this.page = page;
}
2025-03-09 21:02:19 -07:00
async goto() {
await this.page.goto("/");
}
2025-03-09 21:02:19 -07:00
async createNewChat() {
await this.page.goto("/");
await this.page.waitForSelector("[data-testid='multimodal-input']");
2025-03-11 14:39:36 -07:00
}
getInput() {
return this.page.getByTestId("multimodal-input");
2025-03-09 21:02:19 -07:00
}
async typeMessage(message: string) {
const input = this.getInput();
await input.fill(message);
2025-03-09 21:02:19 -07:00
}
async sendMessage() {
await this.page.getByTestId("send-button").click();
2025-03-09 21:02:19 -07:00
}
async sendUserMessage(message: string) {
await this.typeMessage(message);
await this.sendMessage();
2025-03-09 21:02:19 -07:00
}
getSendButton() {
return this.page.getByTestId("send-button");
}
getStopButton() {
return this.page.getByTestId("stop-button");
2025-03-09 21:02:19 -07:00
}
async clickSuggestedAction(index = 0) {
const suggestions = this.page.locator(
"[data-testid='suggested-actions'] button"
);
await suggestions.nth(index).click();
}
2025-03-09 21:02:19 -07:00
async openModelSelector() {
const modelButton = this.page
.locator("button")
.filter({ hasText: MODEL_BUTTON_REGEX })
.first();
await modelButton.click();
2025-03-09 21:02:19 -07:00
}
2025-04-25 23:40:15 -07:00
async selectModel(modelName: string) {
await this.openModelSelector();
await this.page.getByText(modelName).first().click();
2025-04-25 23:40:15 -07:00
}
async searchModels(query: string) {
await this.openModelSelector();
await this.page.getByPlaceholder("Search models...").fill(query);
}
2025-03-09 21:02:19 -07:00
}