Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
K6 unique data per scenario

I am creating a test with two scenarios with different amount of users and ramp-up time. The idea is that each user shall login once to retrieve a SSO-cookie, that shall be used in subsequent requests. The user data is stored in one json-file and each group of users are parsed to two shared arrays, one for each scenario. The users are grouped in the JSON with different roles and accesses rights so they can't be mixed.

The below code works pretty well if you don't have that many users and "correct" sleep in business logic part, else it will get out sync in regards of exec.scenario.iterationInTest. I am not able to use VU id either since VU id is per test and not per scenario.

Anyone who has any workaround for this?

At the moment I am calling a third party API-counter to get numbers in order to get unique users for each scenario but I don't like that solution. It would be great to have a unique VuserID per scenario starting from 1.

import { SharedArray } from "k6/data";
import jsonpath from "https://jslib.k6.io/jsonpath/1.0.2/index.js"

import { login } from '../requests/login.js';

const testdata = JSON.parse(open('../data/testdata.json'));
const usersA = new SharedArray("usersA", function () { return jsonpath.value(testdata, '$.usersA') });
const usersB = new SharedArray("usersB", function () { return jsonpath.value(testdata, '$.usersB') });

let user;
const usersARampUp = usersA.length * 2;
const usersBRampUp = usersB.length * 9;


export const options = {
    scenarios: {
        loginUserA: {
            executor: 'ramping-vus',
            exec: 'userA',
            startVUs: 0,
            stages: [
                { duration: usersARampUp + 's', target: usersA.length },
                { duration: '10m', target: usersA.length }
            ]
        },
        loginUserB: {
            executor: 'ramping-vus',
            exec: 'userB',
            startVUs: 0,
            stages: [
                { duration: usersBRampUp + 's', target: usersB.length },
                { duration: '10m', target: usersB.length }
            ]
        }
    }
};

export function userA() {
    let dataCounter = exec.scenario.iterationInTest;

    if (__ITER == 0) { //Only login once per test to retrieve SSO cookie
        user = usersA[dataCounter];
        login(user.userName, user.password); //SSO-cookie is set in cookieJar
    }
  //Business logic after login and SSO cookie is retrieved
}

export function userB() { 
    let dataCounter = exec.scenario.iterationInTest;

    if (__ITER == 0) { //Only login once per test to retrieve SSO cookie
        user = usersB[dataCounter];
        login(user.userName, user.password); //SSO-cookie is set in a cookieJar
    }
  //Business logic after login and SSO cookie is retrieved
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!