Reusing k6 browser across VUs

Hi,

I have been testing one of a high-volume app (API and rendering of HTML) in the same scenario, it has been working quite well, however the VUs we configured was only 25, we really need to get our soak and spike tests with k6, we want to reach as high as 500 VUs, I understand just vertically scaling the machines will help the cause, unfortunately we will not be able to do it all the way.

Am I right in assuming that for each VU a browser instance is created? Is it possible to share an instance of a browser across all VUs? Is reusing pages an option? could you please advise on some best practices to run efficient browser tests

Thanks

Hi @harishvenkataramanan,

Yes, it’s possible.

You can use the K6_BROWSER_WS_URL environment variable to pass a DevTools WebSocket URL to the k6 browser.

  1. Run a Chromium browser with remote debugging on:

    yourChromiumExecutable --remote-debugging-port=9222
    
  2. Extract the WebSocket URL:

    curl -s localhost:9222/json/version
    

    Or, go to this address in your browser and find webSocketDebuggerUrl.

  3. Pass the WebSocket URL to the k6 browser:

    K6_BROWSER_WS_URL='websocket URL here' k6 script.js
    

PS: You can also pass multiple WebSocket URLs separated by commas.

Hope this helps.