Sunday, September 20, 2020

TestCafe Setup

Getting Started


Make sure Node.js (version 6 or newer) and npm are installed on your computer.

Please refer this url for Node.js installer https://nodejs.org/en/download/ 

Check the Node and npm version in the terminal

Install the testcafe using npm

npm install -g testcafe

Creating the sample test

For sample test we are going to test https://devexpress.github.io/testcafe/example page.

Create a sample.js file.The file must have a special structure.

Tests must be organized into fixtures.

Copy paste the following code to see the test in action.

import { Selector } from 'testcafe'; // import testcafe selectors

fixture `Getting Started`// declare the fixture
    .page `https://devexpress.github.io/testcafe/example`;  // specify the start page


// Create a test and place your code there
test('My first test', async t => {
    await t
        .typeText('#developer-name', 'Saranraj')
        .click('#submit-button')

        // Use the assertion to check if the actual header text is equal to the expected one
        .expect(Selector('#article-header').innerText).eql('Thank you, Saranraj!');
});

Running the Test

Execute the following command in a terminal.

Specify the target browser and the test script path.

testcafe chrome sample.js

TestCafe automatically opens the chosen browser and starts test execution within it.

Viewing the Results

TestCafe outputs the results into a command shell by default.







1 comment:

TestCafe Setup

Getting Started Make sure Node.js (version 6 or newer) and npm are installed on your computer. Please refer this url for Node.js installer h...