接口测试自动化框架--V1版本

框架主要技术: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>
  • 4
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 12
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值