Multiple scenario with single file

Hi Team,

New to the K6, I’m planning to set up a framework that supports multiple applications with a single repo. Guide me on this.

User Scenario:
A portal contains multiple applications. All the applications some steps are common and some are different like below. I plan to break the individual export functions (Ex export function step01(){}, …)

App01Test.js

  1. Scenario 01
  • Common Step 01
  • Step 02
  • Step 03
  1. Scenario 02
  • Common Step 01
  • Step 03
  • Step 04
  1. Scenario 03
  • Common Step 01
  • Step 04
  • Step 05

App01Test.js

  1. Scenario 01
  • Common Step 01
  • Step 06
  • Step 07
  1. Scenario 02
  • Common Step 01
  • Step 06
  • Step 08
  1. Scenario 03
  • Common Step 01
  • Step 06
  • Step 09

Then if I want to run a test on App 01, I can simply run “k6 run App01Test.js”. How can I achieve this?

You can split your tests into different JS files, and each of those can export relevant options and functions to run just that single test. Then you can have other files that import these single files and re-export some of their functions and export options.scenarios so that multiple tests run concurrently. And you can have environment variables in some of these files to toggle certain sub-scripts on and off. Here are some links to get you started:

1 Like