一般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