Search code examples
node.jstypescriptplaywright

How to Parameterise a boolean value in process.env


I have a playwright script that requires to have boolean value for the headless option. I would like to pass this as a parameter in process.env. The pipeline build will accept headless version but when someone wants to run it locally, it would be best to run it in the headed version. Hence it would be convenient to parameterize it.

  import test, { Browser, chromium, expect, Page } from '@playwright/test'



  async function authSetup() {
    
    const browser: Browser = await chromium.launch({headless: process.env.headless})
    const context = await browser.newContext()
    const page: Page = await context.newPage()

This results in an error:

Error: browserType.launch: headless: expected boolean, got string

Solution

  • Just compare its value.

    { headless: process.env.headless === "true" }