如何在使用Serenity-BDD和Rest Assured时解决模糊委托问题

huangapple go评论85阅读模式
英文:

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

欢迎提供解决这些错误的任何解决方案!

英文:

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!

答案1

得分: 1

抱歉,看起来是一个 POM.xml 配置问题:

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

英文:

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.

huangapple
  • 本文由 发表于 2020年4月8日 18:24:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/61098432.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定