k6 community forum

How i can use absolute path in k6 load testing framework

I want to use absolute path in k6 js script file. Can someone please help in how to do this?

Instead of this

import {getAddCookieInfoPayLoad} from "../../../scripts/oAuth/addCookieInfoScript.js";
import {getQueryCookieInfoPayLoad} from "../../../scripts/oAuth/queryCookieInfoScript.js";

I want this:

import {getAddCookieInfoPayLoad} from "scripts/oAuth/addCookieInfoScript.js";

import {getQueryCookieInfoPayLoad} from "scripts/oAuth/queryCookieInfoScript.js";

You can use absolute paths:

import {getAddCookieInfoPayLoad} from "/absolute/path/to/scripts/oAuth/addCookieInfoScript.js";

and you can also import them with the file:// schema:

import {getAddCookieInfoPayLoad} from "file:///absolute/path/to/scripts/oAuth/addCookieInfoScript.js";

Though in general I find relative paths to be more usable and be more reliable when multiple people are working on the scripts, possibly across different OSes.