0.11.9 • Published 3 months ago

@autometa/cucumber-runner v0.11.9

Weekly downloads
-
License
ISC
Repository
github
Last release
3 months ago

Introduction

Autometa Cucumber Runner is a wrapper for multiple established test runners like jest and vitest that enables support for testing .feature files.

Full Documentation

Features

  • Utilize you or your teams favorite testing framework with Cucumber
  • Steps are defined globally and scenarios are self assembling
  • Steps can be overridden for specific features or scenarios with edge behavior
  • Per-Scenario dependency injection of tester-defined classes.
  • Cucumber expressions
  • Extensive handling of data tables
  • CommonJs and ESM compatible

Install

npm add -D @autometa/cucumber-runner
yarn add -D @autometa/cucumber-runner
pnpm add -D @autometa/cucumber-runner

Quick Start

Configure

To begin, add *.feature.ts as a test file pattern to your test library config if needed. Also, add autometa.config.ts to the setup files option

import { defineConfig } from 'vitest/config'

defineConfig({
  ...
  setupFiles: ['autometa.config.ts']
  include: ['**/*.{test,spec,feature}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}']
  ...
})
export default {
  ...
  setupFilesAfterEnv: ['autometa.config.ts']
  testMatch: ['**/?(*.)+(spec|test|feature).[jt]s?(x)']
  ...
}

Next, create the autometa.config.ts. To use globally available step files, add a globals option, and provide the test functions of your test framework. It's also a good idea to import reflect-metadata from this file. reflect-metadata is a required dependency of this library.

import "reflect-metadata";
import { defineConfig } from "@autometa/cucumber-runner";
import { describe, test, beforeEach, beforeAll, afterEach, afterAll } from "vitest";

defineConfig({
  globals: "globals",
  runner: {
    name: "vitest",
    describe,
    test,
    beforeEach,
    beforeAll,
    afterEach,
    afterAll,
  },
});
import "reflect-metadata";
import { defineConfig } from "@autometa/cucumber-runner";

defineConfig({
  globals: "globals",
  runner: {
    name: "jest",
    describe,
    test,
    beforeEach,
    beforeAll,
    afterEach,
    afterAll,
  },
});

Use

Feature: A User Can Log In
  Background: Set up a new User
    Given a new registered User
      | username | name | age | password |
      | johnny5  | John | 45  | paS5091! |

  Scenario: A User logs in with valid credentials
    When they log in
     | username | password |
     | johnny5  | paS5091! |
    Then they see their profile

  Scenario: A User logs in with a bad password
      When they log in
     | username | password |
     | johnny5  | oops     |
    Then they are informed their password is incorrect
import { Given, When, Then, Feature, Before, Scenario } from "@autometa/cucumber-runner";
import { App } from "../src/app";

Before("Launch browser", async ({ world, myDriver }) => {
  world.page = await myDriver.start(process.env.API_URL);
});

Given("a new registered User", async (data: HTable, { world, httpClient }: App) => {
  const userDetails = data.json(0);
  await httpClient.createUser(userDetails);
});

When("they log in", async (userDetails: HTable, { world: { page } }: App) => {
  const { username, password } = userDetails.json(0);
  await page.logUserIn(username, password);
});

Then("they see their profile", async ({ world: { page } }: App) => {
  await page.verifyProfileOpen();
});

Then(
  "they are informed their {word} is incorrect",
  async (field: string, { world: { page } }: App) => {
    await page.verifyBadLoginField(field);
  }
);

Feature("../features/my-feature.feature");

// override Steps

Feature(() => {
  Given("a new registered User", async (data: HTable, { world: { page } }: App) => {
    const userDetails = data.json(0);
    await page.gotoRegistration();
    await page.registerWith(userDetails);
  });

  Scenario("A User logs in with a bad password", () => {
    Then("they are informed their password is incorrect", async ({ world: { page } }: App) => {
      await page.verifyBadPassword();
    });
  });
}, "../features/my-feature.feature");

// load multiple feature files

Feature("../features/my-feature.feature", "../features/my-other-feature.feature");
0.11.9

3 months ago

0.11.8

3 months ago

0.11.7

3 months ago

0.11.0

3 months ago

0.11.1

3 months ago

0.11.2

3 months ago

0.11.3

3 months ago

0.11.4

3 months ago

0.11.5

3 months ago

0.11.6

3 months ago

0.10.5

4 months ago

0.10.4

6 months ago

0.10.3

6 months ago

0.7.10

8 months ago

0.7.9

9 months ago

0.9.4

7 months ago

0.7.6

10 months ago

0.9.3

7 months ago

0.7.5

10 months ago

0.7.8

9 months ago

0.9.5

7 months ago

0.7.7

9 months ago

0.10.1

7 months ago

0.10.2

6 months ago

0.10.0

7 months ago

0.9.0

7 months ago

0.8.0

8 months ago

0.9.2

7 months ago

0.7.4

10 months ago

0.9.1

7 months ago

0.7.2

11 months ago

0.7.1

11 months ago

0.7.3

10 months ago

0.7.0

11 months ago

0.6.0

11 months ago

0.5.4

12 months ago

0.5.3

12 months ago

0.5.6

11 months ago

0.5.5

12 months ago

0.5.2

12 months ago

0.3.11

1 year ago

0.3.10

1 year ago

0.5.1

1 year ago

0.3.8

1 year ago

0.3.7

1 year ago

0.3.6

1 year ago

0.3.5

1 year ago

0.3.4

1 year ago

0.3.3

1 year ago

0.3.2

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago

0.2.0

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago