K6 HTTP Authentication

1.3k Views Asked by At

I am having a login page with "Username, Password" and "login" button. I am able to login with the username and password manually from the browser.

In K6, through script, I am facing issue when i try to login by passing the username and password to the K6 script. Trying to get login status is authenticated? or not as part of my load test script? I am getting INFO[0000] null in the console.

Below is my script.

import http from 'k6/http';
import encoding from 'k6/encoding';
import { check } from 'k6';

export default function () {

const encodedCredentials = encoding.b64encode("admin:pass@1");
const options = {
headers:{
    Authorization: `Basic ${encodedCredentials}`,
}};

const res = http.post('https://mysiteexample.com/LogIn', options); 
console.log(res.json);
}

I have followed this official URL https://k6.io/docs/examples/http-authentication/ but this also doesn't work for me and URL given in the doc is not clear how to format my URL like this.

0

There are 0 best solutions below