Replies: 1 comment 1 reply
-
Hey @patarky 👋 Thanks for the thorough explanation. As you mentioned, My suggestion is that you integrate the export async function getUser(): Promise<void> {
const initialTime = Date.now();
const res: User | null = await redis.lpop('users');
console.log('Response from Redis:', res);
if (res === null) {
console.error('No users found in Redis');
throw new Error('err_no_users_found_in_redis');
}
const user: User = res;
const finalTime = Date.now();
if (process.env.SHOW_TIMING) {
console.log(`Time taken: ${finalTime - initialTime}ms`);
}
console.log('getUser username', user.username);
console.log('getUser password', user.password);
return user
}
export async function playwrightLoginTest(page, context, events, test) {
const { step } = test;
const user = await getUser();
context.vars.username = user.username;
context.vars.password = user.password;
await loginCms(page, step, context);
} This way it is basically the same as doing it with |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi artillery.io community,
I greatly appreciate the active and helpful discussions on this board. I am currently facing an issue where I can't access
context.vars
from a Playwright testfunction, and I am hoping for some guidance.Problem Description
I am attempting to build a parameterized smoke test for our internal CMS system, which is behind a login. Each virtual user must be unique as they alter server-side data. I followed the Redis/Upstash example, which was beneficial for user creation and uniqueness.
However, I am stuck on reusing the
context.vars
values generated from thegetUser
(in processor.ts) function. Although I am passing the context object along, the values forcontext.vars.username
andcontext.vars.password
turn up as undefined when accessed in my Playwright scenario."Expected" Behavior
Before each Playwright scenario, I expect a
beforeScenario
hook to retrieve an individual user from Redis and store the username and password incontext.vars
for access in subsequent scenarios. My understanding is that for all scenarios executet by a vU the beforeScenario is always executet bevorhand.Current Behavior
"playwrightLoginTest"
works when I do not usebeforeScenario
and instead use hardcoded username and password incommands.ts
."beforeScenario: getUser"
successfully logs the correct user from Redis into the console."beforeScenario: getUser"
and"testFunction: "playplaywrightLoginTest"
are run together, the all console.log statements within the playwright parts outputundefined
for both the username and password. Additionally, the browser window often does not open.My gut feeling from reading the docs and other discussions is, that somehow or by design of artillery the
context.vars.username
andcontext.vars.password
can only be accesed withinbeforeScenario
. I think its not a artilley issue and more on my side - because I'm not that experienced. But I'm somehow confused because it seems so simple - to get access to the stored values. I hope someone here can give me a hint or point me in the right direction. Thank you all for taking a look.artillery.yml
processor.ts
commands.ts
console output from a run with above yml:
Infobits:
beforeScenario is currently not compatible with playwright but I try to use it not in the same scenario (which could be the issue?)
#2279
I thought about beforeScenario because of this comment:
#2770
Other solutions to this case by using .env vars:
https://medium.com/@tolandominic/front-end-load-testing-with-playwright-and-artillery-4fa1ac615fda
Beta Was this translation helpful? Give feedback.
All reactions