fintech-automation-test
Version:
Autonomous Test Automation
92 lines (79 loc) • 3.98 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 petPetidUploadimageResponsepayload = JSON.stringify({ id: 12345, name: 'User4182', status: 'available' });
let petPetidUploadimageResponse = http.post('https://petstore.swagger.io/v2/pet/{petId}/uploadImage', petPetidUploadimageResponsepayload, { headers });
check(petPetidUploadimageResponse, {
'POST /pet/{petId}/uploadImage status is 200': (r) => r.status === 200,
});
sleep(1);
const petResponsepayload = JSON.stringify({ id: 12345, name: 'User2512', status: 'available' });
let petResponse = http.post('https://petstore.swagger.io/v2/pet', petResponsepayload, { headers });
check(petResponse, {
'POST /pet status is 200': (r) => r.status === 200,
});
sleep(1);
const petPetidResponsepayload = JSON.stringify({ id: 12345, name: 'User278', status: 'available' });
let petPetidResponse = http.post('https://petstore.swagger.io/v2/pet/{petId}', petPetidResponsepayload, { headers });
check(petPetidResponse, {
'POST /pet/{petId} status is 200': (r) => r.status === 200,
});
sleep(1);
const storeOrderResponsepayload = JSON.stringify({ id: 12345, name: 'User536', status: 'available' });
let storeOrderResponse = http.post('https://petstore.swagger.io/v2/store/order', storeOrderResponsepayload, { headers });
check(storeOrderResponse, {
'POST /store/order status is 200': (r) => r.status === 200,
});
sleep(1);
const userCreatewithlistResponsepayload = JSON.stringify({ id: 12345, name: 'User3195', status: 'available' });
let userCreatewithlistResponse = http.post('https://petstore.swagger.io/v2/user/createWithList', userCreatewithlistResponsepayload, { headers });
check(userCreatewithlistResponse, {
'POST /user/createWithList status is 200': (r) => r.status === 200,
});
sleep(1);
const userCreatewitharrayResponsepayload = JSON.stringify({ id: 12345, name: 'User7758', status: 'available' });
let userCreatewitharrayResponse = http.post('https://petstore.swagger.io/v2/user/createWithArray', userCreatewitharrayResponsepayload, { headers });
check(userCreatewitharrayResponse, {
'POST /user/createWithArray status is 200': (r) => r.status === 200,
});
sleep(1);
const userResponsepayload = JSON.stringify({ id: 12345, name: 'User1511', status: 'available' });
let userResponse = http.post('https://petstore.swagger.io/v2/user', userResponsepayload, { headers });
check(userResponse, {
'POST /user status is 200': (r) => r.status === 200,
});
sleep(1);
}
module.exports = { options, default: defaultFunction };