I am currently working on setting up e2e tests using Cypress and Cucumber for my project. The application is built with Vue CLI 4.1.1, and I have added the package cypress-cucumber-preprocessor (V1.19.0) via NPM.
Update:
After extensive research and testing, I believe I have identified the source of the issue but am struggling to find a solution:
The '@vue/cli-plugin-babel/preset' does not seem to be compatible with .feature files...
Here is my babel.config.js file:
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
]
}
Any suggestions on how I can integrate cli-plugin-babel with Cypress-Cucumber?
In my Test.feature file, I execute steps defined in test.step.js files. Below is the content of my test.spec.js:
import { When, Then } from 'cypress-cucumber-preprocessor/steps';
import { HomePage } from './pages/home.page';
When(/^I open the Home page$/, () => {
let homePage = new HomePage();
homePage.goTo();
});
Then(/^I see "([^"]*)" in the main heading$/, msg => {
cy.contains('h1', msg)
});
And here is the content of my PageObject home.page.js:
export class HomePage {
goTo() {
cy.visit("/");
}
}
When running:
npm run test:e2e
I encounter the following error:
Oops...we found an error preparing this test file:
tests/e2e/features/Test.feature
The error was:
SyntaxError: 'import' and 'export' may appear only with 'sourceType: module'
This occurred while Cypress was compiling and bundling your test code. This is usually caused by:
- A missing file or dependency
- A syntax error in the file or one of its dependencies
Fix the error in your code and re-run your tests.
These errors do not occur when using:
export function goToHomePage() {
cy.visit("/");
}
You can view my project on Github: https://github.com/truar/cloudcmr-v2 (branch master for the passing case, branch pageObject_pattern for the failing case).
I suspect this issue is related to ES6 and Cypress, but I am unsure of the exact cause. Additionally, most resources online discuss Cypress-Cucumber integration with Typescript, which I am not utilizing.
Any insights on what could be causing this?