microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
66.05k stars 3.6k forks source link

[Feature] Mixing separated fixtures #8346

Closed Delexir closed 1 year ago

Delexir commented 3 years ago

It seems is very necessary of possibility to combine fixtures from any files for each specific test case in unique combination. Is it possible in future? image

Thank you!

radekBednarik commented 3 years ago

Hello, @Delexir see https://github.com/radekBednarik/p-issue-repro whether this would help you, folder test

JoelEinbinder commented 3 years ago

@dgozman did we have a test.merge fixtures method at some point or am I imagining it?

pavelfeldman commented 3 years ago

I don't think we have it, but you can use JavaScript to achieve it via passing reusable fixture definitions into either extend chain or merge them into an object in a single extend call.

It is important to know that the set of instantiated fixtures for test is defined by the test, not by the fixtures. So you can put all fixtures into one bucket and your test will only use the ones it needs, there is no overhead on other ones, they are not created for each test.

bgotink commented 3 years ago

I've just run into the same scenario, where I want to merge multiple fixture sets that come from completely separate packages. I ended up introducing mixin functions in the packages that I control, to allow for combining these sets:

import {
  PlaywrightTestArgs,
  PlaywrightTestOptions,
  PlaywrightWorkerArgs,
  PlaywrightWorkerOptions,
  TestType,
  test as base,
} from '@playwright/test';

import {
  NgxPlaywrightTestArgs,
  NgxPlaywrightTestOptions,
  ngxPlaywrightFixtures,
} from './implementation';

export function mixinFixtures<
  T extends PlaywrightTestArgs & PlaywrightTestOptions,
  W extends PlaywrightWorkerArgs & PlaywrightWorkerOptions,
>(
  test: TestType<T, W>,
): TestType<NgxPlaywrightTestArgs & NgxPlaywrightTestOptions & T, W> {
  return test.extend(ngxPlaywrightFixtures);
}

export const test = mixinFixtures(base);

example usage:

import {test as base} from '@playwright/test';
import {mixinFixtures as mixinNgxPlaywright} from '@ngx-playwright/test';
import {mixinFixtures as mixinCoverage} from '@hypothetical-packages-that-dont-exist/playwright-coverage';

export const test = mixinCoverage(mixinNgxPlaywright(base));
Delexir commented 3 years ago

@bgotink Thank you!! I'll try to do the same with mixins

bsteffensTempus commented 2 years ago

Any update on this? This seems like a logical next step for fixtures.

pavelfeldman commented 1 year ago

Why was this issue closed?

We are prioritizing the features based on the upvotes, recency and activity in the issue thread. It looks like this issue only has a handful of upvotes, has not been touched recently and/or we lack sufficient feedback to act on it. We are closing issues like this one to keep our bug database maintainable. Please feel free to open a new issue and link this one to it if you think this is a mistake.

amitz commented 10 months ago

The "Merge Fixtures" feature that was introduced on 1.39 won't work with fixture definitions. Is it possible to somehow support it? This will alleviate the pain of mixing all the Fixture/Worker Fixture manually as stated about.

EDIT: @pavelfeldman Would you rather me to open a new feature request on allowing mergeFixtures to accept fixtures objects? or can we keep it here?