grafana / xk6-browser

The browser module adds support for browser automation and end-to-end web testing via the Chrome Devtools Protocol to k6.
https://grafana.com/docs/k6/latest/javascript-api/k6-browser/
GNU Affero General Public License v3.0
342 stars 42 forks source link

Providing Browser Module Options as environment variables in Scenario has no effect #1068

Open SunstriderEx opened 1 year ago

SunstriderEx commented 1 year ago

Brief summary

There are Browser Module Options that can be provided as environment variables. When providing this options in command line then it works. But in scenario (section env) it don't.

xk6-browser version

k6 v0.47.0 (commit/5ceb210056, go1.21.2, windows/amd64)

OS

Windows 10

Chrome version

117.0.5938.152

Docker version and image (if applicable)

No response

Steps to reproduce the problem

Just run following script:

import { browser } from 'k6/experimental/browser';

export const options = {
  scenarios: {
    browserLevel: {
      options: {
        browser: {
          type: 'chromium',
        },
      },
      env: {
        K6_BROWSER_LOG: 'error',
        K6_BROWSER_HEADLESS: 'false',
      },
      executor: 'shared-iterations',
      vus: 1,
      iterations: 1,
    },
  },
};

export default async function () {
  console.log(`__ENV.K6_BROWSER_LOG = '${__ENV.K6_BROWSER_LOG}'`);

  const page = browser.newPage();

  try {
    await page.goto('https://test.k6.io/');
  } finally {
    page.close();
  }
}

Expected behaviour

Browser Module Options have to work with scenario. In this case browser GUI should be visible and console info message (console.log()) should be hidden.

Actual behaviour

Browser Module Options provided in scenario has no effect – browser opens in headless mode and info messages appear in output. Output messages for the script:

INFO[0001] __ENV.K6_BROWSER_LOG = 'error'                source=console

As you can see __ENV.K6_BROWSER_LOG equals error but info message presented anyway.


When providing this options in command line then it works as expected:

k6 run script.js -e K6_BROWSER_HEADLESS=false -e K6_BROWSER_LOG=error
inancgumus commented 1 year ago

@SunstriderEx I believe this feature works as expected, as the scenario environment variables are only for user scripts. However, the environment variables provided by the command-line are for the k6 process and its execution.