UNPKG

fintech-automation-test

Version:
91 lines (77 loc) 3.25 kB
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', }; let petFindbystatusResponse = http.get('https://petstore.swagger.io/v2/pet/findByStatus', { headers }); check(petFindbystatusResponse, { 'GET /pet/findByStatus status is 200': (r) => r.status === 200, }); sleep(1); let petFindbytagsResponse = http.get('https://petstore.swagger.io/v2/pet/findByTags', { headers }); check(petFindbytagsResponse, { 'GET /pet/findByTags status is 200': (r) => r.status === 200, }); sleep(1); let petPetidResponse = http.get('https://petstore.swagger.io/v2/pet/{petId}', { headers }); check(petPetidResponse, { 'GET /pet/{petId} status is 200': (r) => r.status === 200, }); sleep(1); let storeInventoryResponse = http.get('https://petstore.swagger.io/v2/store/inventory', { headers }); check(storeInventoryResponse, { 'GET /store/inventory status is 200': (r) => r.status === 200, }); sleep(1); let storeOrderOrderidResponse = http.get('https://petstore.swagger.io/v2/store/order/{orderId}', { headers }); check(storeOrderOrderidResponse, { 'GET /store/order/{orderId} status is 200': (r) => r.status === 200, }); sleep(1); let userUsernameResponse = http.get('https://petstore.swagger.io/v2/user/{username}', { headers }); check(userUsernameResponse, { 'GET /user/{username} status is 200': (r) => r.status === 200, }); sleep(1); let userLoginResponse = http.get('https://petstore.swagger.io/v2/user/login', { headers }); check(userLoginResponse, { 'GET /user/login status is 200': (r) => r.status === 200, }); sleep(1); let userLogoutResponse = http.get('https://petstore.swagger.io/v2/user/logout', { headers }); check(userLogoutResponse, { 'GET /user/logout status is 200': (r) => r.status === 200, }); sleep(1); } module.exports = { options, default: defaultFunction };