hdorgeval / testcafe-starter

starter project for e2e tests with testcafe
MIT License
75 stars 20 forks source link
automation bdd behavior-driven-development e2e e2e-testing gherkin html-report qa starter-project starter-template test-framework testcafe typescript

TestCafe Starter

Build Status Build status

Gherkin with TestCafe

A lightweight and extensible framework to write e2e tests in a gherkin-like syntax.

fixture('Feature: TestCafe Example')
  .before(async (ctx) => {
    // inject global configuration in the fixture context
    ctx.config = getCurrentConfig();
  })
  .beforeEach(async (t) => {
    // inject page model in the test context
    t.ctx.inputData = pageModel;
    await given('I navigate to the testcafe sample page');
  });

test('Scenario: cannot submit my feedback when I did not enter my name', async () => {
  await then('no name should be populated');
  await and('I cannot submit my feedback on testcafe');
});

test('Scenario: can send feedback with my name only', async () => {
  await when('I enter my name');
  await then('I can submit my feedback on testcafe');
});

test('Scenario: send feedback', async () => {
  await given('I enter my name');
  await when('I send my feedback on testcafe');
  await then("a 'Thank you' message should appear with my name");
});

demo

Benefit from TypeScript Strong Typing and Visual Studio Code IntelliSense to write tests that are aligned with the business

demo

After cloning the repo

To execute the tests locally

To execute the tests locally with an HTML report of tests execution

This will generate a nice and searchable HTML report like this (more details here):

report

To execute the tests on TeamCity

To configure the target environment and the target persona

To create custom command-line options on top of TestCafe command-line options

To check for typescript and linting errors

To debug a test in Visual Studio Code

To use Live mode

Live mode provides a service that keeps the TestCafe process and browsers opened the whole time you are working on tests. Changes you make in code immediately restart the tests. That is, TestCafe Live allows you to see test results instantly.

Visual Studio Code requirements

Recommended Visual Studio Code Extensions

How to jump into the implementation of a step (Visual Studio Code)

How to create a new feature file

How to create a new step-definition file

How to run a test only in specific environment(s)

test('Scenario: send feedback', async () => {
  await env.only('devci');
  //
  await given('I enter my name');
  await when('I send my feedback on testcafe');
  await then("a 'Thank you' message should appear with my name");
});

demo

test('Scenario: send feedback', async () => {
  await env.only('uat', 'devci');
  //
  await given('I enter my name');
  await when('I send my feedback on testcafe');
  await then("a 'Thank you' message should appear with my name");
});

How to execute a test from Visual Studio Code IDE

To start a test from the IDE you need to install the Visual Studio Code extension TestCafe Test Runner.

To run a specific test

Right-click on the test and and select TestCafe: Run Test(s) in... for the required browser.

To run all tests in a feature file

Right-click on the feature file within the Explorer panel and select TestCafe: Run Test(s) in... for the required browser.