Cucumber 7.14.0中如何在Cucumber Options中使用多标签?
解决Cucumber 7.14.0多标签使用报错问题
问题原因
Cucumber 7.x版本对@CucumberOptions的tags参数做了调整,不再支持数组形式({}包裹的写法),该参数现在仅接受单个字符串类型的值,这直接导致你遇到Type mismatch: cannot convert from String[] to String的类型转换错误。
修正后的代码
将tags的数组写法改为单个字符串,多个标签通过逻辑运算符连接:
- 要运行任意一个标签的用例(逻辑或),用
or或直接空格分隔 - 要运行同时满足多个标签的用例(逻辑与),用
and连接
package com.app.main; import org.junit.runner.RunWith; import io.cucumber.junit.Cucumber; import io.cucumber.junit.CucumberOptions; @RunWith(Cucumber.class) @CucumberOptions( glue = {"com.app.stepdef"}, features = {"Features"}, plugin = {"pretty","html:target/HtmlReport.html","json:target/JSONReport.json"}, dryRun = true, monochrome=true, tags = "@smoke or @sanity" // 运行带@smoke或@sanity标签的用例 // 若需同时满足两个标签,可写为 tags = "@smoke and @sanity" ) public class MyRunner { }
额外说明
- 排除指定标签的用例可使用
not,比如@smoke not @ignore - 空格分隔多个标签等价于
or逻辑,即@smoke @sanity和@smoke or @sanity效果一致
内容的提问来源于stack exchange,提问作者Mohanraj Rathinakumar
相关产品推荐
相关产品推荐

