2

I've created Cucumber test project and successfully configured Guice support by cucumber-guice. When I've added serenity-cucmber and configure test runner with CucumberWithSerenity I've got an error:

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.

The cause is there are two ObjectFactory implementations:

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

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

Is it possible to use serenity-cucumber along with cucumber guice?

GreenTeaCake
  • 848
  • 10
  • 17

2 Answers2

4

As per serenity-cucumber developer we cannot use Guice and should use Spring. https://github.com/serenity-bdd/serenity-cucumber/issues/8

GreenTeaCake
  • 848
  • 10
  • 17
0

You can select the ObjectFactory implementation by adding the following property in src/test/resources/cucumber.properties:

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

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

Note that you will loose the Senerity Page feature. Otherwise you could write your own ObjectFactory class which implements the features of both GuiceFactory and SerenityObjectFactory.

Julien Kronegg
  • 4,968
  • 1
  • 47
  • 60