diff --git a/k6-test-data/arrays.js b/k6-test-data/arrays.js new file mode 100644 index 0000000..fac12d1 --- /dev/null +++ b/k6-test-data/arrays.js @@ -0,0 +1,16 @@ +import http from 'k6/http'; + +export const options = { + vus: 3, + duration: '3s', +}; + +const usernames = ['user1','user3','admin']; +const passwords = ['123123','qwerty','qweqweqwe']; + +export default function () { + http.get('https://test-api.k6.io/public/crocodiles/'); + let random = Math.floor(Math.random() * usernames.length); + + console.log(`username: ${usernames[random]}, psw: ${passwords[random]}`); +} diff --git a/k6-test-data/csv-example.js b/k6-test-data/csv-example.js new file mode 100644 index 0000000..f2a622b --- /dev/null +++ b/k6-test-data/csv-example.js @@ -0,0 +1,18 @@ +import http from 'k6/http'; + +import papaparse from 'https://jslib.k6.io/papaparse/5.1.1/index.js'; + +const csvData = papaparse.parse(open('data.csv'), {header: true}).data; + +export const options = { + vus: 3, + duration: '3s', +}; + +export default function () { + http.get('https://test-api.k6.io/public/crocodiles/'); + + let random = Math.floor(Math.random() * csvData.length); + + console.log(`username: ${csvData[random].username}, psw: ${csvData[random].password}`); +} diff --git a/k6-test-data/data.csv b/k6-test-data/data.csv new file mode 100644 index 0000000..44176ae --- /dev/null +++ b/k6-test-data/data.csv @@ -0,0 +1,4 @@ +username,password +user,123456 +johndoe,qwerty +admin,123qwe123 \ No newline at end of file diff --git a/k6-test-data/data.json b/k6-test-data/data.json new file mode 100644 index 0000000..595104c --- /dev/null +++ b/k6-test-data/data.json @@ -0,0 +1,6 @@ +{ + "users": [ + { "username": "json_admin", "password": "123456" }, + { "username": "json_test", "password": "qwerty" } + ] + } \ No newline at end of file diff --git a/k6-test-data/json-example.js b/k6-test-data/json-example.js new file mode 100644 index 0000000..a918b4f --- /dev/null +++ b/k6-test-data/json-example.js @@ -0,0 +1,16 @@ +import http from 'k6/http'; + +const jsonData = JSON.parse(open('./data.json')).users; + +export const options = { + vus: 3, + duration: '3s', +}; + +export default function () { + http.get('https://test-api.k6.io/public/crocodiles/'); + + let random = Math.floor(Math.random() * jsonData.length); + + console.log(`username: ${jsonData[random].username}, psw: ${jsonData[random].password}`); +} diff --git a/k6-test-data/shared-array-example.js b/k6-test-data/shared-array-example.js new file mode 100644 index 0000000..d311216 --- /dev/null +++ b/k6-test-data/shared-array-example.js @@ -0,0 +1,20 @@ +import http from 'k6/http'; +import {SharedArray} from 'k6/data'; + +const sharedData = new SharedArray("Shared Credentials", function(){ + let data = JSON.parse(open('./data.json')).users; + return data; +}) + +export const options = { + vus: 3, + duration: '3s', +}; + +export default function () { + http.get('https://test-api.k6.io/public/crocodiles/'); + + let random = Math.floor(Math.random() * sharedData.length); + + console.log(`username: ${sharedData[random].username}, psw: ${sharedData[random].password}`); +} diff --git a/k6-test-data/template-script.js b/k6-test-data/template-script.js new file mode 100644 index 0000000..4a8114a --- /dev/null +++ b/k6-test-data/template-script.js @@ -0,0 +1,10 @@ +import http from 'k6/http'; + +export const options = { + vus: 3, + duration: '3s', +}; + +export default function () { + http.get('https://test-api.k6.io/public/crocodiles/'); +}