Write First Automation Script using TestCafe

In this, Testcafe Automation Automation tutorial, We will understand, How to Write  First Automation Script using Testcafe.

Pre Requirements

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 First Automation Script using TestCafe

Before starting the testcase writing in testcafe, let’s understand some important keywords and functions of Testcafe. Like fixture, test

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

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.

.page:  is used to navigate on the URL or page.

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

When you use testcafe first time, might be you will get the console error “testcafe.ps1 cannot be loaded because running scripts is disabled on this system”, To solve this error  just enter the below command to enable the script.

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted

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