admin 管理员组文章数量: 1086019
I've got a mixture of Cucumber .feature
files and normal Cypress .spec.js
files.
Normally, they run together fine as I have included:
specPattern: ["cypress/e2e/**/*.spec.js", "cypress/e2e/*.feature"],
in my cypress.config.js
file.
However, I want to use Cypress's Module API, eg:
const mySpecs = [
`homePage.spec.js`,
`aboutPage.spec.js`
];
cypress.run({
browser: 'chrome',
spec: mySpecs,
});
The above works, but not if I also have a .feature
file.
const mySpecs = [
`homePage.spec.js`,
`aboutPage.spec.js`,
`contactPage.feature`
];
I've tied modifying the above, eg:
cypress.run({
browser: 'chrome',
spec: mySpecs,
config: {
specPattern: ["cypress/e2e/**/*.spec.js", "cypress/e2e/*.feature"],
}
});
and
cypress.run({
browser: 'chrome',
specPattern: ["cypress/e2e/**/*.spec.js", "cypress/e2e/*.feature"],
spec: mySpecs
});
Does anyone know if this is possible?
I've got a mixture of Cucumber .feature
files and normal Cypress .spec.js
files.
Normally, they run together fine as I have included:
specPattern: ["cypress/e2e/**/*.spec.js", "cypress/e2e/*.feature"],
in my cypress.config.js
file.
However, I want to use Cypress's Module API, eg:
const mySpecs = [
`homePage.spec.js`,
`aboutPage.spec.js`
];
cypress.run({
browser: 'chrome',
spec: mySpecs,
});
The above works, but not if I also have a .feature
file.
const mySpecs = [
`homePage.spec.js`,
`aboutPage.spec.js`,
`contactPage.feature`
];
I've tied modifying the above, eg:
cypress.run({
browser: 'chrome',
spec: mySpecs,
config: {
specPattern: ["cypress/e2e/**/*.spec.js", "cypress/e2e/*.feature"],
}
});
and
cypress.run({
browser: 'chrome',
specPattern: ["cypress/e2e/**/*.spec.js", "cypress/e2e/*.feature"],
spec: mySpecs
});
Does anyone know if this is possible?
Share Improve this question edited Mar 28 at 13:03 Leta Waldergrave 8964 silver badges13 bronze badges asked Mar 28 at 2:51 MeltingDogMeltingDog 15.6k52 gold badges178 silver badges322 bronze badges1 Answer
Reset to default 2I just ran a clean system including typescript and badeball/cypress-cucumber-preprocessor.
I added Badeball's example duckduckgo.feature
plus it's step file in the folder cypress/e2e/features
.
This is the cypress.config.ts
, pretty much as per Example setup except the specPattern
setting included feature and non-feature file patterns (only used .js
spec patterns not .ts
but you should be able to specify those as well).
import { defineConfig } from "cypress";
import createBundler from "@bahmutov/cypress-esbuild-preprocessor";
import { addCucumberPreprocessorPlugin } from "@badeball/cypress-cucumber-preprocessor";
import { createEsbuildPlugin } from "@badeball/cypress-cucumber-preprocessor/esbuild";
export default defineConfig({
e2e: {
specPattern: ['**/*.e2e.js', '**/*.spec.js', '**/*.feature'],
async setupNodeEvents(on, config) {
await addCucumberPreprocessorPlugin(on, config);
on('file:preprocessor', createBundler({
plugins: [createEsbuildPlugin(config)],
})
)
return config
},
},
})
In the Module API script to run the tests, I used similar to your script but I specified the full path from the project root, i.e included cypress/e2e
.
const cypress = require('cypress')
const mySpecs = [
`./cypress/e2e/home-page-test.spec.js`,
`./cypress/e2e/about-page-test.spec.js`,
`./cypress/e2e/features/duckduckgo.feature`
];
cypress
.run({
browser: 'chrome',
spec: mySpecs,
})
For me the full path to specs and feature was required, otherwise Cypress reported it did not match any specs (or features).
My understanding is the Module API runner uses cypress.config.ts
as the base config, then adds anything you put in the script as an override, similar to the way the Cypress CLI lets you override browser, spec, etc.
So if you have specified specPattern
in cypress.config.ts
and all the specs and features can be run via the GUI (npm cypress open), then the Module API script just needs to specify the specs and features (and in this case browser, presuming you don't want the default Electron browser).
本文标签: javascriptCan I get the Cypress API to run feature files as well as spec filesStack Overflow
版权声明:本文标题:javascript - Can I get the Cypress API to run `.feature` files as well as `spec` files? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744059296a2526427.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论