1

我有一个邮递员集合,其中包含每个请求的请求和测试用例。每个请求我有两个测试用例。一个用于验证状态代码,另一个用于验证响应时间。我需要经常执行状态代码测试用例和偶尔响应时间测试用例结果。如何在不修改每次运行的集合的情况下实现它,是否可以在终端中提供任何选项?

集合.json

                {
                    "name": "Metadata",
                    "item": [
                        {
                            "name": "info",
                            "event": [
                                {
                                    "listen": "test",
                                    "script": {
                                        "id": "32cf67e7-5d42-4231-86fe-e7fffa32c855",
                                        "exec": [
                                            "pm.test(\"Status code is 200\", function () {",
                                            "    pm.response.to.have.status(200);",
                                            "});",
                                            "pm.test(\"Response time is less than 300ms\", function () {",
                                            "    pm.expect(pm.response.responseTime).to.be.below(300);",
                                            "});"
                                        ],
                                        "type": "text/javascript"
                                    }
                                }
                            ],
                            "request": {
                                "auth": {
                                    "type": "bearer",
                                    "bearer": [
                                        {
                                            "key": "token",
                                            "value": "{{tokenAdmin}}",
                                            "type": "string"
                                        }
                                    ]
                                },
                                "method": "GET",
                                "header": [],
                                "url": {
                                    "raw": "{{url}}/api/m0/metadata/info",
                                    "host": [
                                        "{{url}}"
                                    ],
                                    "path": [
                                        "api",
                                        "m0",
                                        "metadata",
                                        "info"
                                    ]
                                }
                            },
                            "response": []
                        }
                    ],
                    "protocolProfileBehavior": {},
                    "_postman_isSubFolder": true
                }


4

1 回答 1

0

对于一个非常基本的流程,您可以使用moment它来检查当前是哪一天,如果符合条件,它将运行responseTime测试。

let moment  = require('moment'),
    date    = moment().format('dddd');

// Runs on each request
pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});

// Only runs on a Friday 
if (date === 'Friday') {
    pm.test("Response time is less than 1000ms", function () {
        pm.expect(pm.response.responseTime).to.be.below(1000);
    });
}

Moment有许多不同的选项可供您使用,如果您只想在 sprint 结束时或在给定的一天运行该检查,它们可能会起作用。

于 2020-05-21T11:06:28.243 回答