使用带有 Rest Assured 的 Serenity-BDD 时如何解决不明确的委托

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

我在尝试将 Serenity BDD 与 JBehave 和 Rest-Assured 结合使用时 运行 遇到了错误。 特别是,当 JBehave 场景的步骤通过 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/");
}

生成的错误如下:

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

感谢解决这些错误的任何解决方案!

糟糕,这似乎是 POM.xml 配置问题:

使用 Serenity Rest-Assured 时,POM.xml 不能包含独立的 放心的依赖。 在 POM.xml 中同时拥有 Serenity Rest-Assured 和独立的 Rest-Assured 库将导致错误。