2

我已经创建了 Cucumber 测试项目并通过 cucumber-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(在 cucumber-guice 中)

  • cucumber.runtime.SerenityObjectFactory(在 serenity-cucumber 中)

是否可以将宁静黄瓜与黄瓜酱一起使用?

4

2 回答 2

4

根据 serenity-cucumber 开发人员的说法,我们不能使用 Guice,应该使用 Spring。https://github.com/serenity-bdd/serenity-cucumber/issues/8

于 2015-03-12T14:24:29.917 回答
0

您可以ObjectFactory通过在中添加以下属性来选择实现src/test/resources/cucumber.properties

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

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

请注意,您将失去 SenerityPage功能。否则,您可以编写自己的ObjectFactory类来实现 和 的GuiceFactory特性SerenityObjectFactory

于 2017-04-10T08:04:21.700 回答