Hi guys,
We are currently trying to run multiple users with different sessions in a performance test.
We used the documentation: Data Parameterization from your website.
That part works, we see it picks random user, with password and does the login flow for our application.
However, the login flow generates a cookie that we want to use in an upcoming request after the login flow.
- Login flow (2 requests)
- Actual test endpoint from svc (1 request)
It works just fine if we have the 3 requests in the “export default function”, however we want to have the login flow as part of the “export function setup”, as explained here. Test lifecycle
If we do that, it will use the random user picker but it will just create one cookie and use only one user for all VUS.
Could you explain how we can solve that problem for every VU and have the login flow not part of the actual test?
And, what is best practice is in this use case in your opinion?
export default function () {
let res;
const randomUser = csvData[Math.floor(Math.random() * csvData.length)];
res = http.get(__ENV.URL + '/login', { responseType: 'text' });
const elem = res.html().find('input[name=csrf]');
const val = elem.attr('value');
sleep(randomIntBetween(2, 3));
const params = {
"csrf" : val,
"username": randomUser.username,
"password": __ENV.PASSWORD,
};
console.log('Random user: ', JSON.stringify(params));
res = http.post(__ENV.URL + '/doLogin/', params, {redirects: 0,})
cookie = res.cookies
sleep(randomIntBetween(2, 3));
console.log('Cookie: ', JSON.stringify(cookie));
check(res, {
'login succeeded': (r) => r.headers['Location'] === '/dashboard/'
});
sleep(1);
res = http.get(__ENV.URL + '/by-session', cookie)
check(res,
{'is status 200': (r) => r.status === 200},
{'is not empty' : (r) => r.json().access_token
});