GithubHelp home page GithubHelp logo

thebrainfamily / cypress-cucumber-typescript-example Goto Github PK

View Code? Open in Web Editor NEW
32.0 3.0 19.0 179 KB

Example of using Cypress with Cucumber and Typescript

Gherkin 3.26% TypeScript 16.30% JavaScript 80.44%

cypress-cucumber-typescript-example's Introduction

cypress-cucumber-typescript-example's People

Contributors

badeball avatar lgandecki 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

Watchers

 avatar  avatar  avatar

cypress-cucumber-typescript-example's Issues

No type definitions, Webstorm support not working

Hi, not sure which repo is correct to report this to but giving a shot here!

According to https://www.npmjs.com/package/cypress-cucumber-preprocessor under Webstorm, there is an example of how to enable step navigation by using a specific regex pattern.

Using this repo as an example and modifying google.ts to read Given(/^I pass?/, () => { as per the instructions does not work though, as well as
import { Given } from "cypress-cucumber-preprocessor/steps"; results in TS7016 (no declaration found for module).

I'm not quite sure what setup the example on npmjs is using to get Webstorm working, so it'd be super interesting to see a working example of this perhaps in this typescript-example repo :)

Cypress detected that you returned a promise in a test, but also invoked one or more cy commands inside of that promise.

Seems to be caused by the inclusion of common/globalBefore.ts.
This warning occurs in the browser console when running tests (even if the test actually doesn't do an awful lot).

The issue can be seen in this PR: #8

Run

npm run test:open

Run the only feature test available. Look at the browser console output to see numerous examples

cypress_runner.js:179344 Cypress Warning: Cypress detected that you returned a promise in a test, but also invoked one or more cy commands inside of that promise.

The test title was:

  > Passing with TypeScript "before each" hook

While this works in practice, it's often indicative of an anti-pattern. You almost never need to return both a promise and also invoke cy commands.

Cy commands themselves are already promise like, and you can likely avoid the use of the separate Promise.

If your remove the common/globalBefore.ts file the warnings go away.

@focus not working as expected

I logged this issue before but did not provide enough detail about how to replicate it.

Firstly my understanding of the @Focus tag is that only that scenario will run and all other scenarios in all other features will not.

Taking this repo as an example is not ideal as it does not have enough features/scenarios. So I deleted the features in this repo and copied in the features from the original repo: https://github.com/TheBrainFamily/cypress-cucumber-preprocessor

So I now have:

common
news
socialNetworks
All.features

I then renamed all the .js files to .ts.

I then included a tsconfig.json file in the root like this:

{
    "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "types": ["node", "cypress"],
        "moduleResolution": "node",
        "lib": ["es2016", "dom", "dom.iterable"],
        "downlevelIteration": true,
        "sourceMap": true,
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "noImplicitReturns": true,
        "esModuleInterop": true,
        "strict": false
    },
    "exclude": [
        "node_modules"
    ],
    "include": [
        "cypress/**/*.ts"
    ]
}

I then added a cypress/support/index.d.ts file like this:

// in cypress/support/index.d.ts
// load type definitions that come with Cypress module
/// <reference types="cypress" />

My package.json file ensured that we have the latest stuff:

{
  "name": "cypress-cucumber-typescript-example",
  "version": "1.0.0",
  "description": "Example of how to use Cypress with Cucumber and TypeScript",
  "main": "index.js",
  "scripts": {
    "test": "npx cypress run --spec \"**/*.features\""
  },
  "author": "Lukasz Gandecki",
  "license": "ISC",
  "dependencies": {
    "cypress": "^4.9.0",
    "cypress-cucumber-preprocessor": "^2.5.2",
    "tsify": "^4.0.1",
    "typescript": "^3.4.5"
  },
  "cypress-cucumber-preprocessor": {
    "nonGlobalStepDefinitions": true
  }
}

I then added this line to the top of cypress/integration/common/globalBefore.ts

/// <reference path="../../support/index.d.ts" />

Ran npm i to install everything.

I want to focus only on the first Google test like this:

Feature: The Google

  I want to open Google page

  @focus
  Scenario: Opening a Google network page
    Given I open Google page
    Then I see "Google" in the title

  Scenario: Different kind of opening
    Given I kinda open Google page
    Then I am very happy

When I run npm run test I find that
Scenario: Opening a Google network page runs
Scenario: Different kind of opening is pending
so far so good....however, all the other tests in news and socialNetworks also run

This seems wrong to me. I would only expect one scenario to run.

Cypress Failed to Start

Hi,

I cloned the repo, Installed the dependencies and when i run test, i'm getting an error Cypress failed to start. I have installed cypress globally, also tried running the test from ./node_modules/.bin/cypress open but no luck. Attached the screenshot for reference

image

Trying to run the sample code but stuck

Hello,

I'm new to Cypress and trying to run your example in order to work with Cypress-cucumber-typescript. I use IntelliJ Ultimate and configured/installed cucumber.js and cypress-cucumber-preprocessor.

When running 'cypress open' from node-module/.bin I get this
cypress-cucumber-preprocessor

Message: ENOTDIR invalid cwd /Users/radomj/cypress-cucumber-typescript-example-master/node_modules/.bin/cypress/integration

Stack trace:

Error: ENOTDIR invalid cwd /Users/radomj/cypress-cucumber-typescript-example-master/node_modules/.bin/cypress/integration
    at Glob._readdirError (/Users/radomj/Library/Caches/Cypress/5.6.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/glob/glob.js:592:21)
    at /Users/radomj/Library/Caches/Cypress/5.6.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/glob/glob.js:553:12
    at go$readdir$cb (/Users/radomj/Library/Caches/Cypress/5.6.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/graceful-fs/graceful-fs.js:162:14)
    at FSReqCallback.oncomplete (fs.js:159:23)

image
Please, help

Thanks in advance

Jeff

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.