Created
June 20, 2020 05:56
-
-
Save spham/2f40d24b535a542ef84552615fc7d21b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { | |
| sleep, | |
| group | |
| } from "k6"; | |
| import http from "k6/http"; | |
| export const options = { | |
| stages: [{ | |
| duration: "1m", | |
| target: 10 | |
| }, | |
| { | |
| duration: "3m", | |
| target: 10 | |
| }, | |
| { | |
| duration: "1m", | |
| target: 0 | |
| }, | |
| ], | |
| }; | |
| export default function main() { | |
| let response; | |
| // get token csrf | |
| const res = http.get("https://my.svp.com/login", { | |
| "responseType": "text" | |
| }); | |
| const elem = res.html().find('input[name=_token]'); | |
| const val = elem.attr('value'); | |
| group("page_1 - https://my.svp.com/login", function () { | |
| response = http.post( | |
| "https://my.svp.com/login", | |
| '{"_token": val,"email":"loginHere","password":"passwordHere"}', { | |
| headers: { | |
| accept: "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", | |
| "accept-encoding": "gzip, deflate, br", | |
| "accept-language": "fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7,la;q=0.6,bn;q=0.5,vi;q=0.4,es;q=0.3,da;q=0.2,zh-CN;q=0.1,zh;q=0.1,de;q=0.1", | |
| "cache-control": "max-age=0", | |
| connection: "keep-alive", | |
| host: "my.svp.com", | |
| "sec-fetch-dest": "document", | |
| "sec-fetch-mode": "navigate", | |
| "sec-fetch-site": "cross-site", | |
| "sec-fetch-user": "?1", | |
| "upgrade-insecure-requests": "1", | |
| "Content-Type": "application/json", | |
| }, | |
| } | |
| ); | |
| }); | |
| group("page_2 - https://my.svp.com/logout", function () { | |
| response = http.post( | |
| "https://my.svp.com/logout", | |
| '{"_token": val}', { | |
| headers: { | |
| accept: "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", | |
| "accept-encoding": "gzip, deflate, br", | |
| "accept-language": "fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7,la;q=0.6,bn;q=0.5,vi;q=0.4,es;q=0.3,da;q=0.2,zh-CN;q=0.1,zh;q=0.1,de;q=0.1", | |
| "cache-control": "max-age=0", | |
| connection: "keep-alive", | |
| host: "my.svp.com", | |
| "sec-fetch-dest": "document", | |
| "sec-fetch-mode": "navigate", | |
| "sec-fetch-site": "same-origin", | |
| "sec-fetch-user": "?1", | |
| "upgrade-insecure-requests": "1", | |
| "Content-Type": "application/json", | |
| }, | |
| } | |
| ); | |
| }); | |
| // Automatically added sleep | |
| sleep(1); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment