How to run one or multiple testcases from test file in Testcafe

In this, Testcafe tutorial, Let’s create an testcafe automation example, where we have multiple testcases in a testfile and we have to run only one testcase form the file or run multiple (more than one but not all testcase). To achieve this example let’s create a simple end to end automation test file in Testcafe. before that check out the required development environment for testcase.  

Run single testcase from test file in Testcafe

test.only is used to select the teastcase that should be run on priority. In the below example let’s Create a testfile (test.js) that contains 4 Testcases to perform mathematical operations. Now suppose we need to run only one testcases out of these 4. So we added .only after test.

import { Selector } from 'testcafe';

fixture `Getting Started` 
//.page `https://codebun.com/`

 test('Add Two Numbers', async t => {
      console.log(2+2)

  });

test.only('Mul Two Numbers', async t => {
    console.log(2*2)

});

test('Sub Two Numbers', async t => {
    console.log(2-2)

});

test('Div Two Numbers', async t => {
    console.log(2/2)

});

Run Multiple testcase from test file in Testcafe

In the below example let’s use the same file (test.js) that contains 4 Testcases to perform mathematical operations. Now we will run 2 testcases out of these 4. So we added .only after test.

import { Selector } from 'testcafe';

fixture `Getting Started` 
//.page `https://codebun.com/`

 test('Add Two Numbers', async t => {
      console.log(2+2)
  });

test.only('Mul Two Numbers', async t => {
    console.log(2*2)
});

test.only('Sub Two Numbers', async t => {
    console.log(2-2)
});

test('Div Two Numbers', async t => {
    console.log(2/2)
});