无法将宁静黄瓜(又名修昔底德黄瓜)与黄瓜一起使用



我已经创建了黄瓜测试项目,并成功地通过黄瓜-guice配置了Guice支持。当我添加 serenity-cucmber 并使用 CucumberWithSerenity 配置测试运行程序时,我遇到了一个错误:

More than one Cucumber ObjectFactory was found in the classpath
You probably may have included, for instance, cucumber-spring AND cucumber-guice as part of
your dependencies. When this happens, Cucumber falls back to instantiating the
DefaultJavaObjectFactory implementation which doesn't provide IoC.
In order to enjoy IoC features, please remove the unnecessary dependencies from your class path.

原因是有两个 ObjectFactory 实现:

  • cucumber.runtime.java.guice.impl.GuiceFactory (in cucumber-guice)

  • cucumber.runtime.SerenityObjectFactory (in serenity-cucumber)

是否可以将宁静黄瓜

和黄瓜一起使用?

根据 Serenity-Cucumber 开发者,我们不能使用 Guice,应该使用 Spring。 https://github.com/serenity-bdd/serenity-cucumber/issues/8

可以通过

src/test/resources/cucumber.properties中添加以下属性来选择ObjectFactory实现:

cucumber.api.java.ObjectFactory = cucumber.runtime.java.guice.impl.GuiceFactory

来源: https://cucumber.io/blog/2015/07/08/polymorphic-step-definitions

请注意,您将失去 Senerity Page 功能。否则,您可以编写自己的ObjectFactory类来实现GuiceFactorySerenityObjectFactory的功能。

最新更新