利用 Postman 导出Python、JAVA、PHP、javaScript、swift、Go、OC等多门语言的测试脚本来进行接口测试

目录

1、Postman 语言导出操作

2、使用Postman导出的Python脚本语言结合数据驱动来完成接口测试


Postman 能导出各种不同的语言,可以根据自己最熟悉的语言来进行导出操作,从而进行接口自动化测试,同时也方便后期的二次开发工作。

各个版本的Python环境安装参考:https://blog.csdn.net/xiao66guo/article/details/98338083     (MAC、Windows自动化测试+Appium+Python依赖环境最全安装和配置)

1、Postman 语言导出操作

第一步:

第二步:

整体操作演示:

2、使用Postman导出的Python脚本语言结合数据驱动来完成接口测试

# -*- coding:utf-8 -*-
__author__ = 'xiaoguo'

import requests
import unittest

class APITestCase(unittest.TestCase):

    def test_api(self):
        url = "https://www.v2ex.com/api/nodes/show.json"
        # 由于传递的参数是固定的,没有实现数据的驱动
        # querystring = {"name": "java"}
        headers = {
            'cache-control': "no-cache",
            'Postman-Token': "e1cf7279-c5ea-453a-8806-ac72ce2b4bc4"
        }
        # 数据驱动
        for test_name in ['java', 'ios', 'python', 'php']:
            print(test_name)
            responseData = requests.request('GET', url, headers=headers, params={'name': test_name}).json()
            self.assertEqual(responseData['name'], test_name)

if __name__ == '__main__':
    unittest.main()

执行结果:

发布了36 篇原创文章 · 获赞 63 · 访问量 9662

猜你喜欢

转载自blog.csdn.net/xiao66guo/article/details/103163356
今日推荐