Book Image

Modern Web Testing with TestCafe

By : Dmytro Shpakovskyi
Book Image

Modern Web Testing with TestCafe

By: Dmytro Shpakovskyi

Overview of this book

TestCafe is an open source end-to-end testing framework that combines unmatched ease of use with advanced automation and robust built-in stability mechanisms. This book is a comprehensive, project-based introduction to TestCafe that will show you how to use the TestCafe framework and enable you to write fast and reliable tests; plus you’ll have a proof of concept ready to demonstrate the practical potential of TestCafe. You’ll begin by learning how to write end-to-end web tests using the TestCafe syntax and features of the TestCafe framework. You’ll then go from setting up the environment all the way through to writing production-ready tests. You’ll also find out how to build a sample set of tests in a step-by-step manner and use TestCafe to log in to the website, verify the elements present on different pages, create/delete entities, and run custom JavaScript code. As you advance, you’ll delve into several stages of refactoring that will take you through the showcase setup/teardown and PageObject patterns. While this test suite is relatively simple to build, it showcases some of the most prominent features of TestCafe. Finally, this TestCafe book will show you how the tests can be run on a free and simple-to-use website, without requiring you to build and deploy your own servers or backend services. By the end of this book, you’ll have learned how to write and enhance end-to-end tests with TestCafe to solve real-world problems and deliver results.
Table of Contents (9 chapters)

Creating a test

TestCafe supports tests written using JavaScript, TypeScript, or CoffeeScript with all modern features, such as arrow functions and async/await. In addition to that, TestCafe will automatically transpile TypeScript and CoffeeScript code before running tests, so you do not need to tackle it on your own.

As we agreed initially, throughout this book we will be using JavaScript to write the tests.

In continuation of our previous efforts from Chapter 3, Setting Up the Environment, we already have test-project folder with the .testcaferc.json configuration file in it. So, let's start by opening any shell (for example, we will use Terminal with bash) and following the next steps:

  1. Go to test-project folder and create a folder for our tests:
    $ cd test-project/
    $ mkdir tests
  2. Now go to that folder and create a basic-tests.js file:
    $ cd tests/
    $ touch basic-tests.js
  3. Open basic-tests.js in a code editor (or IDE) of your choice and let's create a simple...