How to use cucumber-expressions - 10 common examples

To help you get started, we’ve selected a few cucumber-expressions examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sitegeist / gherkin-testcafe / src / resolveStepDefinition.js View on Github external
const glob = require('glob');
const path = require('path');
const {CucumberExpression, ParameterTypeRegistry} = require('cucumber-expressions');

const {steps} = require('./args').argv;
const stepDefinitionsPaths = [].concat(...steps.map(pattern => glob.sync(pattern)));
const parameterTypeRegistry = new ParameterTypeRegistry();

//
// A global registry to load load and resolve all step definitions
//
class StepDefinitionRegistry {
	constructor() {
		this.definitions = {};
		this.runtime = {};
		this.latestType = '';

		['given', 'when', 'then'].forEach(keyword => {
			this.definitions[keyword] = [];
			this.runtime[keyword] = (expression, implementation) => this.definitions[keyword].push({
				implementation,
				expression: new CucumberExpression(expression, parameterTypeRegistry)
			});
github sitegeist / gherkin-testcafe / src / resolveStepDefinition.js View on Github external
this.runtime[keyword] = (expression, implementation) => this.definitions[keyword].push({
				implementation,
				expression: new CucumberExpression(expression, parameterTypeRegistry)
			});
		})
github Codeception / CodeceptJS / lib / interfaces / bdd.js View on Github external
let steps = {};

const STACK_POSITION = 2;

/**
 * @param {*} step
 * @param {*} fn
 */
const addStep = (step, fn) => {
  const stack = (new Error()).stack;
  steps[step] = fn;
  fn.line = stack && stack.split('\n')[STACK_POSITION];
  if (fn.line) fn.line = fn.line.trim().replace(/^at (.*?)\(/, '(');
};

const parameterTypeRegistry = new ParameterTypeRegistry();

const matchStep = (step) => {
  for (const stepName in steps) {
    if (stepName.indexOf('/') === 0) {
      const res = step.match(new RegExp(stepName.slice(1, -1)));
      if (res) {
        const fn = steps[stepName];
        fn.params = res.slice(1);
        return fn;
      }
      continue;
    }
    const expression = new CucumberExpression(stepName, parameterTypeRegistry);
    const res = expression.match(step);
    if (res) {
      const fn = steps[stepName];
github cucumber / cucumber / fake-cucumber / javascript / src / DefaultStepDefinitions.ts View on Github external
export default function defaultStepDefinitionRegistry(): StepDefinitionRegistry {
  return new StepDefinitionRegistry([
    new StepDefinition(
      new CucumberExpression('a passed {word}', new ParameterTypeRegistry()),
      () => undefined
    ),
    new StepDefinition(
      new CucumberExpression('a failed {word}', new ParameterTypeRegistry()),
      () => {
        throw new Error('Nope')
      }
    ),
    new StepDefinition(
      new CucumberExpression('a pending {word}', new ParameterTypeRegistry()),
      () => 'pending'
    ),
    new StepDefinition(
      new CucumberExpression(
        'an ambiguous {word}',
        new ParameterTypeRegistry()
      ),
      () => undefined
    ),
    new StepDefinition(
github cucumber / cucumber / fake-cucumber / javascript / src / DefaultStepDefinitions.ts View on Github external
export default function defaultStepDefinitionRegistry(): StepDefinitionRegistry {
  return new StepDefinitionRegistry([
    new StepDefinition(
      new CucumberExpression('a passed {word}', new ParameterTypeRegistry()),
      () => undefined
    ),
    new StepDefinition(
      new CucumberExpression('a failed {word}', new ParameterTypeRegistry()),
      () => {
        throw new Error('Nope')
      }
    ),
    new StepDefinition(
      new CucumberExpression('a pending {word}', new ParameterTypeRegistry()),
      () => 'pending'
    ),
    new StepDefinition(
      new CucumberExpression(
        'an ambiguous {word}',
        new ParameterTypeRegistry()
github cucumber / cucumber-js / src / support_code_library_builder / index.ts View on Github external
({ code, line, options, pattern, uri }) => {
        const expression =
          typeof pattern === 'string'
            ? new CucumberExpression(pattern, this.parameterTypeRegistry)
            : new RegularExpression(pattern, this.parameterTypeRegistry)
        const wrappedCode = this.wrapCode({
          code,
          wrapperOptions: options.wrapperOptions,
        })
        return new StepDefinition({
          code: wrappedCode,
          expression,
          id: this.newId(),
          line,
          options,
          pattern,
          unwrappedCode: code,
          uri,
        })
      }
github TheBrainFamily / cypress-cucumber-preprocessor / lib / resolveStepDefinition.js View on Github external
this.runtime = (matcher, implementation) => {
      let expression;
      if (matcher instanceof RegExp) {
        expression = new RegularExpression(
          matcher,
          this.options.parameterTypeRegistry
        );
      } else {
        expression = new CucumberExpression(
          matcher,
          this.options.parameterTypeRegistry
        );
      }

      this.definitions.push({
        implementation,
        expression,
        featureName: window.currentFeatureName || "___GLOBAL_EXECUTION___"
      });
    };
github cucumber / cucumber / fake-cucumber / javascript / src / DefaultStepDefinitions.ts View on Github external
export default function defaultStepDefinitionRegistry(): StepDefinitionRegistry {
  return new StepDefinitionRegistry([
    new StepDefinition(
      new CucumberExpression('a passed {word}', new ParameterTypeRegistry()),
      () => undefined
    ),
    new StepDefinition(
      new CucumberExpression('a failed {word}', new ParameterTypeRegistry()),
      () => {
        throw new Error('Nope')
      }
    ),
    new StepDefinition(
      new CucumberExpression('a pending {word}', new ParameterTypeRegistry()),
      () => 'pending'
    ),
    new StepDefinition(
      new CucumberExpression(
        'an ambiguous {word}',
        new ParameterTypeRegistry()
      ),
      () => undefined
    ),
    new StepDefinition(
      new CucumberExpression('an {word} step', new ParameterTypeRegistry()),
      () => undefined
    ),
    new StepDefinition(
      new CucumberExpression(
        'I have {int} cukes in my belly',
github cucumber / cucumber / fake-cucumber / javascript / src / DefaultStepDefinitions.ts View on Github external
new CucumberExpression('a pending {word}', new ParameterTypeRegistry()),
      () => 'pending'
    ),
    new StepDefinition(
      new CucumberExpression(
        'an ambiguous {word}',
        new ParameterTypeRegistry()
      ),
      () => undefined
    ),
    new StepDefinition(
      new CucumberExpression('an {word} step', new ParameterTypeRegistry()),
      () => undefined
    ),
    new StepDefinition(
      new CucumberExpression(
        'I have {int} cukes in my belly',
        new ParameterTypeRegistry()
      ),
      cukes => cukes
    ),
  ])
}
github Codeception / CodeceptJS / lib / interfaces / bdd.js View on Github external
const matchStep = (step) => {
  for (const stepName in steps) {
    if (stepName.indexOf('/') === 0) {
      const res = step.match(new RegExp(stepName.slice(1, -1)));
      if (res) {
        const fn = steps[stepName];
        fn.params = res.slice(1);
        return fn;
      }
      continue;
    }
    const expression = new CucumberExpression(stepName, parameterTypeRegistry);
    const res = expression.match(step);
    if (res) {
      const fn = steps[stepName];
      fn.params = res.map(arg => arg.getValue());
      return fn;
    }
  }
  throw new Error(`No steps matching "${step.toString()}"`);
};