I support implemented tests framework and can't change version of tools, so need to resolve it with current version. The test framework use RestAssered, Cucumber, Serenity. When tests run in parallel sometimes they are failed due to several Authorization headers in request. In single run, everything is ok. As I know Serenity just reuse features of the framework. So I think, maybe I configured in wrong way RestAssured. My flow is:
- In Before method I set up
@cucumber.api.java.Before
public void beforeScenario(Scenario scenario) {
RestAssured.baseURI = "https://test.net";
RestAssured.requestSpecification = new
Specification().requestSpecificationWithAdminToken(token);
RestAssured.responseSpecification = new Specification().responseSpecification();
RestAssured.config = RestAssuredConfig.config().decoderConfig(decoderConfig().noContentDecoders());
}
public class Specification {
public RequestSpecification requestSpecificationWithAdminToken(String token) {
return new RequestSpecBuilder().
addHeader("Authorization", "Bearer " + token).
setAccept(ContentType.JSON).
setContentType(ContentType.JSON).
log(LogDetail.ALL).
build();
}
public ResponseSpecification responseSpecification() {
return new ResponseSpecBuilder().
log(LogDetail.ALL).
build();
}
}
- Tests like this
SomeBinding bindings = SerenityRest.
given().queryParams(params).
when().get("/api/some/GetEntities").
then().statusCode(HttpStatus.SC_OK).extract().response().as(SomeBinding.class);
- For parallel run I use maven-failsafe-plugin with configuration
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<argLine>-Xmx1024m</argLine>
<includes>
<include>${test.include}</include>
</includes>
<excludes>
<exclude>${test.exclude}</exclude>
</excludes>
<parallel>classes</parallel>
<threadCount>${parallel.count}</threadCount>
<perCoreThreadCount>false</perCoreThreadCount>
<rerunFailingTestsCount>1</rerunFailingTestsCount>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
When I run tests in parallel I faced with issue that sometimes requests contain several Authorithation headers.
Authorization=Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6ImJjYzM3YjliOTM4ODQ3ODJiOWRhYjN
Authorization=Bearer OTM4ODQ3ODJiOWRhYjNmYjI5NDgyYzdjIiwianRpIjoiMjg3M2VjNDA0MmFjNGNkNzk0ODE5NTE0N2I5YzczMjUiL
Accept=application/json, application/javascript, text/javascript, text/json
Content-Type=application/json; charset=UTF-8
Could somebody please give advice how to resolve it?