HI,
I have tried to set up a project with cypress / cypress-cucumber-preprocessor and typescript without much success. I've decied to give it a shot without typescript. However, it's like Cypress is not recognizing my tests. I'm getting this error:
No tests found in your file:
/my-project/test/cypress/integration/google.js
We could not detect any tests in the above file. Write some tests and re-run.
This is my plugins/index.js I have
const cucumber = require('cypress-cucumber-preprocessor').default
module.exports = on => {
on('file:preprocessor', cucumber())
}
My cypress.json file
{
"ignoreTestFiles": "*.feature"
}
My package.json file
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"cypress": "cypress open"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@cypress/webpack-preprocessor": "^4.0.2",
"@types/node": "^10.12.18",
"awesome-typescript-loader": "^5.2.1",
"cypress": "^3.1.4",
"cypress-cucumber-preprocessor": "^1.9.1",
"typescript": "^3.2.2"
},
"cypress-cucumber-preprocessor": {
"nonGlobalStepDefinitions": true
}
}
This is my feature file google.feature
Feature: The Google
I want to open Google page
@focus
Scenario: Opening a the Google home page
Given I open Google page
Then I see "google" in the title
And this is my google.spec.js file
import { Given, Then } from "cypress-cucumber-preprocessor/steps";
const url = 'https://google.com'
Given(/^I open Google page?/, () => {
cy.visit(url)
})
Then(/I see "google" in the title?/, () => {
console.log("google :)")
})
What am I doing wrong?
Thank you
Hi, @alveshelio, happy to see you trying out this library.
To start with - you do not need need this line "ignoreTestFiles": "*.feature" in your cypress.json.
Secondly - where do you have your google.spec.js file? Is it located anywhere else than cypress/support/step_definitions/ you should add some extra config to your package.json, as described here https://github.com/TheBrainFamily/cypress-cucumber-preprocessor#step-definition-location-configuration
Hi @sawasawasawa,
Thank you for the reply. My file google.spec.js was located in cypress/integration, I followed this example: https://github.com/TheBrainFamily/cypress-cucumber-example. In this example, the google.js file is in cypress/integration/google.
I think my error was that I was trying to run the .js files and in fact, cypress will run the .feature files.
Now my .feature files are in cypress/integration/featureName and my .js files are in cypress/e2e/featureName/nameOf.featureFile/.
I've re-read the doc and it's very explicit:
Step definitions creation
Then put your step definitions in cypress/integration with the folder name matching the .feature filename. Easier to show than to explain, so, assuming the feature file is in cypress/integration/Google.feature , as proposed above, the preprocessor will read all the files inside cypress/integration/Google/, so:
cypress/integration/Google/google.js (or any other .js file in the same path)
Thank you very much for the help
That's the 'new' approach that you used - it was introduced here just around 3 weeks ago.
I'm glad it's working for you now. Happy hacking!
@alveshelio Please confirm - did it actually work for you in the end? To use the 'new approach' you need to use this configuration:
"cypress-cucumber-preprocessor": {
"nonGlobalStepDefinitions": true
}
Hi @lgandecki,
Yes it did work, I've used "nonGlobalStepDefinitions": true
Thank you very much for the support.
Hello. I'm trying to setup the project with your module, but I'm just not able to get it running.
All I get though when I try to run the .feature is colourful bubbles for a second and: No tests found in your file: cypress/integration/app/Test.feature.
My setup is typescript through webpack…
module (dumped to console, so limited depth){
rules: [
{
test: /\.(js|jsx|ts|tsx)$/,
exclude: /node_modules/,
include: [Array],
use: [Array]
},
{ test: /\.json$/, use: 'json-loader', type: 'javascript/auto' },
{
test: /\.png|jpg|gif|svg$/i,
exclude: /node_modules/,
use: [Object]
},
{ test: /\.feature$/, use: 'cypress-cucumber-preprocessor/loader' },
{ test: /\.features$/, use: 'cypress-cucumber-preprocessor/lib/featuresLoader' },
{ test: /\.css$/, use: [Array] },
{ test: /\.scss$/i, oneOf: [Array] }
]
}
cypress/integration/app/Test.featureFeature: The main page
I want to open the main page
Background:
Given I open the desktop application
Scenario: Opening the main page
Then I see "Slush Pool" in the title
cypress/integration/app/Test/Test.tsximport { Given, Then } from 'cypress-cucumber-preprocessor/steps';
Given('I open the desktop application', () => {
cy.visit('localhost:8000');
});
Then(`I see "{string}" in the title`, title => {
cy.title().should('include', title);
});
…and I do have the nonGlobalStepDefinitions option enabled in package.json.
I don't think it really should be relevant, but I'm using Yarn@Berry with PnP enabled
I'm pretty confused by @alveshelio's answer above
Now my .feature files are in cypress/integration/featureName and my .js files are in cypress/e2e/featureName/nameOf.featureFile/.
Why would the steps file (considering he meant those by js files) be in cypress/e2e/… and not along with the .feature file?
I've been able to look into the result returned by the loader:
const {
resolveAndRunStepDefinition,
defineParameterType,
given,
when,
then,
and,
but,
Before,
After,
defineStep
} = require("â–’â–’â–’/.yarn/unplugged/cypress-cucumber-preprocessor-npm-2.5.4-059da41c96/node_modules/cypress-cucumber-preprocessor/lib/resolveStepDefinition");
const Given = (window.Given = window.given = given);
const When = (window.When = window.when = when);
const Then = (window.Then = window.then = then);
const And = (window.And = window.and = and);
const But = (window.But = window.but = but);
window.defineParameterType = defineParameterType;
window.defineStep = defineStep;
const {
createTestsFromFeature
} = require("â–’â–’â–’/.yarn/unplugged/cypress-cucumber-preprocessor-npm-2.5.4-059da41c96/node_modules/cypress-cucumber-preprocessor/lib/createTestsFromFeature");
window.cucumberJson = {"generate":false};
describe(`The main page`, function() {
require('â–’â–’â–’/cypress/integration/app/Test/steps.ts')
createTestsFromFeature('Test.feature', 'Feature: The main page\n\n I want to open the main page\n\n Background:\n Given I open the desktop application\n\n Scenario: Opening the main page\n Then I see \"Slush Pool\" in the title\n');
});
So, I've got it working … in the end it seems to have been caused by webpack config (god knows what exactly).
I've fixed it by not reusing our overly complex config for bundling of the web app & just re-created one inline.
@kubijo did you get this working with a steps file with tsx extension? I have a similar webpack config to yours and the steps cannot be found if the file extension is tsx. ts works just fine but I need to use JSX in my steps files.
Looking at the source of cypress-cucumber-preprocessor it looks like it might not be expecting tsx files but I'd need to check into it some more.
@kubijo did you get this working with a steps file with
tsxextension? I have a similar webpack config to yours and the steps cannot be found if the file extension istsx.tsworks just fine but I need to use JSX in my steps files.Looking at the source of cypress-cucumber-preprocessor it looks like it might not be expecting
tsxfiles but I'd need to check into it some more.
Nope, we're using *.ts and I don't recall the reason for it from the top of my head… just a vague idea that I wanted to distinguish those files from project files… maybe :shrug:
Ah ok. Thanks @kubijo for confirming!
Most helpful comment
Hi, @alveshelio, happy to see you trying out this library.
To start with - you do not need need this line
"ignoreTestFiles": "*.feature"in your cypress.json.Secondly - where do you have your google.spec.js file? Is it located anywhere else than
cypress/support/step_definitions/you should add some extra config to your package.json, as described here https://github.com/TheBrainFamily/cypress-cucumber-preprocessor#step-definition-location-configuration