Search code examples
javarest-assuredjbehaveserenity-bdd

How to resolve ambiguous delegation when using Serenity-BDD with Rest Assured


I am running into an error when trying to use Serenity BDD with JBehave and Rest-Assured. In particular, i get the following errors when a JBehave scenario's step is issuing a request via RestAssured:

@Given("The standalone Rest-Assured")
//succeeds
public void rest_assured_standalone() {
    resp = RestAssured.given().get("https://randomuser.me/api/");
}

@Given("The Serenity Rest-Assured")
//fails
public void rest_assured_serenity() {
    resp = SerenityRest.given().get("https://randomuser.me/api/");
}

The error generated is below:

java.lang.ExceptionInInitializerError
        at net.serenitybdd.rest.utils.RestDecorationHelper.decorate(RestDecorationHelper.java:20)
        at net.serenitybdd.rest.SerenityRest.given(SerenityRest.java:220)
        at objectPackage.RestOperation.loginOperation(RestOperation.java:18)
        at classPackage.Login.loginServer(Login.java:24)
        at testPackage.steps.loginToServer(steps.java:58)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:567)
        at org.jbehave.core.steps.StepCreator$ParametrisedStep.perform(StepCreator.java:790)
        at org.jbehave.core.embedder.PerformableTree$FineSoFar.run(PerformableTree.java:349)


Caused by: java.lang.IllegalArgumentException: Cannot resolve ambiguous delegation of public io.restassured.specification.ResponseSpecification io.restassured.specification.ResponseSpecification.root(java.lang.String) to net.bytebuddy.implementation.bind.MethodDelegationBinder$MethodBinding$Builder$Build@969b7745 or net.bytebuddy.implementation.bind.MethodDelegationBinder$MethodBinding$Builder$Build@5b1bfc25

Appreciate any solutions to resolving these errors!


Solution

  • My bad, it appears to be a POM.xml configuration issue:

    When using Serenity Rest-Assured, the POM.xml cannot contain the standalone Rest-Assured Dependency. Having both Serenity Rest-Assured and the standalone Rest-Assured libraries in the POM.xml will result in the error.