如何通过测试类传递从有效载荷中提取的变量?

如何通过测试类传递从有效载荷中提取的变量?,第1张

如何通过测试类传递从有效载荷中提取的变量

在Citrus中,您可以使用来在整个测试套件之前执行 *** 作

TestDesignerBeforeSuiteSupport
。像这样:

public class SetupAuthTokenBeforeSuite extends TestDesignerBeforeSuiteSupport {    @Override    public void beforeSuite(TestDesigner designer) {        designer.echo("Setting up authentication token");        designer.http()     .client(HttpTqaClient)     .send()     ...        designer.http()     .client(HttpTqaClient)     .receive()     .response(HttpStatus.OK)     .messageType(MessageType.JSON)     .extractFromHeader("Authorization", "header_token")     .extractFromPayload("$.id_token", "payload_token");        designer.action(new AbstractTestAction() { @Override public void doExecute(TestContext testContext) {     testContext.getGlobalVariables().put("global_auth_token", "${payload_token}"); }        });    }}

无论您运行什么测试或从您的测试套件中进行多少测试,Citrus始终会选择并执行这些测试,然后再运行任何测试。您只需要在Citrus上下文中将其配置为bean。

诀窍是使用上面提取的变量的值设置一个 全局变量 。之后,您可以在以下任何测试中使用此变量:

http()     .client(HttpTqaClient)     .send()     .get("/account/api/lk/lk-client/current")     .accept("application/json")     .contentType("application/json")     .header("Authorization", "${global_auth_token}");

我必须问,您使用的是哪个版本的Citrus?建议您使用

TestNGCitrusTestRunner
代替,
TestNGCitrusTestDesigner
因此使用
TestRunnerBeforeSuiteSupport
代替
TestDesignerBeforeSuiteSupport



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5501920.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-13
下一篇 2022-12-12

发表评论

登录后才能评论

评论列表(0条)

保存