Print attribute username when request fails

Hi Team,
I want to write the attribute username in a file when it fails or exits for any reason. kinda Finally block in scala. I tried the below code below setup() but its throwing error “missing parameter type: session”
after {
session =>
if (!session.isSuccess) {
session(“user”).asOption[String] match {
case Some(user) =>
// Log the username into the file
val writer = new java.io.FileWriter(file, true)
try {
writer.write(s"Failed request with username: $username\n")
} finally {
writer.close()
}
case None =>
// No username found in the session
println(“No username found for failed request.”)
}
}
session
Thanks

Hello Alex,

As a quick note, you will get a faster answer if you post this in the open-source section as this part of the forum is related to Enterprise questions.

Unfortunately, right now I don’t know of any easy way to do this. If you find a solution I would be interested to see it.

Best of luck,
Pete

Some time ago I have thinking about something similar, you can see code snippet in Java for my proposition here:

In scala the After hook isn’t working and I need to print the username when the request fails.

The after hook works as expected, see Gatling Simulation scripting reference

It runs once after the whole Simulation completes, not every time after each virtual user completes.

@slandelle is there any option where I can write the failed usernames in a file when it exits?

Hi All,
Found a solution:
For single file Using the below we can extract the usernames or any other attributes and output it to a new file.
grep -o 'username → [^,]’ target/gatling/reports/simulation-errors-.log | sed ‘s/username → //g’ | sort | uniq > target/gatling/reports/UsernameExtracted.txt

The above command can be added in Jenkins job etc during completion of reports.

-A

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.