fintech-automation-test
Version:
Autonomous Test Automation
57 lines (49 loc) • 2.05 kB
JavaScript
const http = require('k6/http');
const { check, sleep } = require('k6');
const testData = JSON.parse(open('../../../test/api/testData/api_test_data.json'));
const options = {
vus: 10, // Virtual users
duration: '1m', // Test duration
};
// Function to perform login and return the session token or cookie
// function login() {
// const url = config.swaggerUrl; // Login endpoint
// const payload = JSON.stringify({
// username: config.username,
// password: config.password,
// });
// const params = {
// headers: {
// 'Content-Type': 'application/json',
// },
// };
// const response = http.post(url, payload, params);
//
// check(response, {
// 'login was successful': (r) => r.status === 200,
// });
//
// // Extract token from response body
// const authToken = JSON.parse(response.body).token; // Example: Extract token from response body
// return authToken; // Return the token to be used in subsequent requests
// }
function defaultFunction() {
//const token = login();
const headers = {
// 'Authorization': `Bearer ${token}`, // Pass the token as a Bearer token
'Content-Type': 'application/json',
};
const petResponsepayload = JSON.stringify({ id: 12345, name: 'User7610', status: 'available' });
let petResponse = http.put('https://petstore.swagger.io/v2/pet', petResponsepayload, { headers });
check(petResponse, {
'PUT /pet status is 200': (r) => r.status === 200,
});
sleep(1);
const userUsernameResponsepayload = JSON.stringify({ id: 12345, name: 'User4132', status: 'available' });
let userUsernameResponse = http.put('https://petstore.swagger.io/v2/user/{username}', userUsernameResponsepayload, { headers });
check(userUsernameResponse, {
'PUT /user/{username} status is 200': (r) => r.status === 200,
});
sleep(1);
}
module.exports = { options, default: defaultFunction };