尝试将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库都将导致错误。

10-06 16:17