Skip to content
Learn with RV – Tech Blog
Learn with RV – Tech Blog

#testautomation #qa #programming #linux #devops

  • Home
  • Who am I?
  • 1-on-1 Mentoring
  • 18 Testimonials
  • YouTube
  • LinkedIn
  • Contact
Learn with RV – Tech Blog

#testautomation #qa #programming #linux #devops

August 12, 2024October 2, 2024

How to add Error Handler to log errors in k6 load tests

Apparently, when you run k6 load tests and some of them fails, by default you don’t have access to the errors in the console (the only things displayed are the test name and the expected result, but NOT the actual result). In order to see the actual results that caused the failure, you will need to implement an Error Handler class in your project.

error-k6-no-actual

For example, in the above image you can’t know why the test failed. The status code was not expected 200, but what was the actual status? Personally, I consider this information mandatory for the debugging process.

The solution

In the project structure, I usually like to create a ‘lib’ folder with a new ‘ErrorHandler.js’ file that contains the following

The next step is to import the ‘errorHandler’ method in our test file.

Note: depending on your test file location, you might have a different “from ‘./lib‘” path. Also double check ErrorHandler ends with ‘.js‘

Last but not least, include the errorHandler.logError method in each of your tests.

Test example:

That’s it! Simple, isn’t it? Now whenever a test happens to fail, you will see in the console the actual error – e.g. below example shows an actual status code of 502 that causes test failure

You can find more information regarding this approach and also the source code in the official Grafana documentation HERE

Enjoyed this article? Make sure to subscribe to my YouTube Channel for more Test Automation tutorials, and follow me on LinkedIn and Twitter for regular insights.
Looking to improve your test automation skills?
I’ve created a personalized 1-on-1 Mentoring program refined to boost YOUR skills. Reach out at iamrv@razvanvancea.ro for more details and together will create a learning path adapted to your current skills and goals that you are aiming for, in a timely-efficient manner🚀

Post Views: 221

Related

Share this article:
QA

Post navigation

Previous post
Next post

Recent Posts

  • Using cross-env in Your Node.js Projects: A Practical Guide
  • How to copy-paste text from clipboard using TestCafe
  • How to copy-paste text from clipboard using Cypress
  • How to repeat any CLI Command for X times using NPM repeat-cli-command
  • k9s: A Guide to Master Kubernetes Clusters from your Terminal

Recent Comments

  1. Paul on Web Accessibility: A step-by-step guide to Testing with pa11y
  2. Automated Tests for website Accessibility with Axe and TestCafe - Learn with RV - Tech Blog on How to generate E2E TestCafe Framework in seconds
  3. RV on Exploring Faker.js: A Powerful Tool for Generating Realistic Random Test Data
  4. Adrian Maciuc on Exploring Faker.js: A Powerful Tool for Generating Realistic Random Test Data
  5. Nick on Cypress vs Playwright vs Testcafe – which framework is faster?

Archives

  • June 2025
  • March 2025
  • February 2025
  • January 2025
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023

Categories

  • Linux
  • Programming
  • QA
  • Tools
  • Uncategorized
©2025 Learn with RV – Tech Blog | WordPress Theme by SuperbThemes