You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The artillery docs say "Any variable captured during the before execution will be available to all virtual users and to the after scenario. These sections can be useful to set up or tear down test data."
I'm unable to get this working in Playwright using a TypeScript config, and there doesn't seem to be any documentation on using before/after in this context.
This is what I've tried:
import{Page}from'@playwright/test';exportconstconfig={target: 'http://localhost:3000',engines: {playwright: {launchOptions: {headless: true,},},},};exportconstbefore={engine: 'playwright',testFunction: async(context: any,events: any,done: any): Promise<void>=>{context.vars=context.vars||{};context.vars.testData='hello from before';console.log(`before: set context.vars.testData to "${context.vars.testData}"`);}};exportconstafter={engine: 'playwright',testFunction: async(context: any,events: any,done: any): Promise<void>=>{context.vars=context.vars||{};console.log(`after: context.vars.testData is "${context.vars.testData}"`);}};exportconstscenarios=[{engine: 'playwright',testFunction: async(_page: Page,vuContext: any,_events: any,test: any): Promise<void>=>{console.log(`scenario: vuContext.vars.testData is "${vuContext.vars?.testData}"`);}}];
but the data is undefined in both the scenario and the after:
⠴ before: set context.vars.testData to "hello from before"
⠇ scenario: vuContext.vars.testData is "undefined"
⠇ after: context.vars.testData is "undefined"
I can use a global variable to pass info from the before to the after, but not the scenario:
letglobalData: any={};exportconstbefore={engine: 'playwright',testFunction: async(context: any,events: any,done: any): Promise<void>=>{globalData.testData='hello from before';console.log(`before: set globalData.testData to "${globalData.testData}"`);}};exportconstafter={engine: 'playwright',testFunction: async(context: any,events: any,done: any): Promise<void>=>{console.log(`after: globalData.testData is "${globalData.testData}"`);}};exportconstscenarios=[{engine: 'playwright',testFunction: async(_page: Page,vuContext: any,_events: any,test: any): Promise<void>=>{console.log(`scenario: globalData.testData is "${globalData.testData}"`);}}];
⠼ before: set globalData.testData to "hello from before"
⠇ scenario: globalData.testData is "undefined"
⠇ after: globalData.testData is "hello from before"
My next fallback is to rely on writing a file to disk to store the data I need, but what I really want to have access to is an instance of a class, so not easily serializable, and is quickly moving away from being able to usefully leverage the same code my Playwright functional tests use.
Can I get some guidance on how to properly pass data from before into both scenarios and after?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
The artillery docs say "Any variable captured during the before execution will be available to all virtual users and to the after scenario. These sections can be useful to set up or tear down test data."
I'm unable to get this working in Playwright using a TypeScript config, and there doesn't seem to be any documentation on using
before
/after
in this context.This is what I've tried:
but the data is undefined in both the scenario and the after:
I can use a global variable to pass info from the before to the after, but not the scenario:
My next fallback is to rely on writing a file to disk to store the data I need, but what I really want to have access to is an instance of a class, so not easily serializable, and is quickly moving away from being able to usefully leverage the same code my Playwright functional tests use.
Can I get some guidance on how to properly pass data from
before
into bothscenarios
andafter
?Beta Was this translation helpful? Give feedback.
All reactions