Rayrun
← Back to Discord Forum

How to get variable values from the use attribute in projects in the playwright.config.ts file

optional518posted in #help-playwright
Open in Discord

my playwright.config.ts

type TestOptions = { username: string; password: string; }

export default defineConfig<TestOptions>({ ...... projects: [ { name: 'setup', testMatch: /login.setup.ts/, }, { name: 'production', use: { ...devices['Desktop Chrome'], baseURL: 'xxx', username: 'xxx', password: 'xxx', storageState: '.auth/user.json', }, dependencies: ['setup'], }, });

my test.spec.ts

setup('xxx', async ({ page }) => { await page.goto('/distribute'); await page.locator('input[name="account"]').fill(process.env.username!); await page.locator('input[name="password"]').fill(process.env.password!); ...... })

When I use process.env.username, I cannot get the value of username.

This thread is trying to answer question "How can I get the value of a variable from the 'use' attribute in projects in the playwright.config.ts file?"

12 replies

Hope these links help you

.env files section

@jaratlanta: https:playwright.dev/docs/test-parameterize, but the example does not indicate how to get the variables in the custom project parameter

https:playwright.dev/docs/test-parameterize, but the example does not indicate how to get the variables in the custom project parameter

Read closely it does . If you want complex then try this

@jaratlanta: But I really didn't get any more valid information from the last link, can you tell me

But I really didn't get any more valid information from the last link, can you tell me

@optional518: see section Passing Environment Variables and .env files

see section Passing Environment Variables and .env files

@jaratlanta: ok, thanks. I'll look at the youtube video for a .env solution first. But I'd like to dig a little deeper to see if there's a way to get a variable in the custom project parameter

ok, thanks. I'll look at the youtube video for a .env solution first. But I'd like to dig a little deeper to see if there's a way to get a variable in the custom project parameter

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.