GithubHelp home page GithubHelp logo

badeball / cypress-cucumber-preprocessor Goto Github PK

View Code? Open in Web Editor NEW

This project forked from klaveness-digital/cypress-cucumber-preprocessor

1.3K 43.0 143.0 2.35 MB

Run cucumber/gherkin-syntaxed specs with Cypress

License: MIT License

Gherkin 41.53% TypeScript 58.08% JavaScript 0.38%

cypress-cucumber-preprocessor's Introduction

cypress-cucumber-preprocessor

Build status Npm package weekly downloads

This preprocessor aims to provide a developer experience and behavior similar to that of Cucumber, to Cypress.

ℹ️ The repositor has recently moved from github.com/TheBrainFamily to github.com/badeball. Read more about the transfer of ownership here.

Installation

$ npm install @badeball/cypress-cucumber-preprocessor

Introduction

The preprocessor (with its dependencies) parses Gherkin documents and allows you to write tests as shown below.

# cypress/e2e/duckduckgo.feature
Feature: duckduckgo.com
  Scenario: visiting the frontpage
    When I visit duckduckgo.com
    Then I should see a search bar
// cypress/e2e/duckduckgo.ts
import { When, Then } from "@badeball/cypress-cucumber-preprocessor";

When("I visit duckduckgo.com", () => {
  cy.visit("https://www.duckduckgo.com");
});

Then("I should see a search bar", () => {
  cy.get("input").should(
    "have.attr",
    "placeholder",
    "Search the web without being tracked"
  );
});

Building

Building can be done once using:

$ npm run build

Or upon file changes with:

$ npm run watch

There are multiple types of tests, all ran using npm scripts:

$ npm run test:fmt
$ npm run test:types
$ npm run test:unit
$ npm run test:integration # make sure to build first
$ npm run test # runs all of the above

Attribution

A special thanks goes out to Łukasz Gandecki for developing and maintaning the cypress-cucumber integration before me, in addition to all other contributors. Some of the work has partially been sponsored by Klaveness Digital.

cypress-cucumber-preprocessor's People

Contributors

aloneh avatar arichard-info avatar asashour avatar badeball avatar bauglir avatar bn-jcundill avatar dependabot-preview[bot] avatar fcurella avatar fryuni avatar gpincheiraa avatar holgergp avatar jcundill avatar jprealini avatar kayvanbree avatar laistomazz avatar lgandecki avatar liamchilds avatar lukebjerring avatar mallison avatar mateusznowosad avatar mrkjdy avatar nilgaar avatar nyanhorse avatar ralphpulselive avatar sawasawasawa avatar sonaryr avatar song-nan17 avatar twilczek avatar vidhirambhia avatar vladonemo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cypress-cucumber-preprocessor's Issues

Error on Linux machines

Hello.

I'm trying to use the library, but it throws an error on my Linux machine (Ubuntu 16.04). On Mac works fine.

screenshot

Possible Generate Cucumber JSON Reports Post Test Run Execution

Hi there

I'm currently evaluating the toolset for a project I'm currently working on. I have used cucumber js with protractor before which worked very well for me in the past so hoping to do something similar with this toolset and cucumber js. I must say from starting in December the project has evolved significantly so well done on that 👍 .

I notice though that the project doesn't quiet have feature parity with cucumber js. I list key gaps from an e2e test perspective

  1. support for hooks and tags (however that is almost implemented)
  2. generate a cucumber JSON report after a test run (I don't think this is currently possible or I don't know how to do it)
  3. define step_defintions outside of package.json (#70 maybe I have this wrong...see my comment in that thread)

I focus on item number 2. When I run protractor tests with cucumber js I was able to get a cucumber JSON report (typically I got this as a file). All the cucumber families (for example Cucumber-JVM & CucumberJs)
sample.json.zip

produce the same JSON.

I notice cypress supports a number of reporters formats (https://docs.cypress.io/guides/tooling/reporters.html#) from mocha, junit, etc, however I don't know how to get JSON from a cucumber js run.

The reason why I request JSON from cucumber is I can pass that JSON to this report module on a CI server (namely this module https://github.com/jenkinsci/cucumber-reports-plugin which internally uses this library https://github.com/damianszczepanik/cucumber-reporting).

Having the above but especially item number 2 opens the toolset to a wider QA audience in my opinion. Thoughts? Thanks in advance re any help with the above.

Skip scenarios

Does have any way to skip some scenarios by adding a tag @skip for example or another approach?

Combine cypress-cucumber-preprocessor in combination with TypeScript

Hi there,

I'm trying to combine an angular-cli app with cypress, cypress-cucumber-preprocessor and @bahmutov/add-typescript-to-cypress, but I keep getting the following error:

Error: Step implementation missing for: I open the home page

When I change the extension of my definition files to *.js it suddenly works!
Is there a way to make it work for *.ts files as well? And how do I do that?

This is my feature file -- welcome.feature:

  I want to be welcomed by Angular

  Scenario: Opening the home page and being welcomed
    Given I open the home page
    Then  I see "Welcome to app!" in the header

This is my step definition file -- shared.ts:

given('I open the home page', () => {
  cy.visit('http://localhost:4200');
});

This is my plugin config -- index.js:

const cucumber = require('cypress-cucumber-preprocessor').default

module.exports = on => {
  on('file:preprocessor', cypressTypeScriptPreprocessor)
  on('file:preprocessor', cucumber())
}

This is my cypress folder structure:

- cypress
--   integration
--- cy-ts-preprocessor.js
--- index.js
--  support
--- step_definitions
---- shared.ts

ng -v

   _                      _                 ____ _     ___
   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
               |___/
    
Angular CLI: 1.7.3
Node: 9.3.0
OS: darwin x64
Angular: 5.2.9
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 1.7.3
@angular-devkit/build-optimizer: 0.3.2
@angular-devkit/core: 0.3.2
@angular-devkit/schematics: 0.3.2
@ngtools/json-schema: 1.2.0
@ngtools/webpack: 1.10.2
@schematics/angular: 0.3.2
@schematics/package-update: 0.3.2
typescript: 2.5.3
webpack: 3.11.0

dev dependencies:

    "@bahmutov/add-typescript-to-cypress": "^2.0.0",   
    "cypress": "^2.1.0",
    "cypress-cucumber-preprocessor": "^0.3.0",

running cypress with the following command:
yarn cypress open

Run single fearute

Hi, first nice work!.

My doubt is I want to run a folder inside integration called ProjectName for example, do a command like cypress run --folder ./cypress/integration/ProjectName and will be executed all .feature files. Or something like setup a tag like --tag @ProjectName

The ida is use the same project to several applications to reuse the code.

Thanks!!

bug: step definitions never get's reloaded

When using npx cypress open to write tests, it would be great to have auto-updated step definitions. Now they are loaded only once on start only so I need to re-run cypress every time what is very slow.

Using import and export inside step definitions

I am trying to use import and export inside step definitions but it constantly says that sourceType: "module" is required. I tried using require but then it still gives the same error since the required modules use import and export anyway. Is there a workaround for this? Thank you!

[Discussion] Should scenarios be a single test ?

Hello,

Currently, each step in a scenario becomes a single test in cypress. This is expected and this is the way other cucumber frameworks do it.

However, this goes against cypress recommendations and best bractices because they consider that each test should be independant and able to run alone. This is kind of incompatible with cucumber behavior.

It is not only a "best practice" issue because cypress clears a lot of things between tests : cookies, local storage, session storage, spies, stubs...
This means, for example, I can't set-up a mock in a given step and rely on it in a subsequent when or then.

Possible solutions :

  • Make each scenario produce a single test (and Background would become beforeEach, but this would hurt reporting)
  • somehow preserve state for a scenario (currently, cypress only allows to do it for cookies)

See :

  • cypress-io/cypress#686 (second solution would become possible if they implement this but it doesn't look like it's going to be soon).
  • cypress-io/cypress#461 (allows to keep local storage, but it's hacky and doesn't solve other things being cleared)

What do you think ?

Scenario outlines not pulling variable from examples

In a test scenario I have written, I am trying to pull a variable from the examples table and have it in the test name, however it seems to not parse the variable from the feature file. In my case, I have a field called name that I am trying to use. I have tried it both as <name> and "<name>".

image

image

image

Is this expected behaviour or a bug?

vue-cli 3 and cypress

Hello, im using vue-cli v3 with the cypress plugin and when i start a feature test i got the following error:

Uncaught TypeError: Cannot read property 'prototype' of undefined

This error originated from your test code, not from Cypress.

When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.

Cypress could not associate this error to any specific test.

We dynamically generated a new test to display this failure.

Check your console for the stack trace or click this message to see where it originated from.

 at patch (http://localhost:8080/__cypress/tests?p=tests/e2e/specs/Generic.feature-741:51105:54)
    at Object.<anonymous> (http://localhost:8080/__cypress/tests?p=tests/e2e/specs/Generic.feature-741:50966:18)
    at Object.273../fs.js (http://localhost:8080/__cypress/tests?p=tests/e2e/specs/Generic.feature-741:51203:4)
    at o (http://localhost:8080/__cypress/tests?p=tests/e2e/specs/Generic.feature-741:1:265)
    at http://localhost:8080/__cypress/tests?p=tests/e2e/specs/Generic.feature-741:1:316

This is the plugin configuration from cypress and vue-cli, is not the usual config:

// https://docs.cypress.io/guides/guides/plugins-guide.html
const cucumber = require('cypress-cucumber-preprocessor').default;

module.exports = (on, config) => {
  on('file:preprocessor', cucumber());
  return Object.assign({}, config, {
    fixturesFolder: 'tests/e2e/fixtures',
    integrationFolder: 'tests/e2e/specs',
    screenshotsFolder: 'tests/e2e/screenshots',
    videosFolder: 'tests/e2e/videos',
    supportFile: 'tests/e2e/support/index.js',
    step_definitions: 'tests/e2e/support/step_definitions/',
  })
};

I'm not sure if someone has stumbled with this issue or has an idea of how to implement it in the right way.

Webstorm doesn't recognize step definitions

I don't really know if I should ask this here, but Webstorm doesn't recoginize the step definitions of this plugin because the steps are given, when, then. Webstorm does recognize the official cucumber package's Given, When an Then (capitalized). Webstorm recognizing step definitions is extremely helpful in preventing duplicate step definitions.

// Recognized (like the official cucumber package)
Given(`I am on the webpage`, () => {
  cy.visit(url);
});

// Not recognized (like this plugin)
given('I am on the webpage', () => {
  cy.visit(url);
});

webstormnotrecognizingcypresscucumber

I did find a workaround, but I'd rather not have people forget to include this:

// Just add this above the step definitions
const Given = given;
const When = when;
const Then = then;

Is there a way this could be solved without a workaround?

Showing "Given,When,Then" steps in output of the tests

Hi all,

I started using cypress-cucumber-preprocessor recently and I'm really fond of it!

I have a question when executing the scenario's. I would like to see the actual "Given, When, Then" steps in the main output of the tests. It now shows the scenario titles in the output (also in the terminal) and the steps are somewhat hidden inside the actual step behind a log-command. Is this normal behaviour or am I missing something?

image

Note that I am using the "Given" step in the Background in the example above.

Require doesn't resolve from the expected path.

In a file inside cypress/support/step_definitions I require a file ./bla. When I view the network tab of the devtools I see this error:

(function () {
  Cypress.action("spec:script:error", {
    type: "BUNDLE_ERROR",
    error: "Error: Cannot find module './bla' from '<project-path>/cypress/integration'{newline}"
  })
}())

I expect it to resolve from cypress/support/step_definitions and not cypress/integration

Steps definitions are not executed

I used this project successfully about a onth ago, and today I can't make it work anymore.

Whatever I do, I always get the error Error: Step implementation missing for: I am on the "/" page.

Here is my feature :
tests/e2e/specs/vue-cli-demo.feature

Feature: Vue cli demo

I want to see the demo created by 'vue-cli create' to test cypress with cucumber preprocessor

  Scenario: Visualizing the home page
    Given I am on the "/" page
    Then I see the vue logo

  # Scenario: Navigating to the about page
  #   Given I am on the "/" page
  #   When I click on the "about" link in the menu
  #   Then The current page is "/about"
  #   And The page title is "This is an about page"

And the steps :
tests/e2e/support/step_definitions/common.js

/* global given, when, then */
console.log('Hello')
given('I am on the "/" page', () => {
  cy.visit('/');
})

then('I see the vue logo', () => {
  cy.get('img[src="../assets/logo.png"]')
})

The non-default paths are all correctly configured (I think)

I added a console.log in the compile method of the index.js file of the project which prints the result of the function. I get this :

const {resolveAndRunStepDefinition, given, when, then} = require('cypress-cucumber-preprocessor/resolveStepDefinition');
  const { createTestFromScenario } = require('cypress-cucumber-preprocessor/createTestFromScenario');
  const { createTestsFromFeature } = require('cypress-cucumber-preprocessor/createTestsFromFeature');
  { 
    /* global given, when, then */
console.log('Hello')
given('I am on the "/" page', () => {
  cy.visit('/');
})

then('I see the vue logo', () => {
  cy.get('img[src="../assets/logo.png"]')
}) 
    }
  const {Parser, Compiler} = require('gherkin');
  const spec = `Feature: Vue cli demo

I want to see the demo created by 'vue-cli create' to test cypress with cucumber preprocessor

  Scenario: Visualizing the home page
    Given I am on the "/" page
    Then I see the vue logo

  # Scenario: Navigating to the about page
  #   Given I am on the "/" page
  #   When I click on the "about" link in the menu
  #   Then The current page is "/about"
  #   And The page title is "This is an about page"
`
  const gherkinAst = new Parser().parse(spec);
  
  createTestsFromFeature(gherkinAst);

This makes me believe that the plugin correctly finds my step definitions, but they are never executed (I don't see the console.log("Hello") at the top)

Can you help me figure out what's wrong ?

Error: Cannot find module 'test/cypress/support/step_definitions/shared.js'

I'm getting this error:

Error: Cannot find module 'test/cypress/support/step_definitions/shared.js' from '/Users/ashtoc03/Sites/bbc/news-vj-search-lookup/features'

...on v1.2.2 of cypress-cucumber-preprocessor, when v1.0.0 was working ok (removed package-lock.json and it stopped working).

This is our cypress config:

{
    "fileServerFolder": "test/cypress",
    "fixturesFolder": "test/cypress/fixtures",
    "integrationFolder": "features",
    "supportFile":  "test/cypress/support/index.js",
    "pluginsFile": "test/cypress/plugins/index.js",
    "videosFolder": "test/cypress/videos",
    "screenshotsFolder": "test/cypress/screenshots",
    "video": false
}

And here is our dir structure:

screen shot 2018-07-31 at 16 13 43

Could be that there's been an API change and we're doing something wrong, or it could be that this is a regression... (looks similar to #30)?

Gherkin test steps are logged out of order in latest cypress 3.0.1

For the latest Cypress 3.0.1, is anyone else seeing all the "LOG Gherkin_step_name" bunched up at the end?

Example printout in cypress interactive mode:
Feature name
Cypress actions and assertions
Cypress actions and assertions
....
Cypress actions and assertions
Cypress actions and assertions
LOG gherkin_step_name1
LOG gherkin_step_name2
LOG gherkin_step_name3

Instead of the appropriate:
Feature name
LOG gherkin_step_name1
Cypress actions and assertions for step1
LOG gherkin_step_name2
Cypress actions and assertions for step2
LOG gherkin_step_name3
Cypress actions and assertions for step3

fileServerFolder option is being used incorrectly

First off, I would like to show my appreciation for this project, it's something that I've been looking for for a while now, and I'm glad you open sourced it!

The issue is that the fileServerFolder option is being used incorrectly to look for step definitions, when it actual use case is to allow cypress to start a local http static assets folder from this path.

I've created a PR here #17

Problem running ScenarioOutline.feature

Re raising issue here:

When I attempt to run the ScenarioOutline.feature I get errors

screen shot 2018-03-09 at 09 51 04

Could it be missing some dependencies? All the others run ok.

When I run: node -v
I get: v8.9.0

Step definitions with the same name in multiple step_definition files

It looks like you cannot have two steps with the same name in different features with different implementations. e.g.

login.feature
Given I enter my details

...should point to step_definitions/login.js given('I enter my details', function() ... )

signup.feature
Given I enter my details

...should point to step_definitions/signup.js given('I enter my details', function() ... )

At the moment it seems like the first one to be loaded wins. Is there any way to solve this?

Typescript/browserify bundle directory output folder broken on Windows 10

Using the typescript configuration settings for the plugin on Windows 10 with Visual Studio Code, the bundle output folder was being put into the root of the application folder instead of the user profile.

I was able to fix it by changing line 100 in the index.js file to use the path.sep instead of a hardcoded forward slash.

.\node_modules\cypress-cucumber-preprocessor\index.js

const bundleDir = file.outputPath.split(path.sep).slice(0, -2);

Since windows uses the backslash this line was producing an invalid array of folder names.

feature: option to customize mocha template

right now the .feature files gets converted to a mocha test using a hardcoded template. Would be nice if we could pass an option to the preprocessor to override the template

Importing two files in shared.js from the same step_definitions folder will fail file2

I upgraded to version 0.4.0, and put "cypress-cucumber-preprocessor": "^0.4.0" in package.json, and then did "npm install".
However I'm still seeing a similar issue as below:
#30

In my support/step_definitions folder there is implementations.js, helpers.js, and shared.js.

Inside shared.js
const implementations = require('./implementations');
const helpers = require('./helpers');

Importing implementations.js is fine. But it'll look for helpers.js relative to the integration folder, instead of /support/step_definitions.

BDD with Scenario Outline and cypress.io. Is it already possible to use it with cypress?

Hi,
I would like to run a feature file containing a "scenario outline" but it does not work. My data in "Examples" step is never read...

See my feature file:
Feature: The Phones app
I want to test my AngularJS app using Cucumber and Cypress
Scenario Outline: Search the details of a phone
Given a list of phones on phones store
When I search the phone in search input
Examples:
| text |
| dell |

See my js file:
const url = 'http://localhost.../index.html#!/phones';

given('a list of phones on phones store', () => {
cy.visit(url);
// Should be on a new URL which includes '/phones'
cy.url().should('include', '/phones');
})

when('I search the phone {string} in search input', (name) => {
cy.log('name :', name);
// Get an input, type into it and verify that the value has been updated
cy.get('input[ng-model="$ctrl.query"]').type(name).should('have.value', name)
})

I hope that my issue is clear enough for you. I hope that anyone could help me
Thanks :-)

Error: ENOENT: no such file or directory, open '..\cypress-cucumber-example\node_modules\cypress-cucumber-preprocessor\temporary-..\cypress-cucumber-example\cypress\integration\Google.feature.js'

Hi,

Thanks for this nice project!

I tried to run this example but unfortunately encountered some problems when trying to run it.
These are the steps I took:
git clone https://github.com/TheBrainFamily/cypress-cucumber-preprocessor.git
npm install
node_modules\.bin\cypress open
Then tried to run test "Facebook.feature"

I ended up with this error:
Error: ENOENT: no such file or directory, open 'C:\Projects\Github\cypress-cucumber-example\node_modules\cypress-cucumber-preprocessor\temporary-C:\Projects\Github\cypress-cucumber-example\cypress\integration\Facebook.feature.js'

I tried to install some additional depndencies
like
npm install --save gherkin
npm install --save @cypress/browserify-preprocessor
but that didn't help either.

Use with Webpack?

Is this the correct way to employ your plugin with webpack?

const cucumber = require( 'cypress-cucumber-preprocessor' ).default;
const webpack = require( '@cypress/webpack-preprocessor' );

module.exports = ( on /* config */ ) => {
  on( 'file:preprocessor', webpack());
  on( 'file:preprocessor', cucumber());
};

(Add Documentation for) Passing API return values between given/when/then

Hi,

I'm using cypress-cucumber-preprocessor to e2e test an API, and am having trouble using cy.request due to it naturally needing to be chained.

In Cypress I would normally do

cy.request('/test').its('status').should(...) etc 

In the example given you use cy.visit, and I assume this stores it in the cy object? What is the best way to do this? Or is this not the correct way of thinking? Currently I am doing this:

/* global cy, then, when, given */

const testEndpoint = '/test'
let response

given('I have access to the test endpoint', () => {
  // expect(true).to.be.equal(true)
})

when('I request the GET /test endpoint', () => {
  response = cy.request(testEndpoint)
})

then(`I get a {int} response code`, (responseCode) => {
  response.its('status').should('eq', responseCode)
})

whilst this works this is obviously not great, and when I want to split out the then into its own shared file etc it will become a nightmare!

Many thanks

Requesting Enhancement for "Step_Definitions" location configuration in package.json to support glob patterns

First of all I want to say that I really love the work you guys have done here. I would, however, like to propose a small tweak to allow the "steps_definitions" location configuration property, configurable in package.json to allow glob patterns.
A potentially quick fix to make this happen would be to replace (in "index.js" at the root folder)
if (loaded && loaded.config && loaded.config.step_definitions) { return path.resolve(appRoot, loaded.config.step_definitions); }
with
if (loaded && loaded.config && loaded.config.step_definitions) { return `${appRoot}/loaded.config.step_definitions`; }
Getting rid of path.resolve, will allow the user to pass in a glob string without it ultimately resolving to something unintended (doesn't say anywhere that glob patterns aren't supported there yet).
I need this enhancement because i'm working on a project wherein all the step_definitions aren't defined under one parent folder by design. This enhancement will give users more flexibility to structure their step_definition files as they see fit.
I can currently achieve my ask by using the "fileServerFolder" configuration property configurable in "cypress.json" but the comment in the aforementioned "index.js" file says it is deprecated but left for backwards compatibility. Not sure if it is going to remain there longterm though. However, ideally, it would be awesome to have that functionality in the "step_definitions" configuration property.

Thanks! I really appreciate your efforts so far!

fs-events windows 10

I'm trying to run a feature using Windows 10 and cypress is throwing the following error:

The following error was thrown by a plugin. We've stopped running your tests because a plugin crashed.

Error: Cannot find module 'fsevents' from 'C:\Users\Danilo Velasquez\dev\altiro-seed\node_modules\chokidar\lib'
at C:\Users\Danilo Velasquez\dev\altiro-seed\node_modules\browser-resolve\node_modules\resolve\lib\async.js:46:17
at process (C:\Users\Danilo Velasquez\dev\altiro-seed\node_modules\browser-resolve\node_modules\resolve\lib\async.js:173:43)
at ondir (C:\Users\Danilo Velasquez\dev\altiro-seed\node_modules\browser-resolve\node_modules\resolve\lib\async.js:188:17)
at load (C:\Users\Danilo Velasquez\dev\altiro-seed\node_modules\browser-resolve\node_modules\resolve\lib\async.js:69:43)
at onex (C:\Users\Danilo Velasquez\dev\altiro-seed\node_modules\browser-resolve\node_modules\resolve\lib\async.js:92:31)
at C:\Users\Danilo Velasquez\dev\altiro-seed\node_modules\browser-resolve\node_modules\resolve\lib\async.js:22:47
at C:\Users\Danilo Velasquez\AppData\Local\Cypress\Cache\3.0.2\Cypress\resources\app\packages\server\node_modules\graceful-fs\polyfills.js:284:29
at FSReqWrap.oncomplete (fs.js:152:21)

I'm not sure if this problem is related to the configuration, cypress or the plugin.

making one test in scenario outline an option

I am struggling with cypress' insistence on tearing the world down between tests. With protractor, we did not need to do this. Not your issue, but...

Scenario outlines are especially painful as invoking "background" ( log in and navigate to where I need to be) on each example becomes very long running. I'd like to see an option where the scenario outlines could be "rendered" as one test rather than "n" tests.

Given, When, Then keywords explicitly mapped

Given, When, Then keywords are explicitly mapped, the basic cucumber rules are not getting followed. i.e we are allowed to create duplicate step with a different keyword. For instance given(user navigates to {string}) is valid as well as then(user navigates to {string}) is also valid.
I believe the vice versa should be the case, wherein cucumber should allow the use of any keyword to define in the feature file but only one declaration of the step.

Feature file Background section issue

The Background section in the feature files is treated as an Scenario, in other words it is only executed once and should be executed before each scenario.
This is coming from the cucumber.io docs
"Occasionally you'll find yourself repeating the same Given steps in all of the scenarios in a feature file. Since it is repeated in every scenario it is an indication that those steps are not essential to describe the scenarios, they are incidental details.
You can literally move such Given steps to the background by grouping them under a Background section before the first scenario
"

Cypress run in Jenkins

When I run cypress run in Jenkins like this:

stage('Build e2e test container') {
        docker.build('wecapangular/cypress', "-f Dockerfile.cypress .")
    }

    stage('Run e2e tests') {
      withDockerContainer(args: "-u root", image: 'wecapangular/cypress') {
        sh 'cd /usr/src/app && npm run cypress:run'
      }
    }

With this Dockerfile:

FROM cypress/base

COPY package.json /usr/src/app/package.json
COPY package-lock.json /usr/src/app/package-lock.json
COPY src /usr/src/app/src/
COPY karma.conf.js /usr/src/app
COPY angular.json /usr/src/app
COPY tsconfig.json /usr/src/app
COPY cypress.json /usr/src/app
COPY cypress /usr/src/app
COPY .npmrc /usr/src/app

WORKDIR /usr/src/app

RUN npm install

Cypress will raise an error. It can't find spec files within cypress/integration/.

Does cypress-cucumber-preprocessor work with the cypress run command?

TypeScript tests fail with `ParseError: 'import' and 'export' may appear only with 'sourceType: module'`

Attempting to set up cypress-cucumber-preprocessor with add-typescript-to-cypress, I receive the following error when running a .feature test in Cypress whose step definitions are in a steps.ts file containing an import statement:

Error running plugin
The following error was thrown by a plugin. We've stopped running your tests because a plugin crashed.

...

ParseError: 'import' and 'export' may appear only with 'sourceType: module'

Running a separate spec.ts file containing an import using only @bahmutov/add-typescript-to-cypress in cypress/plugins/index.js works fine, but as soon as I add on('file:preprocessor', cucumber()); TypeScript tests containing import fail with the same error.

I see other open issues related to that same error but for ES6, not TypeScript (targeting ES5), so I am opening this case.

Versions:

Show a better error message when using import instead of require

syntaxError: 'import' and 'export' may only appear at the top level (8:0) while parsing /Users/jason.lin/cypress-cucumber-example/cypress/integration/login.feature while parsing file: /Users/jason.lin/cypress-cucumber-example/cypress/integration/login.feature

import { loginPage } from '../page-objects/login.po.js';

when('I login with good credential', () => {
	return loginPage.login('[email protected]', '412Debby1');
})

Stubbing API requests and waiting for responses

I have some tests written in cypress that stub some API requests, fill in forms, submit those forms and the ending result is dependent on the stubbed responses. That works really well. However, I am having some difficulties translating those flows of actions into gherkin scenarios.

An example:

login.js

cy.server();

cy.visit('/login');

cy.route({
    method: 'POST',
    response: 'fixture:login/success.json',
    status: 204,
    url: '/api/login',
}).as('postLogin');

cy.get('#login-form-username').type('username');
cy.get('#login-form-password').type('somepassword');
cy.get('#login-form').find('button[type="submit"]').click();
cy.wait('@postLogin').its('status').should('be', 204);

In my opinion the logical way to convert this flow of actions to gherkin would be:

login.feature

Given I visit the "/login" page
When I fill in the username field in the login form with "[email protected]"
And I fill in the password field in the login form with "somepassword"
And I submit the login form
Then I am logged in

However this won't work since the last step is the one defining what stub should be used, but the submit already occurred. One solution would be to have a step definition for stubbing explicitly. Another solution would be to combine the last two steps in one step. However, those two sound weird to me. Are those the only solutions? Are there any conventions on how to do this? Could you add examples on how to do this?

Besides that how can we handle async actions in step definitions? I also have cases where I need to wait for some action before continuing.

help with regular expressions

Using version 0.6.0. I can't figure out how to incorporate regular expressions into the step function.

I'm trying to not only make 'exact' an optional word, but have the step function track whether 'exact' is included or not in the gherkin sentence. This is so my step function's logic can act on whether 'exact' was in the sentence or not.
Goal:
"Then I do a exact search" => step function parameter exactParam will store 'exact'
"Then I do a search" => step function parameter exactParam will store either null, undefined, or ''

But the following cause cypress to say "Step implementation missing for: I do a exact search":
then('I do a (exact)? search'), (exactParam) => {.... //rest of code
then('/I do a (exact)? search/'), (exactParam) => {.... //rest of code
then('^/I do a (exact)? search$/'), (exactParam) => {.... //rest of code
then('^/I do a (exact\s+)?search$/'), (exactParam) => {.... //rest of code

I also tried another simple regex example to look for a single digit in the gherkin sentence:
"Then I do 2"

But Cypress still said "step implementation missing for: I do 2"
then('I do (\d)'), (num) => {.... //rest of code
then('I do (\d+)'), (num) => {.... //rest of code
then('/I do (\d+)/'), (num) => {.... //rest of code

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.