After, TableDefinition } from 'cucumber'; import { expect, use } from 'chai'; import chaiJestSnapshot from 'chai-jest-snapshot'; import chaiFs from 'chai-fs'; import chaiString from 'chai-string'; import { Question } from './world'; use(chaiString); use(chaiFs); use(chaiJestSnapshot); BeforeAll(function() { chaiJestSnapshot.resetSnapshotRegistry(); }); After(function() { if (this.spawned && !this.output.closed) { this.spawned.kill(); } }); Before(function(testCase) { const { name } = testCase.pickle; this.snapshot.testname = name; this.snapshot.filename = `features/__snaps__/${name .toLowerCase() .replace(/\s/g, '-')}.snap`;
function StepSampleWithoutDefineSupportCode() { setWorldConstructor(function({attach, parameters}) { this.attach = attach; this.parameters = parameters; this.visit = (url: string, callback: Callback) => { callback(null, 'pending'); }; this.toInt = parseInt; }); Before((scenarioResult: HookScenarioResult, callback: Callback) => { console.log(scenarioResult.result.status === Status.FAILED); callback(); }); Before({ timeout: 1000 }, (scenarioResult: HookScenarioResult, callback: Callback) => { console.log(scenarioResult.result.status === Status.FAILED); callback(); }); Before('@tag', (scenarioResult: HookScenarioResult, callback: Callback) => { console.log(scenarioResult.result.status === Status.FAILED); callback(); }); BeforeAll((callback: Callback) => { console.log("Before all"); callback(); }); BeforeAll({ timeout: 1000 }, (callback: Callback) => { console.log("Before all"); callback(); }); BeforeAll('@tag', (callback: Callback) => { console.log("Before all"); callback(); }); After((scenarioResult: HookScenarioResult, callback: Callback) => { console.log("After"); callback(); }); After({ timeout: 1000 }, (scenarioResult: HookScenarioResult, callback: Callback) => { console.log("After"); callback(); }); After('@tag', (scenarioResult: HookScenarioResult, callback: Callback) => { console.log("After"); callback(); }); AfterAll((callback: Callback) => { console.log("After all"); callback(); }); AfterAll({ timeout: 1000 }, (callback: Callback) => { console.log("After all"); callback(); }); AfterAll('@tag', (callback: Callback) => { console.log("After all"); callback(); }); Given(/^a variable set to (\d+)$/, (x: string) => { console.log("the number is: " + x); }); Given(/^a variable set to (\d+)$/, (x: number) => { console.log(typeof x); }); Given(/^I am on the Cucumber.js GitHub repository$/, function(callback: Callback) { this.visit('https://github.com/cucumber/cucumber-js', callback); }); When(/^I go to the README file$/, (title: string, callback: Callback) => { callback(null, 'pending'); }); Then(/^I should see "(.*)" as the page title$/, {timeout: 60 * 1000}, function(title: string, callback: Callback) { const pageTitle = this.browser.text('title'); if (title === pageTitle) { callback(); } else { callback(new Error("Expected to be on page with title " + title)); } }); // Type for data_table.js on // https://github.com/cucumber/cucumber-js/blob/a5fd8251918c278ab2e389226d165cedb44df14a/lib/cucumber/ast/data_table.js Given(/^a table step with Table raw$/, (table: Table) => { const expected = [ ['Cucumber', 'Cucumis sativus'], ['Burr Gherkin', 'Cucumis anguria'] ]; const actual: string[][] = table.raw(); assert.deepEqual(actual, expected); }); Given(/^a table step with Table rows$/, (table: Table) => { const expected = [ ['Apricot', '5'], ['Brocolli', '2'], ['Cucumber', '10'] ]; const actual: string[][] = table.rows(); assert.deepEqual(actual, expected); }); Given(/^a table step with Table rowHash$/, (table: Table) => { const expected = { Cucumber: 'Cucumis sativus', 'Burr Gherkin': 'Cucumis anguria' }; const actual: { [firstCol: string]: string } = table.rowsHash(); assert.deepEqual(actual, expected); }); Given(/^a table step$/, (table: Table) => { const expected = [ {Vegetable: 'Apricot', Rating: '5'}, {Vegetable: 'Brocolli', Rating: '2'}, {Vegetable: 'Cucumber', Rating: '10'} ]; const actual: Array<{ [colName: string]: string }> = table.hashes(); assert.deepEqual(actual, expected); }); defineParameterType({ regexp: /particular/, transformer: s => s.toUpperCase(), typeName: 'param' // deprecated but still supported }); defineParameterType({ regexp: /particularly/, transformer: s => s.toUpperCase(), name: 'param', preferForRegexpMatch: false, useForSnippets: false }); defineParameterType({ regexp: /(one) (two)/, transformer: (x, y) => x + y, name: 'param', preferForRegexpMatch: false, useForSnippets: false }); defineParameterType({ regexp: /123/, transformer(val) { return this.toInt(val); }, name: 'param', preferForRegexpMatch: false, useForSnippets: false }); Given('a {param} step', param => { assert.equal(param, 'PARTICULAR'); }); }
const { BeforeAll, After, Status } = require("cucumber"); import * as fs from "fs"; import { browser } from "protractor"; import { config } from "../config/config"; BeforeAll({timeout: 10 * 1000}, async () => { await browser.get(config.baseUrl); }); After(async function(scenario) { if (scenario.result.status === Status.FAILED) { // screenShot is a base-64 encoded PNG const screenShot = await browser.takeScreenshot(); this.attach(screenShot, "image/png"); } });