feat(sandbox): create a dropdown selector for sandbox mode (#6519)

This commit is contained in:
Bijin A B
2025-12-30 23:03:06 +05:30
committed by GitHub
parent 0848393319
commit 8fa8ae5fed
12 changed files with 278 additions and 190 deletions

View File

@@ -201,3 +201,16 @@ export const buildGrpcCommonLocators = (page: Page) => ({
tabCount: () => page.getByTestId('tab-response-count')
}
});
/**
* Builds locators for sandbox mode settings
* @param page - The Playwright page object
* @returns Object with locators for sandbox elements
*/
export const buildSandboxLocators = (page: Page) => ({
sandboxModeSelector: () => page.getByTestId('sandbox-mode-selector'),
safeModeRadio: () => page.getByTestId('sandbox-mode-safe'),
developerModeRadio: () => page.getByTestId('sandbox-mode-developer'),
jsSandboxHeading: () => page.getByText('JavaScript Sandbox'),
saveButton: () => page.getByRole('button', { name: 'Save' })
});

View File

@@ -1,4 +1,5 @@
import { Page, expect, test } from '../../../playwright';
import { buildSandboxLocators } from './locators';
/**
* Builds locators for the runner results view
@@ -78,19 +79,6 @@ export const runCollection = async (page: Page, collectionName: string) => {
});
};
/**
* Builds locators for sandbox mode settings
* @param page - The Playwright page object
* @returns Object with locators for sandbox elements
*/
export const buildSandboxLocators = (page: Page) => ({
sandboxModeSelector: () => page.getByTestId('sandbox-mode-selector'),
safeModeRadio: () => page.getByLabel('Safe Mode'),
developerModeRadio: () => page.getByLabel('Developer Mode(use only if'),
jsSandboxHeading: () => page.getByText('JavaScript Sandbox'),
saveButton: () => page.getByRole('button', { name: 'Save' })
});
/**
* Sets up the JavaScript sandbox mode for a collection
* @param page - The Playwright page object
@@ -128,23 +116,12 @@ export const setSandboxMode = async (page: Page, collectionName: string, mode: '
await sandboxLocators.developerModeRadio().waitFor({ state: 'visible', timeout: 5000 });
await sandboxLocators.developerModeRadio().check();
} else {
// For safe mode, check if developer mode is currently selected
const developerModeChecked = await sandboxLocators.developerModeRadio().isChecked().catch(() => false);
if (developerModeChecked) {
// Click the Developer Mode label text inside the security settings form
const securityForm = page.locator('div').filter({ hasText: 'JavaScript Sandbox' }).locator('..').first();
const developerLabel = securityForm.locator('label').filter({ hasText: /^Developer Mode/ }).first();
await developerLabel.waitFor({ state: 'visible', timeout: 5000 });
await developerLabel.click();
}
// Ensure Safe Mode radio is visible and check it
await sandboxLocators.safeModeRadio().waitFor({ state: 'visible', timeout: 5000 });
await sandboxLocators.safeModeRadio().check();
}
await sandboxLocators.saveButton().click();
await page.keyboard.press('Escape');
});
};