Rayrun
โ† Back to Discord Forum

Should page objects be injected into tests as fixtures or imported normally?

joedefilippoposted in #help-playwright
Open in Discord

Little confused about how/when to use fixtures aside from the basic fixtures like page, request, browser, etc.

Should I be thinking about it like dependency injection?

Which is the preferred pattern?

Is it even valid to be thinking about fixtures in this way?

test('test1', async ( { page, loginPage} ) => { loginPage.login(); }

vs.

import {LoginPage} from '../login.page'; test('test1', async ( { page} ) => { const loginPage = new LoginPage(page); loginPage.login(); }

This thread is trying to answer question "Should page objects be injected into tests as fixtures or imported normally?"

3 replies

Hey ๐Ÿ‘‹ ,

I import them via

import {LoginPage} from '../login.page';
test('test1', async ( { page} ) => {
const loginPage = new LoginPage(page);
loginPage.login();
}

but would like to hear everyones input just in case I'm going about it the wrong way.

Use fixtures

I have multiple page fixtures for different kind of authorization (regular persistent test user, admin user, temporary isolated test user, worker shared test user,...) so I need to replace 'page' with my different page fixtures every time when initializing my Pom depending on the test case. Having a fixture for every case did not seem beneficial for me so far.

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 [email protected].