-
Notifications
You must be signed in to change notification settings - Fork 91
refactor(e2e): reorganize test structure for chat and code pages #667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
joyway1978
wants to merge
4
commits into
wecode-ai:main
Choose a base branch
from
joyway1978:refactor/e2e-test-structure
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ca3e8cc
refactor(e2e): reorganize test structure for chat and code pages
fba2f65
fix(e2e): improve selectTeam stability in CI environment
b678255
fix(e2e): fix weak assertions and error handling issues (batch 1)
a1e4aa4
fix(e2e): fix weak assertions and error handling issues (batch 2)
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,220 @@ | ||
| import { Page, Locator } from '@playwright/test' | ||
| import { BasePage } from '../base.page' | ||
|
|
||
| /** | ||
| * Base Task Page - Shared functionality between Chat and Code pages | ||
| * Both /chat and /code routes share common UI elements like: | ||
| * - Team selector | ||
| * - Message input | ||
| - Send button | ||
| * - Task sidebar | ||
| * - Message list | ||
| */ | ||
| export abstract class BaseTaskPage extends BasePage { | ||
| // Common locators shared between Chat and Code pages | ||
| protected readonly messageInput: Locator | ||
| protected readonly sendButton: Locator | ||
| protected readonly teamSelector: Locator | ||
| protected readonly taskSidebar: Locator | ||
| protected readonly messageList: Locator | ||
| protected readonly newTaskButton: Locator | ||
|
|
||
| constructor(page: Page) { | ||
| super(page) | ||
| this.messageInput = page | ||
| .locator( | ||
| '[data-testid="message-input"], textarea[placeholder*="message" i], textarea[placeholder*="type" i], textarea' | ||
| ) | ||
| .first() | ||
| this.sendButton = page | ||
| .locator( | ||
| '[data-testid="send-button"], button[type="submit"]:has-text("Send"), button[type="submit"]:has-text("发送")' | ||
| ) | ||
| .first() | ||
| this.teamSelector = page | ||
| .locator( | ||
| '[data-testid="team-selector"], [data-tour="team-selector"] [role="combobox"], [role="combobox"]' | ||
| ) | ||
| .first() | ||
| this.taskSidebar = page | ||
| .locator('[data-testid="task-sidebar"], [data-testid="conversation-list"], aside') | ||
| .first() | ||
| this.messageList = page | ||
| .locator('[data-testid="message-list"], [data-testid="messages"], .message-list') | ||
| .first() | ||
| this.newTaskButton = page | ||
| .locator( | ||
| 'button:has-text("New"), button:has-text("新建"), [data-testid="new-task"], [data-testid="new-chat"]' | ||
| ) | ||
| .first() | ||
| } | ||
|
|
||
| /** | ||
| * Check if message input is visible and enabled | ||
| */ | ||
| async isMessageInputReady(): Promise<boolean> { | ||
| try { | ||
| await this.messageInput.waitFor({ state: 'visible', timeout: 5000 }) | ||
| return await this.messageInput.isEnabled() | ||
| } catch { | ||
| return false | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Type a message in the input field | ||
| */ | ||
| async typeMessage(message: string): Promise<void> { | ||
| await this.messageInput.fill(message) | ||
| } | ||
|
|
||
| /** | ||
| * Send the current message | ||
| */ | ||
| async sendMessage(message?: string): Promise<void> { | ||
| if (message) { | ||
| await this.typeMessage(message) | ||
| } | ||
| await this.sendButton.click() | ||
| } | ||
|
|
||
| /** | ||
| * Check if team selector is available | ||
| */ | ||
| async hasTeamSelector(): Promise<boolean> { | ||
| const count = await this.teamSelector.count() | ||
| if (count === 0) return false | ||
| return await this.teamSelector.isVisible().catch(() => false) | ||
| } | ||
|
|
||
| /** | ||
| * Select a team by name | ||
| */ | ||
| async selectTeam(teamName: string): Promise<void> { | ||
| await this.teamSelector.click({ force: true }) | ||
| await this.page.waitForTimeout(300) | ||
| const option = this.page.locator(`[role="option"]:has-text("${teamName}")`) | ||
| await option.click() | ||
| await this.page.waitForTimeout(500) | ||
| } | ||
|
|
||
| /** | ||
| * Get the currently selected team name | ||
| */ | ||
| async getSelectedTeam(): Promise<string | null> { | ||
| try { | ||
| return await this.teamSelector.textContent() | ||
| } catch { | ||
| return null | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Click new task button to create a new task | ||
| */ | ||
| async createNewTask(): Promise<void> { | ||
| await this.newTaskButton.click() | ||
| await this.waitForLoading() | ||
| } | ||
|
|
||
| /** | ||
| * Check if new task button is visible | ||
| */ | ||
| async hasNewTaskButton(): Promise<boolean> { | ||
| return await this.newTaskButton.isVisible().catch(() => false) | ||
| } | ||
|
|
||
| /** | ||
| * Wait for a response message to appear | ||
| */ | ||
| async waitForResponse(timeout: number = 30000): Promise<void> { | ||
| await this.page.waitForSelector('[data-testid="message"], [data-role="assistant"], .message', { | ||
| timeout, | ||
| }) | ||
| } | ||
|
|
||
| /** | ||
| * Get all message contents | ||
| */ | ||
| async getMessages(): Promise<string[]> { | ||
| const messages = this.page.locator( | ||
| '[data-testid="message-content"], .message-content, [data-testid="message"]' | ||
| ) | ||
| return await messages.allTextContents() | ||
| } | ||
|
|
||
| /** | ||
| * Get the count of messages | ||
| */ | ||
| async getMessageCount(): Promise<number> { | ||
| return await this.page.locator('[data-testid="message"], .message').count() | ||
| } | ||
|
|
||
| /** | ||
| * Check if task sidebar is visible | ||
| */ | ||
| async isSidebarVisible(): Promise<boolean> { | ||
| return await this.taskSidebar.isVisible().catch(() => false) | ||
| } | ||
|
|
||
| /** | ||
| * Click on a task in the sidebar by index | ||
| */ | ||
| async selectTaskByIndex(index: number = 0): Promise<void> { | ||
| const taskItems = this.page.locator('[data-testid="task-item"], .task-item') | ||
| await taskItems.nth(index).click() | ||
| await this.waitForLoading() | ||
| } | ||
|
|
||
| /** | ||
| * Get the number of tasks in the sidebar | ||
| */ | ||
| async getTaskCount(): Promise<number> { | ||
| return await this.page.locator('[data-testid="task-item"], .task-item').count() | ||
| } | ||
|
|
||
| /** | ||
| * Cancel current running task | ||
| */ | ||
| async cancelTask(): Promise<void> { | ||
| const cancelButton = this.page.locator( | ||
| 'button:has-text("Cancel"), button:has-text("Stop"), button:has-text("取消"), [data-testid="cancel-task"]' | ||
| ) | ||
| if (await cancelButton.isVisible({ timeout: 2000 }).catch(() => false)) { | ||
| await cancelButton.click() | ||
| await this.waitForLoading() | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Check if there's a visible cancel button | ||
| */ | ||
| async hasCancelButton(): Promise<boolean> { | ||
| return await this.page | ||
| .locator('button:has-text("Cancel"), button:has-text("取消"), [data-testid="cancel-task"]') | ||
| .isVisible() | ||
| .catch(() => false) | ||
| } | ||
|
|
||
| /** | ||
| * Wait for streaming/loading to complete | ||
| */ | ||
| async waitForStreamingComplete(timeout: number = 60000): Promise<void> { | ||
| await this.page | ||
| .waitForSelector('[data-streaming="true"], .streaming', { state: 'detached', timeout }) | ||
| .catch(() => {}) | ||
| await this.page | ||
| .waitForSelector('[data-testid="send-button"]:not([disabled])', { timeout }) | ||
| .catch(() => {}) | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| /** | ||
| * Check if streaming is in progress | ||
| */ | ||
| async isStreaming(): Promise<boolean> { | ||
| const streamingIndicator = this.page.locator( | ||
| '[data-streaming="true"], .streaming, [class*="loading"]' | ||
| ) | ||
| return await streamingIndicator.isVisible().catch(() => false) | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.