gpt4 book ai didi

Blacklisting header in Allure Rest Assured(Allure Reasure中的黑名单标题)

转载 作者:bug小助手 更新时间:2023-10-25 15:17:01 29 4
gpt4 key购买 nike



I'm currently working with Allure reports to capture the results of my Rest Assured tests, and I've encountered a challenge.

我目前正在使用Allure Reports来捕获我的放心测试的结果,我遇到了一个挑战。


Specifically, I'm having trouble filtering or blacklisting the header information. When I use the .filters(new AllureRestAssured()) method, it logs all the header details in the Allure reports.

具体来说,我有麻烦过滤或列入黑名单的标题信息。当我使用.filters(新的AllureRestAssured())方法时,它会在Allure报告中记录所有标题细节。


Could someone kindly provide some guidance or insights into this issue? I would greatly appreciate any assistance you can offer.

有没有人能就这个问题提供一些指导或见解?如果您能提供任何帮助,我将不胜感激。


Thank you in advance for your help.

首先要感谢您的帮助。


I have created a separate class and overriding the filter method.

我已经创建了一个单独的类并覆盖了Filter方法。


import io.restassured.filter.Filter;
import io.restassured.filter.FilterContext;
import io.restassured.response.Response;
import io.restassured.specification.FilterableRequestSpecification;
import io.restassured.specification.FilterableResponseSpecification;

public class BlacklistHeaderFilter implements Filter {

private final String[] blacklistedHeaders;

public BlacklistHeaderFilter(String... blacklistedHeaders) {
this.blacklistedHeaders = blacklistedHeaders;
}

@Override
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
for (String header : blacklistedHeaders) {
requestSpec.removeHeader(header);
}
return ctx.next(requestSpec, responseSpec);
}
}

However, when I call as below as part of request secification
.filters(new AllureRestAssured())
.filters(new BlacklistHeaderFilter( "Authorization"))

然而,当我调用以下内容作为请求规范的一部分时,.Filters(new AllureRestAssured()).Filters(new BlacklistHeaderFilter(“Authorization”))


The request fails as the headers get removed before making the call

请求失败,因为在进行调用之前头被删除


更多回答

This behavior is expected. To overcome this, try to override the AllureRestAssured class then mask the request header in log, not remove it from requestSpec

这是意料之中的行为。要解决此问题,请尝试覆盖AllureRestAssured类,然后在日志中屏蔽请求标头,而不是将其从questSpec中删除

优秀答案推荐
更多回答

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com