0

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?

asked Mar 7, 2025 at 8:56

1 Answer 1

0

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.

answered Mar 7, 2025 at 10:25
Sign up to request clarification or add additional context in comments.

1 Comment

Could you please help me with executing the before block?Im still not able to see the log which is inside the before block

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.