modify bot playwright test to stepper mode from parallel (#17811)

* skip bot playwright test

* change spec from parallel mode to stepper mode with the default admin account

---------

Co-authored-by: Shailesh Parmar <shailesh.parmar.webdev@gmail.com>
(cherry picked from commit 5c7ab993e8f8c96c79feb79636d49024223ac3c3)
This commit is contained in:
Ashish Gupta 2024-09-12 20:41:51 +05:30
parent adbe59d889
commit e6c4dcf297
2 changed files with 48 additions and 76 deletions

View File

@ -10,78 +10,49 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import { expect, Page, test as base } from '@playwright/test'; import { expect, test } from '@playwright/test';
import { BotClass } from '../../support/bot/BotClass';
import { UserClass } from '../../support/user/UserClass';
import { performAdminLogin } from '../../utils/admin';
import { import {
createBot, createBot,
deleteBot, deleteBot,
getCreatedBot,
redirectToBotPage, redirectToBotPage,
tokenExpirationForDays, tokenExpirationForDays,
tokenExpirationUnlimitedDays, tokenExpirationUnlimitedDays,
updateBotDetails, updateBotDetails,
} from '../../utils/bot'; } from '../../utils/bot';
const adminUser = new UserClass(); // use the admin user to login
const bot = new BotClass(); test.use({ storageState: 'playwright/.auth/admin.json' });
const bot2 = new BotClass();
const test = base.extend<{ adminPage: Page }>({
adminPage: async ({ browser }, use) => {
const adminPage = await browser.newPage();
await adminUser.login(adminPage);
await use(adminPage);
await adminPage.close();
},
});
test.describe('Bots Page should work properly', () => { test.describe('Bots Page should work properly', () => {
test.beforeAll('Setup pre-requests', async ({ browser }) => { test.slow(true);
const { apiContext, afterAction } = await performAdminLogin(browser);
await adminUser.create(apiContext);
await adminUser.setAdminRole(apiContext);
await bot.create(apiContext);
await bot2.create(apiContext);
await afterAction();
});
test.afterAll('Cleanup', async ({ browser }) => { test('Bots Page should work properly', async ({ page }) => {
const { apiContext, afterAction } = await performAdminLogin(browser); await redirectToBotPage(page);
await adminUser.delete(apiContext);
await bot.delete(apiContext);
await bot2.delete(apiContext);
await afterAction();
});
test('Verify ingestion bot delete button is always disabled', async ({ await test.step(
adminPage, 'Verify ingestion bot delete button is always disabled',
}) => { async () => {
await redirectToBotPage(adminPage); await expect(
page.getByTestId('bot-delete-ingestion-bot')
).toBeDisabled();
}
);
await expect( await test.step('Create Bot', async () => {
adminPage.getByTestId('bot-delete-ingestion-bot') await createBot(page);
).toBeDisabled(); });
});
test('Create and Delete Bot', async ({ adminPage }) => { await test.step('Update display name and description', async () => {
await redirectToBotPage(adminPage); await updateBotDetails(page);
await createBot(adminPage); });
await deleteBot(adminPage);
});
test('Update display name and description', async ({ adminPage }) => { await test.step('Update token expiration', async () => {
await redirectToBotPage(adminPage); await tokenExpirationForDays(page);
await updateBotDetails(adminPage, bot.responseData); await tokenExpirationUnlimitedDays(page);
}); });
test('Update token expiration', async ({ adminPage }) => { await test.step('Delete Bot', async () => {
test.slow(true); await deleteBot(page);
});
await redirectToBotPage(adminPage);
await getCreatedBot(adminPage, bot2.responseData.name);
await tokenExpirationForDays(adminPage);
await tokenExpirationUnlimitedDays(adminPage);
}); });
}); });

View File

@ -16,7 +16,6 @@ import {
getEpochMillisForFutureDays, getEpochMillisForFutureDays,
} from '../../src/utils/date-time/DateTimeUtils'; } from '../../src/utils/date-time/DateTimeUtils';
import { GlobalSettingOptions } from '../constant/settings'; import { GlobalSettingOptions } from '../constant/settings';
import { BotResponseDataType } from '../support/bot/BotClass';
import { import {
descriptionBox, descriptionBox,
redirectToHomePage, redirectToHomePage,
@ -26,7 +25,7 @@ import {
import { settingClick } from './sidebar'; import { settingClick } from './sidebar';
import { revokeToken } from './user'; import { revokeToken } from './user';
const botName = `bot-ct-test-${uuid()}`; const botName = `pw%bot-test-${uuid()}`;
const BOT_DETAILS = { const BOT_DETAILS = {
botName: botName, botName: botName,
@ -40,12 +39,21 @@ const BOT_DETAILS = {
const EXPIRATION_TIME = [1, 7, 30, 60, 90]; const EXPIRATION_TIME = [1, 7, 30, 60, 90];
export const getCreatedBot = async (page: Page, botName: string) => { export const getCreatedBot = async (
page: Page,
{
botName,
botDisplayName,
}: {
botName: string;
botDisplayName?: string;
}
) => {
// Click on created Bot name // Click on created Bot name
const fetchResponse = page.waitForResponse( const fetchResponse = page.waitForResponse(
`/api/v1/bots/name/${encodeURIComponent(botName)}?*` `/api/v1/bots/name/${encodeURIComponent(botName)}?*`
); );
await page.getByTestId(`bot-link-${botName}`).click(); await page.getByTestId(`bot-link-${botDisplayName ?? botName}`).click();
await fetchResponse; await fetchResponse;
}; };
@ -75,7 +83,7 @@ export const createBot = async (page: Page) => {
await expect(table).toContainText(BOT_DETAILS.description); await expect(table).toContainText(BOT_DETAILS.description);
// Get created bot // Get created bot
await getCreatedBot(page, botName); // Replace with actual function to get created bot await getCreatedBot(page, { botName });
await expect(page.getByTestId('revoke-button')).toContainText('Revoke token'); await expect(page.getByTestId('revoke-button')).toContainText('Revoke token');
@ -109,18 +117,11 @@ export const deleteBot = async (page: Page) => {
await expect(page.getByTestId('page-layout-v1')).not.toContainText(botName); await expect(page.getByTestId('page-layout-v1')).not.toContainText(botName);
}; };
export const updateBotDetails = async ( export const updateBotDetails = async (page: Page) => {
page: Page,
botData: BotResponseDataType
) => {
await getCreatedBot(page, botData.name);
await page.click('[data-testid="edit-displayName"]'); await page.click('[data-testid="edit-displayName"]');
await page.getByTestId('displayName').fill(BOT_DETAILS.updatedBotName); await page.getByTestId('displayName').fill(BOT_DETAILS.updatedBotName);
const updateDisplayNameResponse = page.waitForResponse( const updateDisplayNameResponse = page.waitForResponse(`api/v1/bots/*`);
`api/v1/bots/${botData.id ?? ''}`
);
await page.getByTestId('save-displayName').click(); await page.getByTestId('save-displayName').click();
await updateDisplayNameResponse; await updateDisplayNameResponse;
@ -133,9 +134,7 @@ export const updateBotDetails = async (
await page.getByTestId('edit-description').click(); await page.getByTestId('edit-description').click();
await page.locator(descriptionBox).fill(BOT_DETAILS.updatedDescription); await page.locator(descriptionBox).fill(BOT_DETAILS.updatedDescription);
const updateDescriptionResponse = page.waitForResponse( const updateDescriptionResponse = page.waitForResponse(`api/v1/bots/*`);
`api/v1/bots/${botData.id ?? ''}`
);
await page.getByTestId('save').click(); await page.getByTestId('save').click();
await updateDescriptionResponse; await updateDescriptionResponse;
@ -150,13 +149,15 @@ export const updateBotDetails = async (
).toContainText(BOT_DETAILS.updatedBotName); ).toContainText(BOT_DETAILS.updatedBotName);
await expect( await expect(
page.locator( page.locator(`[data-row-key="${botName}"] [data-testid="markdown-parser"]`)
`[data-row-key="${botData.name}"] [data-testid="markdown-parser"]`
)
).toContainText(BOT_DETAILS.updatedDescription); ).toContainText(BOT_DETAILS.updatedDescription);
}; };
export const tokenExpirationForDays = async (page: Page) => { export const tokenExpirationForDays = async (page: Page) => {
await getCreatedBot(page, {
botName,
botDisplayName: BOT_DETAILS.updatedBotName,
});
for (const expiryTime of EXPIRATION_TIME) { for (const expiryTime of EXPIRATION_TIME) {
await revokeToken(page, true); await revokeToken(page, true);