Mo0rBy
Mo0rBy

Reputation: 660

Serenity Screenplay - How to add another ability to an actor later in a test?

I'm using Serenity Screenplay + Cucumber in my test framework. I understand what an Actor is and what Abilities are and that Actor's can be setup to be allowed to perform certain actions (like calling an API).

In my Cucumber feature file, I have 2 Given steps, both stating that the Actor can CallAnApi at 2 different endpoints:

  1. Given User can call an API at service A
  2. And User can call an API at service B (Note that this step is performed immediately after the 1st Given step)

Both of these steps are written like this: actor.can(CallAnApi.at(<serviceBaseUri>));

I ran the tests and found that my POST request was being sent to ServiceB, not service A, despite the fact that I explicitly define the BaseUri for service A in my POST request:

        File jsonPayload = new File(<FilePathToExampleJsonPayload>);
        String serviceA_Baseurl = <BaseUrlHere>;
        actor.attemptsTo(
            Post.to(<APIEndpoint>)
                    .with(request -> request
                        .baseUri(serviceA_Baseurl)
                        .body(jsonPayload))
        );

Now my guess is that the 2nd Given statement, in which Serenity is told the Actor can perform an API call to service B, overwrites the 1st Given statement that states that the Actor can call an API at service A. Is there a way to ADD abilities to an Actor that already exists without overwriting the Actor's current abilities? (This would be the preferred option)

My other option is to have the abilities defined in a single Given step, but that would make my framework much less flexible and maintainable as I'd require a custom Given step for almost every test. I have around 15 services (with more coming in the future) and each test will require me to allow an Actor to access whichever services are needed for the test.

Upvotes: 0

Views: 674

Answers (1)

Tagira
Tagira

Reputation: 31

in similar situation we decided that our actors have the ability to CallAnApi.at(""), and for the calls we use the full path, i.e. Post.to("https://serviceA.domain/path"), Get.resource("https://serviceB.domain/path"). Maybe not the most elegant solution, but so far the only one we found suitable.

Upvotes: 1

Related Questions