Playwright Parameterized Fixtures
Dec 19, 2024
Playwright allows you to parameterize your fixtures, making your tests more flexible and reusable.
type TestFixture = {
scenarioConfig: {
sysPort?: number;
enableLoadBalancing?: boolean;
};
sysSetup: eDockerSetup;
};
export const test = base.extend<TestFixture, WorkerLevelFixture>({
scenarioConfig: [
{
syslogPort: 9514,
enableLoadBalancing: false,
},
{ option: true },
],
...
sysSetup: [
async ({ builder,scenarioConfig }, use) => {
await use({
config: builder
.addService(
syslogSource({
port: `${scenarioConfig.syslogPort}`,
destHost: `${Ips.worker[0]}`,
maxThruput: '1024M',
numEvents: `${scenarioConfig.eventsLoad}`,
replicas: scenarioConfig.replicas,
}),
)
.buildConfig(),
});
},
{ scope: 'test' },
],
In playwright test/scenario in test.parallel,
pass the dynamic test configureation to test.use before test.describe
const testConfigurations = [
{
testName: 'scenario1',
replicas: 1,
},
{
testName: 'scenario2',
replicas: 1,
},
];
test.describe.parallel('sys', () => {
for (const testConfig of testConfigurations) {
test.describe(testConfig.testTag, () => {
test.use({ scenarioConfig: testConfig });
test(`${testConfig.testName}`, async ({
sysSetup,
deployment,
}) => {
await deployment.setupDocker(sysSetup);
});
});
}
});