fugmag
November 29, 2022, 8:13am
1
I have K6-code that tries to parameterize a value to a URL. Here are some code snippets.
const csvDataPatients = new SharedArray('patients', function () {return papaparse.parse(open('../testdata/patients.csv'), { header: true }).data;});
.
.
.
const randomPatient = csvDataPatients[Math.floor(Math.random() * csvDataPatients.length)];
urlProxy.searchParams.append('test_pid', randomPatient);
.
.
.
console.log((urlProxy));
The problem is that console.log print this:
INFO[0000] "https://dev.xx.xx.xx.xx/hpp-webapp/careplan/proxy/login?test_pid=%5Bobject+Object%5D" source=console
The value seems to be encoded wrong?
What happens if you console.log(JSON.stringify(randomPatient)))
? Because it seems like it’s not a simple ID, but rather an Object
of some sort.
fugmag
November 29, 2022, 9:57am
3
INFO[0000] {“fnr”:“05085600143”}
fugmag
November 29, 2022, 9:59am
4
And:
console.log(JSON.stringify(urlProxy))
Gives me:
INFO[0000] “https://xxx/careplan/proxy/login?test_pid=[object+Object] ”
Just use randomPatient.fnr
then?
fugmag
November 29, 2022, 10:47am
6
Hmm,
Where in my script?
const csvDataPatients = new SharedArray('patients', function () {return papaparse.parse(open('../testdata/patients.csv'), { header: true }).data;});
const csvDataHp = new SharedArray('hp', function () {return papaparse.parse(open('../testdata/hp.csv'), { header: true }).data;});
export default function main() {
let response
const vars = {}
const urlProxy = new URL('https://xxx/careplan/proxy/login');
const randomPatient = csvDataPatients[Math.floor(Math.random() * csvDataPatients.length)];
urlProxy.searchParams.append('test_pid', randomPatient);
console.log((randomPatient));
//console.log(JSON.stringify(urlProxy))
//console.log((urlProxy));
group(
'careplan_proxy_login',
function () {
response = http.get(urlProxy.toString()),
{
headers: {
Where you add it to the URL:
fugmag
November 29, 2022, 11:31am
8
urlProxy.searchParams.append(‘test_pid’, randomPatient.fnr);
Gives me “unresolved variable”
Maybe you don’t have fnr
on some randomPatient
rows? I am sorry, but I can’t debug your script in this way, message by message. I suggest you add some checks and console.log()
statements and see where the problem lies that way…
fugmag
November 29, 2022, 2:24pm
10
Ok, fnr is the heading of the csv file, like this:
fnr
13116900216
05085600143