-
Notifications
You must be signed in to change notification settings - Fork 224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document how to transfer cookies from setup() to all VUs #199
Comments
Hm, I suppose we can make this work (haven't looked at the code) but I think it will be of little value. Ultimately you will probably have multiple logins in the majority of cases and you will need to return the tokens as an array/json object from I am not certain that having the cookies from the |
We probably could implement something like this, but I don't think we should. Here are my two main reasons:
import http from "k6/http";
export function setup() {
let res = http.get("https://httpbin.org/cookies/set?my_cookie=test&cookie2=123");
return { cookies: http.cookieJar().cookiesForURL("https://httpbin.org") };
}
export default function (data) {
if (__ITER === 0) { // or in initVU() after https://github.com/loadimpact/k6/issues/785 is done
let jar = http.cookieJar();
Object.keys(data.cookies).forEach(key => {
jar.set("https://httpbin.org", key, data.cookies[key][0]);
});
}
let res = http.get("https://httpbin.org/cookies");
console.log(res.body);
}
What I propose instead of copying the cookies from |
Understood. I think I was assuming the cookie would be maintained, since most other performance tools have the same setup functionality, and it is used primarily as a login function. |
Moving this to the k6.io/docs repo, we should add something like the example above (#199 (comment)) to the docs, along with the explanation that |
If you use the setup function to perform login steps - for example, logging in and automatically storing an SSO cookie - those cookies that are stored will not be automatically available to the main function (please contact me for a specific reproduction, if needed).
The text was updated successfully, but these errors were encountered: