框架主要技术:maven+java+testng+poi+ExtentReports等
主要实现思想:
数据驱动测试,用Excel来管理数据,‘Input’ Sheet中存放输入数据,读取数据后拼成request 调用service, 拿到response后写入 ‘Output’ Sheet 即实际结果, 实际结果在与期望结果作比较,写入结果表中,测试完成后生成测试报告
1.框架主要结构
2.项目目录
3.项目搭建过程
使用的接口示例地址:https://reqres.in/
3.1准备测试案例和配置文件
src/main/config:主要配置地址config.properties
#HOST = http://10.1.1.xxx:8080/xxxx/
HOST = https://reqres.in/
apidata文件夹下新建1.xls,为接口案例
3.2工具类:
com/qa/util:
testBase读取配置文件、
copyFile:复制apidata,生成结果表
Readexcle/writeexcle:读取与写入excle表
3.3RestClient:封装接口方法
RestClient:封装了基本的post、get、delete、put方法
public class RestClient{
final static Logger Log = Logger.getLogger(RestClient.class);
/**
* 不带请求头的get方法封装
* @param url
* @return 返回响应对象
* @throws ClientProtocolException
* @throws IOException
*/
public CloseableHttpResponse get (String url) throws ClientProtocolException, IOException {
//创建一个可关闭的HttpClient对象
CloseableHttpClient httpclient = HttpClients.createDefault();
//创建一个HttpGet的请求对象
HttpGet httpget = new HttpGet(url);
//执行请求,相当于postman上点击发送按钮,然后赋值给HttpResponse对象接收
Log.info("开始发送get请求...");
CloseableHttpResponse httpResponse = httpclient.execute(httpget);
return httpResponse;
}
/**
* 带请求头信息的get方法
* @param url
* @param headermap,键值对形式
* @return 返回响应对象
* @throws ClientProtocolException
* @throws IOException
*/
public CloseableHttpResponse get (String url,HashMap<String,String> headermap) throws ClientProtocolException, IOException {
//创建一个可关闭的HttpClient对象
CloseableHttpClient httpclient = HttpClients.createDefault();
//创建一个HttpGet的请求对象
HttpGet httpget = new HttpGet(url);
//加载请求头到httpget对象
for(Map.Entry<String, String>