I'm using Artillery to load test a web page and trying to perform an action before the load test begins. I attempted to use the "before" hook and print a console.log inside the testLandingPageFlow method. However, when I run the test, I am not able to print the log which is inside the before block
Here is my code (test.ts):
import testConfig from "../config/login.json";
import { testLandingPageFlow } from "../functional/login.test";
export const config = {
...testConfig,
before: {
engine: "playwright",
flowFunction: async()=>{
await beforeLandingPageFlow()
}
},
};
export const scenarios = [
{
engine: "playwright",
flowFunction: testLandingPageFlow,
},
];
export function $rewriteMetricName(metricName: string) {
const metrics = ["TTFB", "LCP", "FID", "FCP", "INP", "CLS"];
for (const metric of metrics) {
if (metricName.startsWith(`browser.page.${metric}`)) {
return `browser.page.${metric}`;
}
}
return metricName;
}
export async function beforeLandingPageFlow() {
console.log("test ***************************************************************************************** ");
}
And here is my config file:
{
"title": "Browser Load test",
"target": "https://my-dev-test.com/",
"plugins": {
"expect": {
"enabled": true
},
"ensure": {
"thresholds": [
{
"browser.page.TTFB.p95": 800
},
{
"browser.page.LCP.p95": 2500
},
{
"browser.page.INP.p95": 200
},
{
"browser.page.FCP.p95": 2000
}
],
"conditions": [
{
"expression": "vusers.failed == 0"
},
{
"expression": "vusers.completed > 200"
}
]
}
},
"engines": {
"playwright": {
"showAllPageMetrics": false,
"defaultTimeout": 90000,
"launchOptions": {
"headless": true
}
}
},
"phases": [
{
"duration": 60,
"arrivalRate": 1,
"maxVusers": 1,
"name": "Ramp up to max 200 virtual users per second for 60s"
}
]
}
Can anyone help me understand why I'm not able to see the log or why is before block not getting executed?
1 Answer 1
Should work if you remove the quotes, i.e.
flowFunction: "beforeLandingPageFlow" to flowFunction: beforeLandingPageFlow
That way you're passing a reference to the function itself, rather than its name as a string.