Code Monkey home page Code Monkey logo

k6-csv-load-testing's Introduction

k6-csv-load-testing

k6JavaScript

k6-csv is a small project that demonstrates how to use the CSV file with k6, a modern load testing tool. This project uses k6 to test the authentication of an API using CSV data. The project includes a CSV file with login credentials and a k6 script that makes POST requests to the API for each set of credentials. The script then checks the responses for various conditions, including status codes and response times.

Getting Started

To use this framework, you need to have Node.js and k6 installed on your machine.

  • Clone the Repository
> git clone https://github.com/farhanlabib/k6-csv-load-testing.git
> cd k6-csv-load-testing
> npm install
  • Install k6
https://k6.io/docs/get-started/installation/

Folder Structure

Code is structured as shown below:

k6-Performance-Testing-Framework/
 ├── specs                                # The k6 test file is located in the spec folder.
 │    ├──main.js                          # Main k6 Script
 │    ├──data.csv                         # CSV File File
 │

Configuring the Test

The performance tests are configured using the options variable in the test script. The options variable defines the stages of the load test, including the duration and target number of requests per second for each stage.

The current configuration is set up as follows:

  • Stage 1: 5 second duration and target of 1 requests per second

Writing the Test

This main.js is a k6 performance test script that tests the login endpoint of a fake store API using data from a CSV file. The script imports the papaparse, http, and check libraries and defines the test stages, parses the CSV data, removes the header row, and makes POST requests for each row of data. The response is checked for various conditions using the check function. If the status code is not 200, the request body is logged to the console.

Run the Test

k6 run specs/main.js

This command will execute the test file and provide a summary of the test results in the console.

k6 run --log-format raw specs/main.js --console-output=./test.csv 

This command will execute the test file and provide a detailed raw log of the test results in a csv file.

Conclusion

This is a basic example of how to use the the CSV data with the k6 load testing tool. You can customize the test to suit your needs by changing the options and the test function.

Feel free to fork and make pull request for any additional feature.

k6-csv-load-testing's People

Contributors

farhanlabib avatar

Stargazers

tiny Flutter team avatar Borys Generalov avatar Amol Deokar avatar

Watchers

tiny Flutter team avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.