Mitrahsoft
  • SERVICES
    • OUR SERVICES
      • SOFTWARE DEVELOPMENT
      • MOBILE DEVELOPMENT
      • BLOCKCHAIN DEVELOPMENT
      • SOFTWARE TESTING
      • CLOUD & DEVOPS SERVICES
      • PRODUCT DEVELOPMENT
      • OFFSHORE DEVELOPMENT
      • SOCIAL MEDIA MARKETING
      TECHNOLOGIES
      • COLDFUSION DEVELOPMENT
      • REACTJS DEVELOPMENT
      • VUEJS DEVELOPMENT
      • ANGULAR DEVELOPMENT
      • NODEJS DEVELOPMENT
      • PYTHON DEVELOPMENT
      • GOLANG DEVELOPMENT
      • GOLANG CORPORATE TRAINING
      COLDFUSION EXPERTISE
      • MURACMS EXPERTISE
      • COLDFUSION APP MIGRATION
      • COLDFUSION HOSTING & SUPPORT
      • CF LEGACY APP MAINTENANCE
      • COLDFUSION REST API
      • ECOMMERCE / SHOPPING CART SOLUTIONS
      • PRESIDECMS EXPERTISE
      MOBILE DEVELOPMENT
      • REACT NATIVE DEVELOPMENT
      • FLUTTER DEVELOPMENT
      • IONIC DEVELOPMENT
      • PHONEGAP DEVELOPMENT
  • ABOUT US
    • ABOUT MITRAHSOFT
    • OUR CLIENTS
    • TESTIMONIALS
    • PORTFOLIO
    • CAREERS
  • CONTACT US
  • BLOG
Adobe Solution PartnerLucee Solution Partner
Adobe Solution PartnerLucee Solution Partner
Adobe Solution PartnerLucee Solution Partner
  • OUR SERVICESSOFTWARE DEVELOPMENTMOBILE DEVELOPMENTBLOCKCHAIN DEVELOPMENTSOFTWARE TESTINGCLOUD & DEVOPS SERVICESPRODUCT DEVELOPMENTOFFSHORE DEVELOPMENTSOCIAL MEDIA MARKETING
    TECHNOLOGIESCOLDFUSION DEVELOPMENTREACTJS DEVELOPMENTVUEJS DEVELOPMENTANGULAR DEVELOPMENTNODEJS DEVELOPMENTPYTHON DEVELOPMENTGOLANG DEVELOPMENTGOLANG CORPORATE TRAINING
    COLDFUSION EXPERTISEMURACMS EXPERTISECOLDFUSION APP MIGRATIONCOLDFUSION HOSTING & SUPPORTCF LEGACY APP MAINTENANCECOLDFUSION REST API ECOMMERCE / SHOPPING CART SOLUTIONSPRESIDECMS EXPERTISE
    MOBILE DEVELOPMENTREACT NATIVE DEVELOPMENTFLUTTER DEVELOPMENTIONIC DEVELOPMENTPHONEGAP DEVELOPMENT
  • ABOUT MITRAHSOFTOUR CLIENTSTESTIMONIALSPORTFOLIOCAREERS
  • CONTACT US
  • BLOG

End To End Browser Automation Testing Using NodeJS Testcafe

HomeBlogEnd To End Browser Automation Testing Using NodeJS Testcafe
NodeJS

End To End Browser Automation Testing Using NodeJS Testcafe

M
Post by MitrahsoftPublished: May 21, 2019

A TEST CASE is a set of conditions under which a tester will determine whether a system under test satisfies requirements or works correctly. The process of developing test cases can help find problems in the requirements or design of an application.

In this blog post, we will see how to write testcase in Testcafe to do end to end testing.

TestCafe is a pure node.js end-to-end solution for testing web apps. It takes care of all the stages: starting browsers, running tests, gathering test results and generating reports. TestCafe doesn't need browser plugins - it works in all popular modern browsers out-of-the-box. It allows you to easily write a functional test that inputs text, clicks buttons, and validates the results.
End to End Browser Automation Testing Using Nodejs Testcafe

TestCafe Features

  • TestCafe works on all popular environments Like Windows, MacOS, and Linux. It supports desktop, mobile, remote and cloud browsers(UI or headless).
  • Test cafe setup is very simple and no need of WebDriver or any other testing software. Install TestCafe with one command, and you are ready to test.
  • We can run tests in any browser without much effort (IE9+, Chrome, Firefox and Safari).
  • Learning TestCafe API's is easy compared to Selenium's APIs. It exposes a minimum number of APIs to learn.
  • TestCafe is free and open source framework.
  • TestCafe Studio Cross Platform IDE for End to End web testing

Testcafe Insight

Getting Started with TestCafe
Install dependencies:

Need to install node.js in your system, then you can install packages with the help of npm command.

TestCafe allows you to write tests using TypeScript or JavaScript (with its modern features like async/await).

npm install -g testcafe

Import testcafe selectors:

A selector is a function that identifies a web page element in the test. The selector API provides methods and properties to select elements on the page and get their state.

import { Selector } from 'testcafe';

Declare fixtures:

TestCafe tests must be organized into categories called fixtures. A JavaScript or TypeScript with TestCafe tests can contain one or more fixtures.

javascript
fixture`workflowBasicTests`
.page`${https://www.testcase.com/testModule}`;

To create a test:

Call the test function and pass the test code inside it. A test controller object t exposes the test API's methods. TestCafe tests are executed on the server side.

javascript
test('Test Case Demo: success', async t => {
  await t
  .click(Selector('#submitButton))
  .expect(Selector('#username').value).eql('')
  .expect(Selector('#password').value).eql('')
  .expect(Selector('#login_panel').find('div').withText('Invalid username or password').exists).eql(true);
});

Running the Test:

TestCafe will chosen the open browser (Chrome) to test by Default and also we can mention the browser to test the test case.

bash
testcafe chrome fileName.js
testcafe edge fileName.js
testcafe firefox fileName.js

Fixture Hooks:

Fixture hooks are executed before the first test in a fixture is started and after the last test is finished.

javascript
fixture`beforeHook`
  .before(async t => {
})

fixture`afterHook`
  .after(async t => {
})

Test Hooks:

Test hooks are executed in each test run before a test is started and after it is finished. If a test runs in several browsers, test hooks are executed in each browser.

javascript
test
.before( async t => {
  /* test initialization code */
})

('Test', async t => { /* ... */ })

.after( async t => {
  /* test finalization code */
});

Assertions:

Fixture hooks are executed before the first test in a fixture is started and after the last test is finished.

The following assertion methods are available in TestCafe:
Deep Equal, Not Deep Equal, Ok, Not Ok, Contains, Not Contains, Type of, Not Type of, Greater than, Greater than or Equal to, Less than, Less than or Equal to, Within, Not Within, Match, Not Match.

javascript
await t
.expect(Selector('td').withText('Value').exists).eql(true);
await t
.expect(Selector('span').withText('Main').innerText).contains("Main");

Testcafe

Simple Test case for Login

In these we are going to see how to write the test for the login with validation using TestCafe. It describes with the step-by-step process and code implementation.

For that we have to do certain process in the TestCafe Studio, steps are given below,

TestCafe Studio Initial Process:

  1. Create a new fixture for the testing application in the TestCafe Studio, With the fixture name and testing site url.
  2. After creating the fixture successfully, we need to record a new test for our created fixture.
  3. TestCafe is connected to our site url which we previously given while creating the fixture.
  4. Now the TestCafe is ready to test our application in the browser.
  5. It provides a set of Browser to record our testing application like Chrome, Edge, Firefox, IE etc..

Testing the application:

  • Once our site is loaded in the browser via TestCafe studio, we are ready to test our application. In this are going to test the signup and login functionalities.
  • For that we must have a test case to test the application, such as we need to test the functionality in all possible ways.
  • Each and every action will be recorded in TestCafe Studio whatever we did in the dom using mouse as well as with the keyboard.
  • In the test case of the functionality that needs the action and its response, then only the user know the expected output for the particular action.

    • For that TestCafe provides the Assertions option to find the expected elements in the DOM

  • TestCafe test our application based on the id or class css selector but it must be unique one. So, the testing case can find the DOM property.
  • Once we are done with recording the test case of our application, the tool is ready to generate the code format of our testing application.

    • It is easy to generate the JS code by simply right click of the created fixture.
    • There is an option like converted to JavaScript code, By selecting this we can generate the JS code of our tested application.

As we have previously seen that how to run our code in editor using testcafe package, Now we are going to run our tested application. The entire code for the login test case which is generated by the TestCafe is given below,

javascript
import { Selector } from 'testcafe';

    fixture`BlogTest`
    .page`https://www.surveymonkey.com/user/sign-up/`;

    test('Login Test case', async t => {
      await t
      .click(Selector('a').withText('LOG IN').nth(0))
      .click(Selector('button').withText('LOG IN'))
      await t
      .expect(Selector('##sign_in_form').find('.missing').textContent).eql("Please enter a username.")
      .typeText(Selector('##username'), 'test')
      .typeText(Selector('##password'), 'test')
      .click(Selector('button').withText('LOG IN'))
      await t
      .expect(Selector('##sign-in').find('.error-message').innerText).eql("The username or password you entered is incorrect. Please try again--and remember that passwords are case sensitive.")
      .click(Selector('##username'))
      .pressKey('ctrl+a')
      .pressKey('delete')
      .typeText(Selector('##username'), 'TestAccount_01')
      .typeText(Selector('##password'), 'testtest')
      .click(Selector('button').withText('LOG IN'))
      await t
      .expect(Selector('##userAcctTab_MainMenu').innerText).eql("TestAccount_01")
      .click(Selector('##userAcctTab_MainMenu'))
      .click(Selector('a').withText('Sign Out').nth(0))
      await t
      .expect(Selector('##hd').find('a').withText('LOG IN').innerText).eql("LOG IN");
    });

Following command is used to run the above code, it runs our test case application which is recorded using TestCafe Studio.

bash
testcafe chrome BlogTestcaseLogin.js

 

Tags

ADYENAMAZON-SESANDROIDAPACHEAPACHE-JMETERAWSBARCODE-SCANNERCOLDBOXCOLDFUSIONCOLDFUSION-API-INTEGRATIONCOLDFUSIONBUILDERECHARTSEVENT-GATEWAYFFMPEGFW1JQUERYJSOUPLUCEEMURACMSMURACMS-THEMENODEJSONESIGNALOSSPAYFLOW-PROPAYMENT-GATEWAYPAYPALPRESIDECMSPUPPETEERRAILORAZUNAREACTJSREACTNATIVERESTSASS-COMPILATIONSEMANTIC-UISUBLIMETEXTTINYMCETWILIOYUI-LIBRARY

Archives

JAN 20DEC 19AUG 19JUL 19JUN 19MAY 19APR 19MAR 19FEB 19JAN 19DEC 18NOV 18OCT 18MAR 16NOV 15SEP 15MAY 15MAY 14OCT 13JUN 13MAY 13APR 13MAR 13FEB 13JAN 13

Follow us

Mitrahsoft
United StatesUnited States

Hurst, Texas, United States

+1 (817) 606-8684usa-sales@mitrahsoft.com

IndiaIndia

Head Office

126G2/5, Thiru malai nagaram,
Kovilpatti - 628 501

Madurai

1/B, 2nd & 3rd floor, GV Complex,

Bye Pass Road, SS Colony,

Madurai - 625 016

Coimbatore

2nd Floor, Sri Narmadha Towers,

Murugan Nagar Rd, Thoppampatti Pirivu,

 K. Vadamadurai, Coimbatore - 641 017

+91 9092480924

business@mitrahsoft.com

ColdFusion
  • eCommerce / Shopping Cart Solutions
  • Payment Gateway Integrations
  • Shipping API Integrations
  • ColdFusion Development Services
  • REST API Development
  • MuraCMS Plugin Creation & Personalization
Technology Services
  • ReactJS Development
  • VueJS Development
  • AngularJS Development
  • NodeJS API Development
  • Python Development
  • Golang Development
  • React Native Development
  • D3.JS data Visualization
Other Services
  • Software Development
  • Mobile Development
  • Blockchain Development
  • Cloud & Devops Services

Connect with MitrahSoft

Please fill out this field
Please fill out this field
Please fill out this field
Please fill out this field
Please fill out this field
Please fill out this field

© 2026 All Rights Reserved. MitrahSoft Solutions Pvt Ltd

Home|About Us|Careers