做接口测试经常会遇到如下两种情况需要处理数据传递
- 接口间的数据依赖,A接口请求的参数需要用到B接口的返回值
- 接口请求通常要用到鉴权的接口获取Token,Token通常会跟其他接口构成一对多的关系,这种情况下我们可以把Token的接口做成一个公共的TestCase,供其他的TestCase调用
1.接口间数据传递
![](https://img2018.cnblogs.com/blog/1372698/201901/1372698-20190102173113938-183249067.png)
-
解决方法
1.增加测试步骤properties用来存放A接口返回值的数据
![](https://img2018.cnblogs.com/blog/1372698/201901/1372698-20190102173425436-1923809592.png)
2.测试步骤properties增加变量
![](https://img2018.cnblogs.com/blog/1372698/201901/1372698-20190102173624021-1407408524.png)
3.增加测试步骤Property Transfer
![](https://img2018.cnblogs.com/blog/1372698/201901/1372698-20190102173755772-403173535.png)
4.Property Transfer关联数据到properties
![](https://img2018.cnblogs.com/blog/1372698/201901/1372698-20190102174215525-2047553095.png)
5.B接口引用properties存储的A接口的返回值
![](https://img2018.cnblogs.com/blog/1372698/201901/1372698-20190102174937516-997706528.png)
2.TestCase间数据传递
![](https://img2018.cnblogs.com/blog/1372698/201901/1372698-20190102194543727-2012271912.png)
-
解决方法
1.给TestCase-customer_1增加propertis保存返回值
![](https://img2018.cnblogs.com/blog/1372698/201901/1372698-20190102194937795-588183797.png)
2.增加测试步骤Property Transfer
![](https://img2018.cnblogs.com/blog/1372698/201901/1372698-20190102195224991-719275798.png)
![](https://img2018.cnblogs.com/blog/1372698/201901/1372698-20190102195806783-1943282981.png)
3.右键点击测试用例add_contract,新增Run testCase
![](https://img2018.cnblogs.com/blog/1372698/201901/1372698-20190102200121207-566096819.png)
4.TestCase_addcontract引用TestCase-add_customer的返回值
![](https://img2018.cnblogs.com/blog/1372698/201901/1372698-20190102202337607-1540766999.png)
![](https://img2018.cnblogs.com/blog/1372698/201901/1372698-20190102202024726-1650663295.png)