-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTest_demo.js
86 lines (68 loc) · 2.57 KB
/
Test_demo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import http from 'k6/http';
import { check, sleep } from 'k6';
import { SharedArray } from 'k6/data';
import { describe, expect} from 'https://jslib.k6.io/k6chaijs/4.3.4.0/index.js'
import papaparse from 'https://jslib.k6.io/papaparse/5.1.1/index.js';
import { textSummary } from 'https://jslib.k6.io/k6-summary/0.0.1/index.js';
const url = 'https://reqres.in/api/users';
// Introducir CSV Data Driven -----------
const csvData = new SharedArray("credentials", function() {
return papaparse.parse(open('./DD.csv'), {header: true}).data;;})
//export function setup() {
// let token = http.get('https://reasdasdsadsdas/d/asd/asd/as/sa');
// }
//
export const options = {
scenarios: {
Unidad: {
executor: 'per-vu-iterations',
vus: 1000,
iterations: 1,
maxDuration: '1s',
gracefulstop: '30s'
},
//PreVUS: {
// executor: 'constant-arrival-rate',
// duration: '1s',
// rate: 100,
// timeUnit: '5s',
// preAllocatedVUs: 10,
// maxVUs: 100,
//},
},
};
export default function () {
// Loop through all username/password pairs ------------
//for (const userPwdPair of csvData) {
// console.log(JSON.stringify(userPwdPair));
// }
// Pick a random username/password pair -------------
var RamdomDataCSV = csvData[Math.floor(Math.random() * csvData.length)];
var names = csvData[Math.floor(Math.random() * csvData.length)]['names'];
var jobs = csvData[Math.floor(Math.random() * csvData.length)]['jobs'];
var payload = JSON.stringify(
{
"name": RamdomDataCSV['names'],
"job": RamdomDataCSV['jobs'],
});
//console.log('debug: ', JSON.stringify(payload));
var params = {
//cookies: { my_cookie: 'value' },
headers:{ 'Content-Type': 'application/json',
//'User-Agent': 'k6',
//'Authorization': 'Token ' + apiToken
}}
// Using a JSON string as body
describe('CONDICIONES ...', () => {
var response = http.get(url, payload, params);
expect(response.status,'El estado de la respuesta').to.equal(200)
})
//sleep(5);
};
export function handleSummary(data) {
console.log('Finished executing performance tests');
return {
'stdout': textSummary(data, { indent: ' ', enableColors: true }), // Show the text summary to stdout...
'summary.json': JSON.stringify(data), // and a JSON with all the details...
};
}