接口自动化框架(java)--4.接口Token传递

本文介绍了在接口自动化测试中如何使用Java处理Token的获取。通过JSONPath解析登录接口响应,提取Token,并将其封装为静态方法,方便在测试用例中调用。同时,强调了在不使用testng.xml时,正确设置dependsOnMethods的重要性,以确保Token的有效传递。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一般token会在登录接口返回结果中呈现,从代码层面获取token的方式有很多种,我是使用jsonpath这个json路径语言去匹配token所在路径的key值

我将获取jsonpath写成一个静态方法放在testUtil里面,将jsonpath路径写在配置文件中,在testcase中使用方法时,只需要传入已返回的请求结果和配置文件中的jsonpath路径即可

package com.qa.tests;


import com.alibaba.fastjson.JSON;
import com.qa.base.TestBase;
import com.qa.Parameters.postParameters;
import com.qa.restclient.RestClient;
import com.qa.util.TestUtil;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.testng.Assert;
import org.testng.Reporter;
import org.testng.annotations.*;
import java.io.IOException;
import java.util.HashMap;
import static com.qa.util.TestUtil.dtt;

public class EFPStagingCN extends TestBase {

    TestBase testBase;
    RestClient restClient;
    CloseableHttpResponse closeableHttpResponse
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值