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

View File

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