Running against multiple projects/urls in single Playwright test run

Viewed 173

I am trying figure this out since few days. Found couple workarounds but nothing seems to work as expected.

My requirement is to run Playwright tests against multiple URLs. Single project - runs perfectly fine, I have few tests already in place. Now I want to introduce multiple projects with the best possible configuration.

For instance my './tests/ProjectA' runs against 'https://projectA.home.com './tests/ProjectB' runs against 'https://projectB.home.com with different credentials and so on.

I want both A & B to run against every release in single run.

I am looking at a config file like this with projects...

projects: [
        {
            name: 'Project A',
            testDir: './tests/ProjectA',
            use: {
                baseURL: process.env.projectA,
            },
        },
        {
            name: 'Project B',
            testDir: './tests/LTI/ProjectB',
            use: {
                baseURL: process.env.projectB
            },
        },
    ],

Issue: I want to check which testDir my current worker is pointing to at 'globalSetup' level so I can authenticate and bring up the URL accordingly.

How do I access Project info at globalSetup level? Or how do I best handle this issue? Appreciate any suggestions. Thanks!!

1 Answers

From what I understand you want to access the current testDir of a project, that is defined in playwright config.

Have you tried using the properties of "TestInfo object" yet? I believe it's made for situations like yours, where you need to access information about the project object.

Official docs: https://playwright.dev/docs/test-advanced

Here is an example I made - I'm console logging the testInfo.project.testDir, but obviously you will do some other logical things with it.

test("that testDir is what I'm expecting it to be!", async ({ page, context }, testInfo) => {
            //console.log(testInfo.project);
            // Access project testDir
            console.log(testInfo.project.testDir);
};
Related