Polymorphic Step Definitions with Cucumber-jvm

Just a quick snippet that I am using to create Polymorphic Step Definitions with cucumber-jvm.

First you need to import picocontainer library.

When you can use it ? It’s useful if you have for example Integration and UI scenarios in the same project. For example, for mobile tests I am using robotium, but for the server tests I am using HTTPClient Apache.

Example:
import cucumber.runtime.java.picocontainer.PicoFactory;

public class TestsFactory extends PicoFactory {
public TestsFactory() {
if ("integration".equals(System.getProperty("com.rsouza.androidTest.integration"))) {
addClass(SupportIntegrationSteps.class);
addClass(SupportIntegration.class);
}
else{
addClass(SupportUI.class);
}
}
}
You just need define Cucumber to use cucumber.api.java.ObjectFactory system property.

  • Create a cucumber.properties file on your classpath and if you are using Maven, this should be src/test/resources/cucumber.properties. If you are using gradle this should be src/androidTest/res/cucumber.properties 
  • Add the following line: cucumber.api.java.ObjectFactory = my.features.CustomPicoFactory

Thank you guys ! See you next week 🙂

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.