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



在尝试将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不能包含独立的Rest Assured Dependency。在POM.xml中同时拥有Serenity Rest Assured和独立的Rest Assure库将导致错误。

相关内容

  • 没有找到相关文章

最新更新