Suc*_*yan 3 cucumber cypress cypress-cucumber-preprocessor
我正在使用 Cypress(版本:10+)+ Cucumber+ Typescript。我需要使用标签运行测试。另外,我尝试了 cypress-tag 但它不起作用。有没有办法可以使用标签运行 cypress 测试而不跳过测试?
您可以参考此示例存储库进行设置,请在此处检查: https ://github.com/badeball/cypress-cucumber-preprocessor/tree/master/examples/browserify-ts
在你的cypress.config.ts中
import { defineConfig } from "cypress";
import { addCucumberPreprocessorPlugin } from "@badeball/cypress-cucumber-preprocessor";
import browserify from "@badeball/cypress-cucumber-preprocessor/browserify";
async function setupNodeEvents(
on: Cypress.PluginEvents,
config: Cypress.PluginConfigOptions
): Promise<Cypress.PluginConfigOptions> {
await addCucumberPreprocessorPlugin(on, config);
on(
"file:preprocessor",
browserify(config, {
typescript: require.resolve("typescript"),
})
);
// Make sure to return the config object as it might have been modified by the plugin.
return config;
}
export default defineConfig({
e2e: {
specPattern: "**/*.feature",
supportFile: false,
setupNodeEvents,
},
});
Run Code Online (Sandbox Code Playgroud)
package.json中应包含以下依赖项,对于设置 cypress-cucumber-preprocessor 设置“filterSpecs: true”和“omitFiltered: true”非常重要,以便通过标签成功运行
{
"dependencies": {
"@badeball/cypress-cucumber-preprocessor": "latest",
"@cypress/browserify-preprocessor": "latest",
"cypress": "latest",
"typescript": "latest"
},
"cypress-cucumber-preprocessor": {
"filterSpecs": true,
"omitFiltered": true
}
}
Run Code Online (Sandbox Code Playgroud)
然后你可以像这样运行你的功能文件:
cypress run --env tags=@foo
Run Code Online (Sandbox Code Playgroud)