-
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): initial draft for catalog model download e2e (#2133)
* chore(test): initial draft for catalog model download e2e Signed-off-by: Vladimir Lazar <[email protected]>
- Loading branch information
Showing
5 changed files
with
205 additions
and
33 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
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,102 @@ | ||
/********************************************************************** | ||
* 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'; | ||
|
||
export class AILabCatalogPage extends AILabBasePage { | ||
readonly catalogTable: Locator; | ||
readonly modelsGroup: Locator; | ||
|
||
constructor(page: Page, webview: Page) { | ||
super(page, webview, 'Models'); | ||
this.catalogTable = this.webview.getByRole('table', { name: 'model' }); | ||
this.modelsGroup = this.catalogTable.getByRole('rowgroup').nth(1); | ||
} | ||
|
||
async waitForLoad(): Promise<void> { | ||
await playExpect(this.heading).toBeVisible(); | ||
await playExpect(this.catalogTable).toBeVisible(); | ||
await playExpect(this.modelsGroup).toBeVisible(); | ||
} | ||
|
||
async getModelRowByName(modelName: string): Promise<Locator | undefined> { | ||
const modelRows = await this.getAllModelRows(); | ||
for (const modelRow of modelRows) { | ||
const modelNameCell = modelRow.getByText(modelName, { exact: true }); | ||
if ((await modelNameCell.count()) > 0) { | ||
return modelRow; | ||
} | ||
} | ||
|
||
return undefined; | ||
} | ||
|
||
async downloadModel(modelName: string): Promise<void> { | ||
const modelRow = await this.getModelRowByName(modelName); | ||
if (!modelRow) { | ||
throw new Error(`Model ${modelName} not found`); | ||
} | ||
const downloadButton = modelRow.getByRole('button', { name: 'Download Model' }); | ||
await playExpect(downloadButton).toBeEnabled(); | ||
await downloadButton.focus(); | ||
await downloadButton.click(); | ||
} | ||
|
||
async createModelService(modelName: string): Promise<void> { | ||
const modelRow = await this.getModelRowByName(modelName); | ||
if (!modelRow) { | ||
throw new Error(`Model ${modelName} not found`); | ||
} | ||
const createServiceButton = modelRow.getByRole('button', { name: 'Create Model Service' }); | ||
await playExpect(createServiceButton).toBeEnabled(); | ||
await createServiceButton.focus(); | ||
await createServiceButton.click(); | ||
|
||
throw new Error('Not implemented'); | ||
} | ||
|
||
async deleteModel(modelName: string): Promise<void> { | ||
const modelRow = await this.getModelRowByName(modelName); | ||
if (!modelRow) { | ||
throw new Error(`Model ${modelName} not found`); | ||
} | ||
const deleteButton = modelRow.getByRole('button', { name: 'Delete Model' }); | ||
await playExpect(deleteButton).toBeEnabled(); | ||
await deleteButton.focus(); | ||
await deleteButton.click(); | ||
await this.page.waitForTimeout(1_000); | ||
await handleConfirmationDialog(this.page, 'Podman AI Lab', true, 'Confirm'); | ||
} | ||
|
||
async isModelDownloaded(modelName: string): Promise<boolean> { | ||
const modelRow = await this.getModelRowByName(modelName); | ||
if (!modelRow) { | ||
return false; | ||
} | ||
|
||
const deleteButton = modelRow.getByRole('button', { name: 'Delete Model' }); | ||
return (await deleteButton.count()) > 0; | ||
} | ||
|
||
private async getAllModelRows(): Promise<Locator[]> { | ||
return this.modelsGroup.getByRole('row').all(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/********************************************************************** | ||
* 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 { Page } from '@playwright/test'; | ||
import type { NavigationBar, Runner } from '@podman-desktop/tests-playwright'; | ||
import { expect as playExpect } from '@podman-desktop/tests-playwright'; | ||
|
||
export async function handleWebview(runner: Runner, page: Page, navigationBar: NavigationBar): Promise<[Page, Page]> { | ||
const AI_LAB_NAVBAR_EXTENSION_LABEL: string = 'AI Lab'; | ||
const AI_LAB_PAGE_BODY_LABEL: string = 'Webview AI Lab'; | ||
|
||
const aiLabPodmanExtensionButton = navigationBar.navigationLocator.getByRole('link', { | ||
name: AI_LAB_NAVBAR_EXTENSION_LABEL, | ||
}); | ||
await playExpect(aiLabPodmanExtensionButton).toBeEnabled(); | ||
await aiLabPodmanExtensionButton.click(); | ||
await page.waitForTimeout(2_000); | ||
|
||
const webView = page.getByRole('document', { name: AI_LAB_PAGE_BODY_LABEL }); | ||
await playExpect(webView).toBeVisible(); | ||
await new Promise(resolve => setTimeout(resolve, 1_000)); | ||
const [mainPage, webViewPage] = runner.getElectronApp().windows(); | ||
await mainPage.evaluate(() => { | ||
const element = document.querySelector('webview'); | ||
if (element) { | ||
(element as HTMLElement).focus(); | ||
} else { | ||
console.log(`element is null`); | ||
} | ||
}); | ||
|
||
return [mainPage, webViewPage]; | ||
} |