net.serenitybdd.core.exceptions.SerenityManagedException:SERENITY_DISABLE_REST_CALLS_AFTER_FAILURES

问题描述 投票:1回答:1

我正在关注许多serenity bdd测试API的例子。主要是(https://github.com/serenity-bdd/serenity-core/blob/master/serenity-screenplay-rest/src/test/java/net/serenitybdd/screenplay/rest/examples/WhenRetrievingUserDetails.java

但是,当我运行我的代码时,我总是得到:

TEST FAILED WITH ERROR: User attempts to recover the password
---------------------------------------------------------------------
[main] ERROR net.serenitybdd.core.Serenity - TEST FAILED AT STEP Rest
[main] ERROR net.serenitybdd.core.Serenity - SERENITY_DISABLE_REST_CALLS_AFTER_FAILURES

net.serenitybdd.core.exceptions.SerenityManagedException: SERENITY_DISABLE_REST_CALLS_AFTER_FAILURES

    at net.serenitybdd.rest.utils.RestExecutionHelper.restCallsAreDisabled(RestExecutionHelper.java:28)
    at net.serenitybdd.rest.utils.RestSpecificationFactory.getInstrumentedRequestSpecification(RestSpecificationFactory.java:105)
    at net.serenitybdd.rest.utils.RestDecorationHelper.decorate(RestDecorationHelper.java:20)
    at net.serenitybdd.rest.SerenityRest.given(SerenityRest.java:220)
    at net.serenitybdd.screenplay.rest.interactions.RestInteraction.rest(RestInteraction.java:32)
    at net.serenitybdd.screenplay.rest.interactions.Post$$EnhancerByCGLIB$$6437c6d9.CGLIB$rest$3(<generated>)
    at net.serenitybdd.screenplay.rest.interactions.Post$$EnhancerByCGLIB$$6437c6d9$$FastClassByCGLIB$$49fc3d71.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at net.thucydides.core.steps.BaseMethodRunner.invokeMethod(BaseMethodRunner.java:10)
    at net.thucydides.core.steps.NormalMethodRunner.invokeMethodAndNotifyFailures(NormalMethodRunner.java:20)
    at net.thucydides.core.steps.StepInterceptor.runNormalMethod(StepInterceptor.java:361)
    at net.thucydides.core.steps.StepInterceptor.testStepResult(StepInterceptor.java:132)
    at net.thucydides.core.steps.StepInterceptor.intercept(StepInterceptor.java:68)
    at net.serenitybdd.screenplay.rest.interactions.Post$$EnhancerByCGLIB$$6437c6d9.rest(<generated>)
    at net.serenitybdd.screenplay.rest.interactions.Post.performAs(Post.java:24)
    at net.serenitybdd.screenplay.rest.interactions.Post$$EnhancerByCGLIB$$6437c6d9.CGLIB$performAs$0(<generated>)
    at net.serenitybdd.screenplay.rest.interactions.Post$$EnhancerByCGLIB$$6437c6d9$$FastClassByCGLIB$$49fc3d71.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at net.thucydides.core.steps.StepInterceptor.invokeMethod(StepInterceptor.java:449)
    at net.thucydides.core.steps.StepInterceptor.executeTestStepMethod(StepInterceptor.java:434)
    at net.thucydides.core.steps.StepInterceptor.runTestStep(StepInterceptor.java:409)
    at net.thucydides.core.steps.StepInterceptor.runOrSkipMethod(StepInterceptor.java:150)
    at net.thucydides.core.steps.StepInterceptor.testStepResult(StepInterceptor.java:137)
    at net.thucydides.core.steps.StepInterceptor.intercept(StepInterceptor.java:68)
    at net.serenitybdd.screenplay.rest.interactions.Post$$EnhancerByCGLIB$$6437c6d9.performAs(<generated>)
    at net.serenitybdd.screenplay.Actor.perform(Actor.java:100)
    at net.serenitybdd.screenplay.Actor.attemptsTo(Actor.java:84)
    at jarv.serenity.carnival.features.steps.steps.RecoverUserNameSteps.he_attemps_to_recover_password(RecoverUserNameSteps.java:40)
    at ✽.he sends the required information to recover his password(src/test/resources/features/ProfileManagement.feature:7)

我有以下测试步骤:

package jarv.serenity.carnival.features.steps.steps;
import net.serenitybdd.screenplay.rest.abilities.CallAnApi;
import net.serenitybdd.screenplay.rest.interactions.Post;
import cucumber.api.java.Before;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import net.serenitybdd.screenplay.Actor;
import static org.hamcrest.Matchers.equalTo;
import static net.serenitybdd.screenplay.rest.questions.ResponseConsequence.seeThatResponse;

public class RecoverUserNameSteps {

    private String theRestApiBaseUrl = "https://www.carnival.com/ProfileManagement/api/v1.0";
    private Actor jorge;
    private String userName;

    @Before
    public void set_the_test(){
        jorge = Actor.named("Jorge, learning serenity rest").whoCan(CallAnApi.at(theRestApiBaseUrl));
    }

    @Given("^Jorge is not a registered user$")
    public void jorge_is_not_registered() throws Throwable {
        //TODO: Investigate what should be done here???
    }

    @Given("^he wants to recover his password$")
    public void jorge_wants_to_recover_the_password() throws Throwable {
        //I am setting this as blank cause the service to retrieve the password will only failed if request parameter is blank!!!
        //When sending any other kind of string response is 202 Accepted, only blanks generate 400 Bad request
        //Test may need to be changed to recover username instead, which has more options to get the error code
        userName = "";
    }

    @When("^he sends the required information to recover his password$")
    public void he_attemps_to_recover_password() throws Throwable {
        //TODO: Create Object Model for Request Body and send it. Anyway example is way too simple to do that and I am running out of time Julian.
        jorge.attemptsTo(
                Post.to("/Accounts/Password/Forgot")
                        .with(request -> request.header("Content-Type", "application/json")
                                .body("{\"username\": \"joe\"}")
                        )
        );
    }

    @Then("^he should be informed that operation could not be done$")
    public void he_must_see_a_failed_response() throws Throwable {
        jorge.should(
                seeThatResponse( "Recover for password was denied",
                        response -> response.statusCode(400)
                )
        );
    }
}

这是我与其他相关依赖的maven

<dependency>
            <groupId>net.serenity-bdd</groupId>
            <artifactId>serenity-rest-assured</artifactId>
            <version>2.0.34</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>net.serenity-bdd</groupId>
            <artifactId>serenity-screenplay-rest</artifactId>
            <version>2.0.34</version>
            <scope>test</scope>
</dependency>

这是我的fork github repo:qazxsw poi

对此有什么想法?

java rest cucumber serenity-bdd
1个回答
1
投票

因为您没有使用匹配的https://github.com/jarvcol/CarnivalTest/tree/addApiTesting依赖项。尝试在serenity-core中添加以下依赖项并更新项目:

pom.xml
© www.soinside.com 2019 - 2024. All rights reserved.