I started in my first Kotlin project and one of the first small improvements I made to my workflow was to use environment variables to decide if I want Playwright e2e tests to run headless or not. I think this is all actually in Java-land but I’m documenting this under Kotlin as that’s what I’m more likely to run into it
To read environment variables in Kotlin, you use Java’s System.getenv
runHeadless = !(System.getenv('HEADLESS') == 'false')It defaults to running headless so to turn it off with an environment variable (HEADLESS=false ./runTests), I check if the value is string “false” and then revert that boolean so with anything else but “false”, it becomes true.