-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(test): create playwground e2e test (#2276)
* chore(test): create playwground e2e test
- Loading branch information
Showing
4 changed files
with
228 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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
58 changes: 58 additions & 0 deletions
58
tests/playwright/src/model/ai-lab-playground-details-page.ts
This file contains 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,58 @@ | ||
/********************************************************************** | ||
* Copyright (C) 2024 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
***********************************************************************/ | ||
|
||
import { expect as playExpect } from '@playwright/test'; | ||
import type { Locator, Page } from '@playwright/test'; | ||
import { AILabBasePage } from './ai-lab-base-page'; | ||
import { AILabPlaygroundsPage } from './ai-lab-playgrounds-page'; | ||
import { handleConfirmationDialog } from '@podman-desktop/tests-playwright'; | ||
|
||
export class AILabPlaygroundDetailsPage extends AILabBasePage { | ||
readonly name: string; | ||
readonly deletePlaygroundButton: Locator; | ||
readonly conversationSectionLocator: Locator; | ||
readonly settingsPanelLocator: Locator; | ||
readonly parametersSectionLocator: Locator; | ||
readonly temperatureSliderLocator: Locator; | ||
readonly maxTokensSliderLocator: Locator; | ||
readonly topPSliderLocator: Locator; | ||
|
||
constructor(page: Page, webview: Page, playgroundName: string) { | ||
super(page, webview, playgroundName); | ||
|
||
this.name = playgroundName; | ||
this.deletePlaygroundButton = this.webview.getByRole('button', { name: 'Delete conversation' }); | ||
this.conversationSectionLocator = this.webview.getByLabel('conversation', { exact: true }); | ||
this.settingsPanelLocator = this.webview.getByLabel('settings panel', { exact: true }); | ||
this.parametersSectionLocator = this.settingsPanelLocator.getByLabel('parameters', { exact: true }); | ||
this.temperatureSliderLocator = this.parametersSectionLocator.getByLabel('temperature slider', { exact: true }); | ||
this.maxTokensSliderLocator = this.parametersSectionLocator.getByLabel('max tokens slider', { exact: true }); | ||
this.topPSliderLocator = this.parametersSectionLocator.getByLabel('top-p slider', { exact: true }); | ||
} | ||
|
||
async waitForLoad(): Promise<void> { | ||
await playExpect(this.heading).toBeVisible(); | ||
} | ||
|
||
async deletePlayground(): Promise<AILabPlaygroundsPage> { | ||
await playExpect(this.deletePlaygroundButton).toBeEnabled(); | ||
await this.deletePlaygroundButton.click(); | ||
await handleConfirmationDialog(this.page, 'Podman AI Lab', true, 'Confirm'); | ||
return new AILabPlaygroundsPage(this.page, this.webview); | ||
} | ||
} |
This file contains 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,91 @@ | ||
/********************************************************************** | ||
* Copyright (C) 2024 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
***********************************************************************/ | ||
|
||
import type { Locator, Page } from '@playwright/test'; | ||
import { expect as playExpect } from '@playwright/test'; | ||
import { AILabBasePage } from './ai-lab-base-page'; | ||
import { handleConfirmationDialog } from '@podman-desktop/tests-playwright'; | ||
import { AILabPlaygroundDetailsPage } from './ai-lab-playground-details-page'; | ||
|
||
export class AILabPlaygroundsPage extends AILabBasePage { | ||
readonly additionalActions: Locator; | ||
readonly newPlaygroundButton: Locator; | ||
readonly playgroundNameInput: Locator; | ||
readonly createPlaygroundButton: Locator; | ||
|
||
constructor(page: Page, webview: Page) { | ||
super(page, webview, 'Playground Environments'); | ||
this.additionalActions = this.webview.getByRole('group', { name: 'additionalActions' }); | ||
this.newPlaygroundButton = this.additionalActions.getByRole('button', { name: 'New Playground', exact: true }); | ||
this.playgroundNameInput = this.webview.getByRole('textbox', { name: 'playgroundName' }); | ||
this.createPlaygroundButton = this.webview.getByRole('button', { name: 'Create playground', exact: true }); | ||
} | ||
|
||
async waitForLoad(): Promise<void> { | ||
await playExpect(this.heading).toBeVisible(); | ||
} | ||
|
||
async createNewPlayground(name: string, timeout = 180_000): Promise<this> { | ||
await playExpect(this.newPlaygroundButton).toBeEnabled(); | ||
await this.newPlaygroundButton.click(); | ||
await playExpect(this.playgroundNameInput).toBeVisible(); | ||
await this.playgroundNameInput.fill(name); | ||
await playExpect(this.playgroundNameInput).toHaveValue(name); | ||
await playExpect(this.createPlaygroundButton).toBeEnabled(); | ||
await this.createPlaygroundButton.click(); | ||
await playExpect(this.createPlaygroundButton).not.toBeVisible({ timeout }); | ||
return this; | ||
} | ||
|
||
async deletePlayground(playgroundName: string): Promise<this> { | ||
const playgroundRow = await this.getPlaygroundRowByName(playgroundName); | ||
if (!playgroundRow) { | ||
throw new Error(`Playground ${playgroundName} not found`); | ||
} | ||
const deleteButton = playgroundRow.getByRole('button', { name: 'Delete conversation', exact: true }); | ||
await playExpect(deleteButton).toBeEnabled(); | ||
await deleteButton.click(); | ||
await handleConfirmationDialog(this.page, 'Podman AI Lab', true, 'Confirm'); | ||
return this; | ||
} | ||
|
||
async doesPlaygroundExist(playgroundName: string): Promise<boolean> { | ||
return (await this.getPlaygroundRowByName(playgroundName)) !== undefined; | ||
} | ||
|
||
async goToPlaygroundDetails(playgroundName: string): Promise<AILabPlaygroundDetailsPage> { | ||
const playgroundRow = await this.getPlaygroundRowByName(playgroundName); | ||
if (!playgroundRow) { | ||
throw new Error(`Playground ${playgroundName} not found`); | ||
} | ||
|
||
const button = playgroundRow.getByRole('button', { name: playgroundName, exact: true }); | ||
await playExpect(button).toBeVisible(); | ||
await button.click(); | ||
|
||
return new AILabPlaygroundDetailsPage(this.page, this.webview, playgroundName); | ||
} | ||
|
||
private async getPlaygroundRowByName(playgroundName: string): Promise<Locator | undefined> { | ||
const row = this.webview.getByRole('row', { name: playgroundName, exact: true }); | ||
if ((await row.count()) > 0) { | ||
return row; | ||
} | ||
return undefined; | ||
} | ||
} |