2025-12-15 14:43:39 +00:00
|
|
|
import type { Page } from "@playwright/test";
|
2025-09-21 11:02:31 -07:00
|
|
|
|
2025-12-15 14:43:39 +00:00
|
|
|
const MODEL_BUTTON_REGEX = /Gemini|Claude|GPT|Grok/i;
|
2025-03-09 21:02:19 -07:00
|
|
|
|
|
|
|
|
export class ChatPage {
|
2025-12-15 14:43:39 +00:00
|
|
|
page: Page;
|
2025-09-21 11:02:31 -07:00
|
|
|
|
|
|
|
|
constructor(page: Page) {
|
|
|
|
|
this.page = page;
|
|
|
|
|
}
|
2025-03-09 21:02:19 -07:00
|
|
|
|
2025-12-14 21:26:49 +00:00
|
|
|
async goto() {
|
|
|
|
|
await this.page.goto("/");
|
2025-05-01 02:28:24 -07:00
|
|
|
}
|
|
|
|
|
|
2025-03-09 21:02:19 -07:00
|
|
|
async createNewChat() {
|
2025-12-15 14:43:39 +00:00
|
|
|
await this.page.goto("/");
|
|
|
|
|
await this.page.waitForSelector("[data-testid='multimodal-input']");
|
2025-03-11 14:39:36 -07:00
|
|
|
}
|
|
|
|
|
|
2025-12-15 14:43:39 +00:00
|
|
|
getInput() {
|
|
|
|
|
return this.page.getByTestId("multimodal-input");
|
2025-03-09 21:02:19 -07:00
|
|
|
}
|
|
|
|
|
|
2025-12-15 14:43:39 +00:00
|
|
|
async typeMessage(message: string) {
|
|
|
|
|
const input = this.getInput();
|
|
|
|
|
await input.fill(message);
|
2025-03-09 21:02:19 -07:00
|
|
|
}
|
|
|
|
|
|
2025-12-15 14:43:39 +00:00
|
|
|
async sendMessage() {
|
|
|
|
|
await this.page.getByTestId("send-button").click();
|
2025-03-09 21:02:19 -07:00
|
|
|
}
|
|
|
|
|
|
2025-12-15 14:43:39 +00:00
|
|
|
async sendUserMessage(message: string) {
|
|
|
|
|
await this.typeMessage(message);
|
|
|
|
|
await this.sendMessage();
|
2025-03-09 21:02:19 -07:00
|
|
|
}
|
|
|
|
|
|
2025-12-15 14:43:39 +00:00
|
|
|
getSendButton() {
|
|
|
|
|
return this.page.getByTestId("send-button");
|
2025-05-01 17:47:48 -07:00
|
|
|
}
|
|
|
|
|
|
2025-12-15 14:43:39 +00:00
|
|
|
getStopButton() {
|
|
|
|
|
return this.page.getByTestId("stop-button");
|
2025-03-09 21:02:19 -07:00
|
|
|
}
|
|
|
|
|
|
2025-12-15 14:43:39 +00:00
|
|
|
async clickSuggestedAction(index = 0) {
|
|
|
|
|
const suggestions = this.page.locator(
|
|
|
|
|
"[data-testid='suggested-actions'] button"
|
|
|
|
|
);
|
|
|
|
|
await suggestions.nth(index).click();
|
2025-12-14 21:26:49 +00:00
|
|
|
}
|
2025-03-09 21:02:19 -07:00
|
|
|
|
2025-12-15 14:43:39 +00: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
|
|
|
|
2025-12-15 14:43:39 +00:00
|
|
|
async selectModel(modelName: string) {
|
|
|
|
|
await this.openModelSelector();
|
|
|
|
|
await this.page.getByText(modelName).first().click();
|
2025-04-25 23:40:15 -07:00
|
|
|
}
|
|
|
|
|
|
2025-12-15 14:43:39 +00:00
|
|
|
async searchModels(query: string) {
|
|
|
|
|
await this.openModelSelector();
|
|
|
|
|
await this.page.getByPlaceholder("Search models...").fill(query);
|
2025-05-01 02:28:24 -07:00
|
|
|
}
|
2025-03-09 21:02:19 -07:00
|
|
|
}
|