Does Playwright offer custom args in the command line?

Viewed 1483

I want to create custom args in the commandline so that my same specs, when the process.argv matches the custom args, does slightly different things. But I couldn't see that option in the docs. Did I miss it or is this not allowed in Playwright?

2 Answers

It seems not possible at this moment. I tried to add my option after --, which terminates original options list, but then those are considered to be arguments to filter files.

Now, I use environmental variables instead. You can define them in .env file and use dotenv package to load it. Then, they will be available through process.env.

import * as dotenv from "dotenv"

export default async function globalSetup() {
    const output = dotenv.config()
    console.log(output.parsed)
    console.log(process.env.MY_ENV_VAR)
    ...
}

It's not clear exactly what you mean, but playwright does support custom launch arguments for chrome along with a multitude of other launch options.

Related