Rayrun
← Back to Discord Forum

How can I integrate fixtures that are in different files?

optional518posted in #help-playwright
Open in Discord

Let's say there are 3 fixtures, each of which implements a different function. How can you integrate these three fixtures into one fixture, and import the integrated fixture in the test case?

This thread is trying to answer question "How can you integrate three fixtures from different files into one fixture, and import the integrated fixture in the test case?"

3 replies

Fixtures are composable so you create a fixture that uses other three fixtures.

Version 1.39 has a feature which might be what you're looking for: merge fixtures: https://playwright.dev/docs/release-notes#merge-test-fixtures It allows you to have all the fixtures defined in multiple places (usually imported from multiple files) available in your test.

If you really want to combine multiple fixtures into one, then -as Mindaugas mentions- you can compose fixtures. One fixture can be implemented to be dependent on the others. And then the dependency fixtures will automatically run.

For example: page is dependent on context, context is dependent on browser, browser is dependent on browserName. But in your test you only mention page.

You can read more about fixtures here: https://playwright.dev/docs/test-fixtures

@refactoreric: thanks a lot.

thanks a lot.

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.