thebrainfamily / cypress-cucumber-example Goto Github PK
View Code? Open in Web Editor NEWExample of using Cypress with Cucumber
License: MIT License
Example of using Cypress with Cucumber
License: MIT License
Hi,
Is there any way available which I can use to run cucumber cypress test parallelly.
Thanks
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.
Been playing with cucumber in python, and the frameworks (behave, pytest-bdd) all appear to ship with spec file generators based on the feature files. Would be something to maybe consider?
Provides some handy tools for generating?
Bug Report:
I have 2 files in integration:
I run command:
You would expect that to output: "Found 2 - path xyz" and execute the 2 feature files, however it stops at the first tag "@1" and doesnt do anything with @2.
I think theres a regression in how its handling this scenario, and you havent made an example with it thus didnt discover the bug.
Please assess when you can!
Regards.
Cypress: 3.8.1
cypress-cucumber-preprocessor: 1.11.0
Google.Feature's Before() produces this error.
`
import { Given, Then, Before } from "cypress-cucumber-preprocessor/steps";
const url = "https://google.com";
let myBeforeCount = 0;
// This verifies that the hooks work with bundling feature
// badeball/cypress-cucumber-preprocessor#234
Before(() => {
expect(myBeforeCount).to.be.lessThan(2);
myBeforeCount += 1;
});
`
Solution: Is to update cypress-cucumber-preprocessor to version 1.16.2 in package.json.
I have two feature file one is login and another one is creation, once login feature file is completed before starting the next feature file application getting its logged out
When I execute both facebook.feature and google.feature with cypress open, facebook.feature passes but google.feature fails with url visit with wrong url. Instead of https//www.google.com I see https://www.google.com/__/#/tests/__all.
When I try recording in dashboard (node_modules/cypress/bin/cypress run --record), it is stuck at the beginning of second feature: google.feature.
When I only execute with one feature, it is working as expected.
I am unable to skip scenarios that are tagged within a feature. I am able to skip entire features though. Here is the example of my issue.
Script from package.json:
"doit:prod": "./node_modules/.bin/cypress-tags run -e TAGS='@feature-tag and not @production-only'"
Example:
@feature-tag
Feature:Example Login Page
Scenario: Validate Login Page Components
Given I visit the Example homepage
Then I validate username field on Example login page
Then I validate password field on Example login page
Then I validate login button on Example login page
Then I validate forgot password on Example login page
@production-only
Scenario: Login With Valid Credentials on Example Homepage
Given I visit the Example homepage
When I type valid username
And I type valid password
Then I expect to see "Example" as user on Example homepage
Expected Result:
I expect cypress to skip the Login With Valid Credentials on Example Homepage scenario.
Actual Result:
Cypress is running both tests.
I have also attempted just trying to skip the scenario without the tag on the feature and just implementing it on the scenario only and that did not work either.
"doit:prod": "./node_modules/.bin/cypress-tags run -e TAGS='not @production-only'",
When I run cypress run --spec **/*.features
I get
zsh: no matches found: **/*.features
Really appreciate all the work that went into this plugin - a pleasure to use and write tests with!
I have now bumped into a situation that I need to segment groups of tests. I am currently relying on a top level all.features
to leverage not spinning up separate chrome instances, but I also need to skip a few of the features.
Is there a recommended way of doing that?
Hi,
So, I cloned the repo, executed it successfully and tried the commands as mentioned
C:\Development\cypress-cucumber-example-master> ./node_modules/.bin/cypress-tags run -e TAGS='@feature-tag'
This gives me the expected result.
====================================================================================================
(Run Finished)
Spec Tests Passing Failing Pending Skipped
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ √ socialNetworks\Facebook.feature 00:04 2 2 - - - │
├────────────────────────────────────────────────────────────────────────────────────────────────┤
│ √ socialNetworks\Twitter.feature 00:05 2 2 - - - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
√ All specs passed! 00:10 4 4 - - -
Now, if I add a script into the package.json such as
"scripts": {
"test": "cypress run --spec \"**/*.feature\"",
"test:all": "cypress run --spec \"**/*.features\"",
"test:tag": "./node_modules/.bin/cypress-tags run -e TAGS='@feature-tag'"
}
and then execute this script, it looks into all the feature files, but doesn't execute any scenario.
PS C:\Development\cypress-cucumber-example-master> npm run test:tag
> [email protected] test:tag C:\Development\cypress-cucumber-example-master
> cypress-tags run -e TAGS='@feature-tag'
====================================================================================================
(Run Starting)
{...}
====================================================================================================
(Run Finished)
Spec Tests Passing Failing Pending Skipped
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ √ All.features 3ms - - - - - │
├────────────────────────────────────────────────────────────────────────────────────────────────┤
│ √ news\Google.feature 3ms - - - - - │
├────────────────────────────────────────────────────────────────────────────────────────────────┤
│ √ socialNetworks\Facebook.feature 1ms - - - - - │
├────────────────────────────────────────────────────────────────────────────────────────────────┤
│ √ socialNetworks\Twitter.feature 1ms - - - - - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
√ All specs passed! 8ms - - - - -
So I wonder if that's the reason there was no a script as part of this repo in the first place, but I don't really understand this different behavior.
I'm pretty new to cypress and nodejs, so my apologies if this is a basic question, but I haven't been able to find an answer so far. If there's any help, I'm on Windows 10.
Why don't we have it yet? This would make life more easier especially debugging where exactly (step) the test failed.
Before everything, thank you Łukasz for your work! It's amazing 🥇
I was just wondering if I could use scenario including a Datatable, like this for example:
The scenario
Scenario: Writing scenario with datatable
Given a table step
| Cucumber | Cucumis sativus |
| Burr Gherkin | Cucumis anguria |
The step definition
given(`a table step`, function(table) {
const expected = [
['Cucumber', 'Cucumis sativus'],
['Burr Gherkin', 'Cucumis anguria']
]
assert.deepEqual(table, expected)
})
But when I do that Cypress displays an AssertionError :
expected undefined to deeply equal [ Array(2) ]
table seems to be undefined. Did I do something wrong?
We are using your implementation and are quite happy but for our tests we need scenario isolated context.(like https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/world.md ) Do you plan to support it or know an way to make this happen ?
thx thomas
Hello,
From what I have seen in the repo Scenario Outlines are now handled by cypress-cucumber.
Althought I am struggling finding the syntax for the variables in the case of a Scenario Outline inplemented in Cypress.
Anyone could add a working example to the repository ?
Thank you :)
I'm new to this so bear with me.
I'm unable to skip test scenarios from feature files with an @Skip tag. The console output is TypeError: this.skip is not a function
OS: Mac OS Catalina (UTD)
Test Framework: Cypress with Cucumber Preprocessor
Browser: Chrome
cucumber: "6.0.5",
cypress: "4.7.0",
cypress-commands: "^1.1.0",
cypress-cucumber-preprocessor: "^2.4.0",
mocha": "^7.2.0"
Please let me know of any more information you would like.
Hey, seems I can't find these for the preprocessor, might be me who can't search properly.
Basically I would like to be able to do some tracability for my tests when they are running against the backend, where I would like to attach the feature name and scenario name in the headers of cy.request
(the BeforeStep
is mostly for completeness).
So I'd like to be able to do:
let featureName: string = ""
let scenarioName: string = ""
BeforeFeature((event, callback) => {
featureName = event.getPayloadItem('feature')
})
// similar for Scenario
Cypress.Commands.overwrite('request', function(originalFn, ...restParameters) {
if (restParameters.length === 1) {
restParameters[0].headers['x-correlation-id'] = `accept-test-${featureName}-${scenarioName}`
}
return originalFn.apply(this, restParameters)
})
I have updated the dependency as follows by cloning this repository and tried to run the tests. I have also open the Cypress and migrated the config and other files to proceed further.
"dependencies": {
"cypress": "^12.0.2",
"cypress-cucumber-preprocessor": "^4.3.1"
}
But ended up with the getting the below errors.
> [email protected] test
> cypress run --spec "**/*.feature"
Warning: We failed to trash the existing run results.
This error will not alter the exit code.
Error: spawn Unknown system error -86
at ChildProcess.spawn (node:internal/child_process:413:11)
at spawn (node:child_process:709:9)
at execFile (node:child_process:336:17)
at node:child_process:243:21
at node:electron/js2c/asar_bundle:5:3131
at s.exports (<embedded>:1372:1011480)
at <embedded>:1372:1019740
at <embedded>:1358:431521
at new Promise (<anonymous>)
at r (<embedded>:1358:431502)
at p (<embedded>:1372:1019248)
at <embedded>:2837:406870
at tryCatcher (/Library/Caches/Cypress/12.0.2/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/util.js:16:23)
at MappingPromiseArray._promiseFulfilled (~/Library/Caches/Cypress/12.0.2/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/map.js:61:38)
at MappingPromiseArray.<anonymous> (~/Library/Caches/Cypress/12.0.2/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise_array.js:114:31)
at MappingPromiseArray.init (~/Library/Caches/Cypress/12.0.2/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise_array.js:78:10)
at Promise._settlePromise (~/Library/Caches/Cypress/12.0.2/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:566:21)
at Promise._settlePromise0 (~/Library/Caches/Cypress/12.0.2/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (~/Library/Caches/Cypress/12.0.2/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:694:18)
at Promise._fulfill (~/Library/Caches/Cypress/12.0.2/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:638:18)
at ~/Library/Caches/Cypress/12.0.2/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/nodeback.js:42:21
at <embedded>:219:98304
at <embedded>:2844:18778
at FSReqCallback.oncomplete (node:fs:188:23)
====================================================================================================
(Run Starting)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 12.0.2 │
│ Browser: Electron 106 (headless) │
│ Node Version: v19.2.0 (/opt/homebrew/Cellar/node/19.2.0/bin/node) │
│ Specs: 1 found (Google.feature) │
│ Searched: **/*.feature │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: Google.feature (1 of 1)
Your configFile threw an error from: cypress.config.js
We stopped running your tests because your config file crashed.
Error: We've tried to resolve your step definitions at cypress/integration, but that doesn't seem to exist. As of version 2.0.0 it's required to set step_definitions in your cypress-cucumber-preprocessor configuration. Look for nonGlobalStepDefinitions and add stepDefinitions right next to it. It should match your cypress configuration has set for integrationFolder. We no longer rely on getting information from that file as it was unreliable and problematic across Linux/MacOS/Windows especially since the config file could have been passed as an argument to cypress.
at module.exports (~/GitHub/cypress-cucumber-example/node_modules/cypress-cucumber-preprocessor/lib/stepDefinitionPath.js:20:15)
at getStepDefinitionsPaths (~/GitHub/cypress-cucumber-example/node_modules/cypress-cucumber-preprocessor/lib/getStepDefinitionsPaths.js:14:46)
at module.exports (~/GitHub/cypress-cucumber-example/node_modules/cypress-cucumber-preprocessor/lib/loader.js:25:36)
at Stream.end (~/GitHub/cypress-cucumber-example/node_modules/cypress-cucumber-preprocessor/lib/index.js:24:18)
at _end (~/GitHub/cypress-cucumber-example/node_modules/through/index.js:65:9)
at Stream.stream.end (~/GitHub/cypress-cucumber-example/node_modules/through/index.js:74:5)
at DestroyableTransform.onend (~/GitHub/cypress-cucumber-example/node_modules/readable-stream/lib/_stream_readable.js:577:10)
at Object.onceWrapper (node:events:627:28)
at DestroyableTransform.emit (node:events:525:35)
at endReadableNT (~/GitHub/cypress-cucumber-example/node_modules/readable-stream/lib/_stream_readable.js:1010:12)
at processTicksAndRejections (node:internal/process/task_queues:82:21)
Whenever a scenario fails the After()
method does not get called.
I'm running the following versions.
"cypress-cucumber-preprocessor": "2.5.0",
"@cypress/webpack-preprocessor": "5.4.1",
"cypress": "4.9.0",
Can I stop the code executing by break point at some row into *.steps.ts using run and debug mode into VSCode?
At the moment code execute till the end of test.
My launch.json
"version": "0.2.0",
"configurations": [
{
"type": "node-terminal",
"request": "launch",
"name": "CY-DEBUG",
"skipFiles": ["<node_internals>/**"],
"command": "./node_modules/.bin/cypress-tags run -e TAGS='@debug'",
"env": {
"SHA":"46ef8ca8788d6e9d97c8d673857e964681df1895",
"BUILD_ID":"2848972426"
}
}
]
}
I tried to run All.features right after npm install from this example repository and it looks like no tests are getting executed. Is there anything I am doing wrong?
~/D/c/cypress-cucumber-example> npm run test:all master!
> [email protected] test:all /Users/<***>/Desktop/cypress/cypress-cucumber-example
> cypress run --spec "**/*.features"
====================================================================================================
(Run Starting)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 3.7.0 │
│ Browser: Electron 73 (headless) │
│ Specs: 1 found (All.features) │
│ Searched: **/*.features │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: All.features (1 of 1)
Browserslist: caniuse-lite is outdated. Please run next command `npm update`
0 passing (1ms)
(Results)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Tests: 0 │
│ Passing: 0 │
│ Failing: 0 │
│ Pending: 0 │
│ Skipped: 0 │
│ Screenshots: 0 │
│ Video: true │
│ Duration: 0 seconds │
│ Spec Ran: All.features │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
(Video)
- Started processing: Compressing to 32 CRF
- Finished processing: /Users/<***>/Desktop/cypress/cypress-cucumber-examp (0 seconds)
le/cypress/videos/All.features.mp4
====================================================================================================
(Run Finished)
Spec Tests Passing Failing Pending Skipped
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ ✔ All.features 2ms - - - - - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
✔ All specs passed! 2ms - - - - -
This feature file has two tests marked with tags @smoke and @regression
Google.feature
Feature: The Facebook
I want to open a social network page
@smoke
Scenario: fhgfh a social network page
Given I open Google page
Then I see "Google" in the title
@regression
Scenario:sd a social network page
Given I open Google page
Then I see "Google" in the title
I want to scenario only with tag @smoke so using command npx cypress-tags run -e TAGS='@smoke'
this command runs the desired scenario but marks others as pending. Example of the result shown in the below image
https://ibb.co/CPfqzLv
How to avoid the not executed scenario "marked as pending"?
Cucumber Given When Then are not printed to the console output after upgrade:
Version used:
"cypress": "^3.1.0",
"cypress-cucumber-preprocessor": "^1.6.0",
Error: Cannot find module 'E:democypress-cucumber-example
ode_modulescypress-cucumber-preprocessorlib/createTestsFromFeature' from 'E:\demo\cypress-cucumber-example\cypress\integration\common'
hi
it seems missing "when" in alls steps.
why ?
It appears scoped hooks aren't working in the demo app. When you run all tests, the before hook that states it only runs during the Google tests is run during all tests.
repro steps: clone the demo app, run cypress, and run all tests.
I was having issues with scoped step definitions in a project and I wanted to make sure it wasn't a weird configuration on my end. I'm wondering if this is a bug with scoped step definitions and if I should file an issue against the main repo.
Thanks
When I try to run cy.server() in order to mock http requests that are executed as part of the tests, I get the following error:
Uncaught CypressError: Cannot call "cy.server()" outside a running test.....
I don't know how to get this to work. This is my code:
import { Given, Then } from 'cypress-cucumber-preprocessor/steps'
beforeEach(() => {
cy.server()
cy.route({
method: 'GET',
url: '/',
response: []
})
})
const url = 'http://localhost:8080'
Given('I click the big button', () => {
cy.visit(url)
cy.get('.btn').click()
})
Then('I can get the MOTD', (title) => {
cy.title().should('include', title)
})
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.