Better Programming

Advice for programmers.

Follow publication

You're unable to read via this Friend Link since it's expired. Learn more

Member-only story

Set Up Scheduled Tests With TestCafe, Gitlab CI, and Alerts on Slack

Angad Singh
Better Programming
Published in
6 min readMay 11, 2020

Photo by Scott Webb on Unsplash

We have a lot of ground to cover in this tutorial so let’s get straight to it!

Objective

To have a front end test for our website that’s run every hour and alerts us of any failure on Slack.

Creating the React App

Create a new React project withnpx create-react-app periodic-testing.

I made a small adjustment to App.js — it looks like this now:

Writing a Test

To add a test to our application, let’s use TestCafe, an end-to-end testing tool. Since we only need this library for testing, we can add it as a dev-dependency with npm i -D testcafe.

Here’s what our basic test looks like:

To execute the test we need to tell TestCafe which test to run and on which browser. To have a shortcut for this setting, let’s add another script to the package.json like this:

"smoke-test": "testcafe 'chrome' tests/smokeTest.js"

If now we run our application npm run start then run the test npm run smoke-test, we can see that TestCafe opens a new chrome window and tries to press a button that has text “Learn React.” If we make a typo and change the Selector in smokeTest.js to look for Learn Rxact and re-run npm run smoke-test, the test fails.

Let’s keep the test in a failing state so we can figure out how to deal with the fail scenario and start adding a bit more logic to our test. Also, I want to use the same file for tests on two browsers, so, to let the test process know which browser we are on, I’ll edit the…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Angad Singh
Angad Singh

Written by Angad Singh

Talking about money, tech and how to make money from tech. https://captainkong.io

No responses yet

Write a response