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 besrc/test/resources/cucumber.properties
. If you are using gradle this should besrc/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