fix(test): flaky Policies.spec and Roles.spec (#21917)

* fix getElementWithPagination function

* fix flakyness

* fix test

* remove error statements
This commit is contained in:
Pranita Fulsundar 2025-06-25 09:42:25 +05:30 committed by GitHub
parent 16aa38da8f
commit 7d74efa501
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 15 deletions

View File

@ -372,6 +372,10 @@ test.describe('Policy page should work properly', () => {
await page.reload();
await page.waitForSelector('[data-testid="loader"]', { state: 'detached' });
await page.waitForLoadState('networkidle');
await getElementWithPagination(page, policyLocator);
await page.getByTestId('manage-button').click();

View File

@ -301,6 +301,8 @@ test('Delete role action from manage button options', async ({ page }) => {
await settingClick(page, GlobalSettingOptions.ROLES);
await page.waitForLoadState('networkidle');
await getElementWithPagination(page, roleLocator);
await page.getByTestId('manage-button').click();

View File

@ -33,29 +33,23 @@ export const removePolicyFromRole = async (
export const getElementWithPagination = async (
page: Page,
locator: Locator,
click = true
click = true,
maxPages = 15
) => {
let hasNext = true;
while (hasNext) {
for (let currentPage = 0; currentPage < maxPages; currentPage++) {
// Check if element is visible on current page
if (await locator.isVisible()) {
click && (await locator.click());
if (click) {
await locator.click();
}
break;
return;
}
const nextBtn = page.locator('[data-testid="next"]');
await nextBtn.scrollIntoViewIfNeeded();
const nextBtn = page.locator('[data-testid="next"]');
await nextBtn.waitFor({ state: 'visible' });
hasNext = !(await nextBtn.getAttribute('disabled'));
if (!hasNext) {
throw new Error('Element not found and no more pages to paginate.');
}
await nextBtn.click();
await page.waitForSelector('[data-testid="loader"]', { state: 'detached' });
}
};