cukes icon indicating copy to clipboard operation
cukes copied to clipboard

Impossible to use CukesHttpPlugin

Open Kidlike opened this issue 6 years ago • 4 comments

I'm trying to write a plugin for cukes-rest but I can't seem to register it.


@Singleton
public class PluginImpl implements CukesHttpPlugin {

    @Override
    public void beforeRequest(RequestSpecification requestSpecification) {
        System.out.println("====== beforeRequest ======");
        requestSpecification
            .filter(new RequestLoggingFilter())
            .filter(new ResponseLoggingFilter());
    }

    // ...other empty overrides...
}

It doesn't seem to have any effect.

I also tried with/without this:


@CukesInjectableModule
public class PluginConf extends AbstractCukesHttpModule {

    @Override
    protected void configure() {
        System.out.println("====== PluginConf ======");
        registerHttpPlugin(PluginImpl.class);
    }
}

Which didn't make any difference either.

EDIT: This is how my main test class looks like:

@RunWith(Cucumber.class)
@CucumberOptions(
    format = {"pretty", "json:target/cucumber.json", "lv.ctco.cukes.core.formatter.CukesJsonFormatter:target/cucumber2.json"},
    glue = "lv.ctco.cukes",
    strict = true
)
public class RunCucumberTest {

I'm using IntelliJ IDEA, and I've tried running the feature files directly, and from the main test class.

Kidlike avatar Jun 05 '18 10:06 Kidlike

After some investigation I found out that the @CukesInjectableModule annotation is only possible to be used in classes under the lv.ctco.cukes package.

This should be at least configurable in cukes.properties, so that anyone can register a plugin.

Relevant snippet:

private void addExternalModules() {
        Reflections reflections = new Reflections("lv.ctco.cukes");
        for (Class targetClass : reflections.getTypesAnnotatedWith(CukesInjectableModule.class)) {
            try {
                Constructor<Module> constructor = targetClass.getConstructor();
                Module module = constructor.newInstance();
                addModule(module);
            } catch (Exception e) {
                throw new CukesRuntimeException("Unable to add External Module to Guice");
            }
        }
    }

https://github.com/ctco/cukes/blob/master/cukes-core/src/main/java/lv/ctco/cukes/core/internal/di/SingletonObjectFactory.java#L77

Kidlike avatar Aug 03 '18 11:08 Kidlike

Have you registered your plugin in cukes.properties file under cukes.plugins property?

JekabsK avatar Sep 12 '18 07:09 JekabsK

Yes I did try that too, made no difference whatsoever.

The only solution that worked was to move the PluginRegistry under lv.ctco.cukes:

package lv.ctco.cukes;

import com.tamedia.cms.uat.plugins.AuthenticationPlugin;

import lv.ctco.cukes.core.extension.CukesInjectableModule;
import lv.ctco.cukes.http.extension.AbstractCukesHttpModule;

@CukesInjectableModule
public class PluginRegistry extends AbstractCukesHttpModule {

    @Override
    protected void configure() {
        registerHttpPlugin(AuthenticationPlugin.class);
    }
}

Kidlike avatar Sep 12 '18 07:09 Kidlike

Any update on this at all? I have hit this problem too.

michaelruocco avatar Oct 17 '18 21:10 michaelruocco