自学内容网 自学内容网

ChatGPT与Postman协作完成接口测试(二)

    ChatGPT生成的Postman接口测试用例脚本如下所示。

ChatGPT生成的Postman接口测试用例脚本

以下是符合Collection v2.1格式要求的 Postman 测试用例脚本,覆盖了正常注册和密码不匹配两种情况的测试:

{

  "info": {

    "_postman_id": "09e63d0d-9a62-4c3b-8a2d-76f352a12312",

    "name": "用户注册接口测试",

    "description": "测试用户注册接口的正常和异常情况",

    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"

  },

  "item": [

    {

      "name": "正常注册",

      "request": {

        "method": "POST",

        "header": [],

        "body": {

          "mode": "urlencoded",

          "urlencoded": [

            {

              "key": "username",

              "value": "testuser",

              "type": "text"

            },

            {

              "key": "password",

              "value": "testpassword",

              "type": "text"

            },

            {

              "key": "passwordConfirm",

              "value": "testpassword",

              "type": "text"

            },

            {

              "key": "firstName",

              "value": "John",

              "type": "text"

            },

            {

              "key": "lastName",

              "value": "Doe",

              "type": "text"

            },

            {

              "key": "address1",

              "value": "123 Main St",

              "type": "text"

            },

            {

              "key": "address2",

              "value": "98765",

              "type": "text"

            },

            {

              "key": "register.x",

              "value": "1.23",

              "type": "text"

            },

            {

              "key": "register.y",

              "value": "4.56",

              "type": "text"

            }

          ]

        },

        "url": {

          "raw": "http://127.0.0.1:1080/cgi-bin/login.pl",

          "protocol": "http",

          "host": [

            "127",

            "0",

            "0",

            "1"

          ],

          "port": "1080",

          "path": [

            "cgi-bin",

            "login.pl"

          ]

        }

      },

      "response": []

    },

    {

      "name": "密码不匹配",

      "request": {

        "method": "POST",

        "header": [],

        "body": {

          "mode": "urlencoded",

          "urlencoded": [

            {

              "key": "username",

              "value": "testuser",

              "type": "text"

            },

            {

              "key": "password",

              "value": "testpassword",

              "type": "text"

            },

            {

              "key": "passwordConfirm",

              "value": "mismatchedpassword",

              "type": "text"

            }

          ]

        },

        "url": {

          "raw": "http://127.0.0.1:1080/cgi-bin/login.pl",

          "protocol": "http",

          "host": [

            "127",

            "0",

            "0",

            "1"

          ],

          "port": "1080",

          "path": [

            "cgi-bin",

            "login.pl"

          ]

        }

      },

      "response": []

    }

  ]

}

您可以将此 Postman 测试用例脚本导入到 Postman 应用程序中,然后执行这些测试用例以验证用户注册接口的正常和异常情况。希望这对您有所帮助!

        从ChatGPT生成的Postman测试用例脚本中,可以看到其覆盖了正常注册和密码不匹配异常注册这两种情况。这符合笔者的预期,所以复制生成的代码,并将其存储到D:\AIBOOK\S_PM_WebTours.json文件中。

  • 接口测试用例评审

       通常情况下,接口测试用例也需要进行测试团队的内部评审,关于评审过程的内容在此不赘述。对已生成的Postman测试用例脚本进行评审,鉴于笔者只想考察正常注册和密码不匹配异常注册这两种情况下接口是否可以正常处理,而生成的Postman测试用例脚本完全满足需求,所以不需要扩展更多的内容。在实际工作中,需酌情处理,先评审ChatGPT生成的Postman测试用例脚本是否达到了预期目标,而后进行处理。

    S_PM_WebTours.json文件的内容如下。

S_PM_WebTours.json文件的内容

{

  "info": {

    "_postman_id": "09e63d0d-9a62-4c3b-8a2d-76f352a12312",

    "name": "用户注册接口测试",

    "description": "测试用户注册接口的正常和异常情况",

    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"

  },

  "item": [

    {

      "name": "正常注册",

      "request": {

        "method": "POST",

        "header": [],

        "body": {

          "mode": "urlencoded",

          "urlencoded": [

            {

              "key": "username",

              "value": "testuser",

              "type": "text"

            },

            {

              "key": "password",

              "value": "testpassword",

              "type": "text"

            },

            {

              "key": "passwordConfirm",

              "value": "testpassword",

              "type": "text"

            },

            {

              "key": "firstName",

              "value": "John",

              "type": "text"

            },

            {

              "key": "lastName",

              "value": "Doe",

              "type": "text"

            },

            {

              "key": "address1",

              "value": "123 Main St",

              "type": "text"

            },

            {

              "key": "address2",

              "value": "98765",

              "type": "text"

            },

            {

              "key": "register.x",

              "value": "1.23",

              "type": "text"

            },

            {

              "key": "register.y",

              "value": "4.56",

              "type": "text"

            }

          ]

        },

        "url": {

          "raw": "http://127.0.0.1:1080/cgi-bin/login.pl",

          "protocol": "http",

          "host": [

            "127",

            "0",

            "0",

            "1"

          ],

          "port": "1080",

          "path": [

            "cgi-bin",

            "login.pl"

          ]

        }

      },

      "response": []

    },

    {

      "name": "密码不匹配",

      "request": {

        "method": "POST",

        "header": [],

        "body": {

          "mode": "urlencoded",

          "urlencoded": [

            {

              "key": "username",

              "value": "testuser",

              "type": "text"

            },

            {

              "key": "password",

              "value": "testpassword",

              "type": "text"

            },

            {

              "key": "passwordConfirm",

              "value": "mismatchedpassword",

              "type": "text"

            }

          ]

        },

        "url": {

          "raw": "http://127.0.0.1:1080/cgi-bin/login.pl",

          "protocol": "http",

          "host": [

            "127",

            "0",

            "0",

            "1"

          ],

          "port": "1080",

          "path": [

            "cgi-bin",

            "login.pl"

          ]

        }

      },

      "response": []

    }

  ]

}

  • 接口测试用例迭代与完善

        如果想要完善接口测试用例,可以依据笔者前面使用的方法,让ChatGPT继续完善测试用例,如关键字过长、特殊字符等接口测试用例。限于篇幅,这里不考虑这些内容。S_PM_WebTours.json文件就是最终的Postman接口测试用例脚本。

未完待续


原文地址:https://blog.csdn.net/tony2yy/article/details/144681605

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!