Testcafe is a Node Js library that is used to perform web automation. it is open source and compatible with various platforms like Windows, Mac, Linux. and support various browsers like Chrome, Firefox, Opera, etc. Read More about What is TestCafe.

In this article, we are going to perform the real-time practical example in TestCafe to start automation with Testcafe. Before, start the automation with testcafe we need some compulsory working environment in your development machine.

Pre-Requirements for Testcafe working environments

Start Automation with TestCafe

Step 1) Create a simple folder “Testcafe tutorial” into your drive.

Step 2) Open the terminal in your VsCode editor.

Simple run the VsCode and open the work folder “Testcafe tutorial” into vs code

Step 3) Install all the required NodeJs libraries.

Open the terminal and enter the below commands to install testcafe.

npm install -g testcafe

Write a simple Test script into TestCafe

In this simple testcafe example, we are going to open the browser and load the URL.

Create a file “test.js” and enter the below code

import { Selector } from 'testcafe';

fixture `Getting Started`
    .page `https://www.seleniumeasy.com/test/`;

test('My First Testcage Automation Script', async t => {

import { Selector } from ‘testcafe’;  is used to import the testcafe library.

fixture:  is used to divide testcases into categories. A fixture and contains multiple testcases of the same categories.

test: is used to write the actual test script.

Run testcafe Testcase

Again open the terminal and enter the below commands.

testcafe chrome File_Name.js

If you are running testcafe the first time you might face some errors related to access, let’s see how to solve them.

testcafe.ps1 cannot be loaded because running scripts is disabled on this system.

To solve this error just enter the below command

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted

Now again enter the same command testcafe chrome File_Name.js and run the project.