admin管理员组文章数量:1278854
Is there a best practice way to read csv files for test data?
Say I have a CSV file that looks like this:
username,password
joe,secret1
jane,secret2
bill,secret3
...and I want to use those usernames and passwords inside a k6 script.
Is there a best practice way to read csv files for test data?
Say I have a CSV file that looks like this:
username,password
joe,secret1
jane,secret2
bill,secret3
...and I want to use those usernames and passwords inside a k6 script.
Share Improve this question asked Nov 7, 2017 at 11:53 RagnarRagnar 1,1822 gold badges9 silver badges16 bronze badges1 Answer
Reset to default 8Yes! You'd use the open()
function in the init context (outside export default function() {...}
). Here's an example if you'd have JSON data in a file:
import { sleep } from "k6";
const data = JSON.parse(open("./data.json"));
export default function() {
let user = data[__VU - 1];
console.log(`${user.username}, ${user.password}`);
sleep(3);
}
...if you have a data file data.json
looking something like this:
[
{
"username" : "user1",
"password" : "test"
},
{
"username" : "user2",
"password" : "test"
}
]
To do the same thing with CSV, I'd look for a JS CSV parsing library and import it as a module
本文标签: javascriptReading from a file in k6Stack Overflow
版权声明:本文标题:javascript - Reading from a file in k6 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741302293a2371159.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论