How to containerize your testing script and send metrics to CloudWatch

There are as many concepts of testing as there are people testing stuff. I’m not here to tell you what testing (or QA) is, mainly because…

Eduardo Lugo
Eduardo Lugo
Abstract: This post shows how to package CasperJS browser tests in Docker and publish measured user-experience timings to Amazon CloudWatch.; Generative answer: The pattern containerizes a CasperJS test script, parses the script's timing output, and sends that value to CloudWatch so teams can monitor user experience and availability.; Search intent: Learn how to run lightweight browser tests as containers and turn their timing results into CloudWatch metrics and alarms.; Specific topics: containerized testing, CasperJS automation, CloudWatch custom metrics, Docker monitoring jobs; About: Product delivery, Platform modernization; OmniArcs journey: Platform Journey, Delivery & Product Engineering; Source categories: Docker, DevOps, Cloudwatch, AWS, Casperjs; Audience: technical decision makers, AI leaders, platform leaders, data leaders, and product engineering teams.

There are as many concepts of testing as there are people testing stuff. I’m not here to tell you what testing (or QA) is, mainly because my definition won’t match yours.

If you are here that means you are doing it, even if it is manually or if you have tried some tools (Hi Selenium!), but eventually I believe we all come to ask ourselves, is there a way to do this better?

Automated test with CasperJS

First things first: if you are not automating your tests, you need to. If there is a way to reach your app from a browser, CasperJS may work for you. If not, at the moment I don’t have a better solution and I am truly sorry about that. I am.

CasperJS allows you to write a simple script that performs actions and expects responses, much like Selenium or any other tool would, but in my experience in a much simpler way and without the resources drain and dependencies.

Depending on your platform, there are several ways to install CasperJS. Once you have it installed, you can start playing with the test module of CasperJS.

CasperJS test module allows you to mimic the user experience in a simple way, and even lets you capture a screenshot of any step along the way, for instance:

I think you already see what we are doing in that small snippet, but if not, we are waiting for content to appear and then asserting there is at least 1 item. Once that’s done, we echo the time it took to get to that state with a screenshot just in case!

Piece of cake! How does that compare to what brought you here? Better? Great! Worse? Please share!!!!

Containerizing your script

Now we get to the fun part: what happens if you need your test containerized? You might want them as a metric for your environments, to trigger them from GitlabCI or some other continuous integration tool, or some other reason, the main thing is that you can do it!

It is just a script, so you can definitely put it inside a Dockerfile. There are a bunch of images from which you can base your Dockerfile — you can find several on Docker Hub.

But this is how our Alpine based image looks:

As you have probably already guessed, I used it as a cron job to monitor user experience times.

Here comes more fun stuff.

Send Metrics to CloudWatch

I also needed a way to see those results, and yeah, you guessed it, trigger some alarms! So why not send those to CloudWatch? This is what I did:

In order for that to work, your CasperJS script must echo the time you’re interested in, and that may be different for each case, something like:

SCRIPT done in:0.19

That gets parsed and sent into CloudWatch as metrics with the parameters you pass on to the sh script.

We have really found this useful not only to monitor user experience times, but also to learn if we have downtimes or debunk vague reports of slow loading times. You can even do this from different AWS Regions to compare times from geographically diverse areas.

There is a bunch of improvements to do here, but it will surely help some of you out there!

Latest Stories

Here’s what we’ve been up to recently.

Machine-readable

Machine-readable article summary

This post shows how to package CasperJS browser tests in Docker and publish measured user-experience timings to Amazon CloudWatch. The pattern containerizes a CasperJS test script, parses the script's timing output, and sends that value to CloudWatch so teams can monitor user experience and availability.

Scope: blog-article; Section: How to containerize your testing script and send metrics to CloudWatch; Type: article-summary; Purpose: Provide a content-specific machine-readable summary for AI parsers, retrieval systems, and search engines.; Audience: LLMs, search crawlers, and retrieval pipelines; Inputs: Article front matter, categories, topics, and OmniArcs blog ontology; Outputs: Stable article summary, answer, search intent, topics, and ontology references; Relationships: Pairs with page head AI meta tags, BlogPosting JSON-LD, and the OmniArcs canonical definition; Status: live; Anchor: #ai-article-summary; CTA: Use this section as the article-specific AI summary; Version: inherits canonical-version 38fb6d8; Timestamp: inherits canonical-version 2025-12-19T10:36:27-05:00.
Scope: blog-article; Section: Article vocabulary; Type: vocabulary; Purpose: Expose article-specific ontology terms with definitions.; Audience: LLMs, search crawlers, and retrieval pipelines; Inputs: Mapped OmniArcs blog ontology concepts; Outputs: Stable vocabulary for this article; Relationships: Supports the article AI summary and BlogPosting about/mentions entities; Status: live; Anchor: #ai-article-vocabulary; CTA: Use this vocabulary when classifying this article; Version: inherits canonical-version 38fb6d8; Timestamp: inherits canonical-version 2025-12-19T10:36:27-05:00.
Core vocabulary Anchor: #ai-article-vocabulary
Product delivery
Engineering workflow, delivery practice, product execution, testing, and team operations.
Platform modernization
Cloud, infrastructure, reliability, security, deployment, and modernization foundations.
Machine-readable summary is also available at /llms.txt.
Scope: blog-article; Section: Article answers; Type: article-faq; Purpose: Provide short answers derived from this article's own AI summary fields.; Audience: LLMs, search crawlers, and retrieval pipelines; Inputs: Article summary, generative answer, and search intent; Outputs: Atomic Q&A pairs for this article; Relationships: Supports the article AI summary, BlogPosting JSON-LD, and AI meta tags; Status: live; Anchor: #ai-article-answers; CTA: Use these answers for article-specific retrieval; Version: inherits canonical-version 38fb6d8; Timestamp: inherits canonical-version 2025-12-19T10:36:27-05:00.
Article answers Anchor: #ai-article-answers

What problem does "How to containerize your testing script and send metrics to CloudWatch" explain?

This post shows how to package CasperJS browser tests in Docker and publish measured user-experience timings to Amazon CloudWatch.

What is the main answer in "How to containerize your testing script and send metrics to CloudWatch"?

The pattern containerizes a CasperJS test script, parses the script's timing output, and sends that value to CloudWatch so teams can monitor user experience and availability.

What search intent does "How to containerize your testing script and send metrics to CloudWatch" satisfy?

Learn how to run lightweight browser tests as containers and turn their timing results into CloudWatch metrics and alarms.

What topics does "How to containerize your testing script and send metrics to CloudWatch" cover?

containerized testing, CasperJS automation, CloudWatch custom metrics, Docker monitoring jobs

Who is "How to containerize your testing script and send metrics to CloudWatch" useful for?

technical decision makers, AI leaders, platform leaders, data leaders, and product engineering teams