我正在尝试创建一个Springboot、黄瓜和Junit4自动化框架。我使用的版本如下:
我创建了一个支柱类,它试图从属性文件(.yml)中获取属性。
道具类:
@Data
@Component
public class PropsConfig {
@Value("${spring.skyewss}")
public String url;
}梯级防御:
public class SkyeWssLoginStepDef implements En {
private final Logger LOGGER = LoggerFactory.getLogger(this.getClass());
private WebDriver driver;
private SkyeWssLoginPage loginPage;
private SkyeWssUtil skyeWssUtil;
@Autowired
private PropsConfig propsConfig;
public SkyeWssLoginStepDef() {
Given("^I open Skye WSS web page$", () -> {
driver = CukeHook.driver;
loginPage = new SkyeWssLoginPage(driver);
driver.get(propsConfig.getUrl());
skyeWssUtil = new SkyeWssUtil();
LOGGER.info("Current page is " + driver.getTitle());
});
}
......
}黄瓜跑步班:
@RunWith(Cucumber.class)
@CucumberOptions(
features = {"src/test/resources/features"},
plugin = {"pretty", "html:target/cucumber-html-report"},
tags = {"@SkyeWss"}
)
@SpringBootTest
public class WssRegApplicationTests {
}我试过在stepdef课程上贴标签,但没有运气。当我给stepdef类标签,如@Component或@SrpingBootTest时,我将得到错误。
com.flexicards.wss_reg.skye.step.SkyeWssLoginStepDef : Glue类类com.flexicards.wss_reg.skye.step.SkyeWssDashboardValStepDef和类com.flexicards.wss_reg.skye.step.SkyeWssDashboardValStepDef都试图配置cucumber.runtime.CucumberException上下文。请确保只有一个胶水类配置spring上下文。
com.flexicards.wss_reg.skye.step.SkyeWssDashboardValStepDef :胶水类cucumber.runtime.CucumberException被注释为@Component;将其标记为Spring自动检测的候选。Cucumber检测并注册胶水类。按spring自动检测胶类可能会导致重复的bean定义。请删除@Component注释
我是Spring和Springboot的新手,我很确定我在某个地方没有正确配置。大多数的例子是春天和黄瓜已经过时了。我已经试过了。类似于创建一个抽象类,这些类由所有步骤防御类扩展。这将给出与@SpringBootTest 1相同的错误。
有人能帮我吗?欢迎任何投入。非常感谢。
发布于 2019-02-25 20:04:07
看来你几乎把一切都做对了。唯一不合适的地方是上下文配置的位置。它必须在一个具有步骤或钩子定义的文件中。否则黄瓜就不会发现了。这应该能起作用:
@SpringBootTest
@AutoConfigureMockMvc
public class CucumberContextConfiguration {
@Before
public void setup_cucumber_spring_context(){
// Dummy method so cucumber will recognize this class as glue
// and use its context configuration.
}
} 您可以在cucumber-spring中找到一个黄瓜github储存库的工作示例。
也许还需要记住,Cucumber将步骤定义实现为spring,而不是像您可能预期的那样对处理过的单元测试类进行后处理。这意味着@MockBean、@SpyBean和朋友们将无法工作。
编辑:
使用Cucumber v6.0.0,您可以省略虚拟方法,而使用@CucumberContextConfiguration注释。
@SpringBootTest
@CucumberContextConfiguration
public class CucumberContextConfiguration {
} https://stackoverflow.com/questions/54873687
复制相似问题