无法使用宁静黄瓜(aka thucydides-cucumber)和黄瓜guice

时间:2015-03-12 01:59:28

标签: guice cucumber-jvm guice-3 thucydides

我已经创建了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(in cucumber-guice)

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

是否可以使用宁静黄瓜和黄瓜guice?

2 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分: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

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