Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Automated tests 邮递员中的请求重用_Automated Tests_Postman_Postman Collection Runner - Fatal编程技术网

Automated tests 邮递员中的请求重用

Automated tests 邮递员中的请求重用,automated-tests,postman,postman-collection-runner,Automated Tests,Postman,Postman Collection Runner,我们的团队希望自动化RESTAPI测试。现在,我们有一组邮递员请求,让他们手动跳转 我们可以为每个测试场景创建一个集合/文件夹,但这将意味着大量重复。我们的API仍在大力开发中,我真的不想在更改后在20个地方修复同样的东西 我希望每个端点请求在一个集合中只出现一次,并且有某种独立的逻辑可以按任意顺序执行它们。我对邮递员了如指掌,因此我正在寻找至少一种黑客方法来实现这一点。创建一个文件,以加载到邮递员集合运行程序中,其结构如下: [{ "testSequence": ["First req

我们的团队希望自动化RESTAPI测试。现在,我们有一组邮递员请求,让他们手动跳转

我们可以为每个测试场景创建一个集合/文件夹,但这将意味着大量重复。我们的API仍在大力开发中,我真的不想在更改后在20个地方修复同样的东西


我希望每个端点请求在一个集合中只出现一次,并且有某种独立的逻辑可以按任意顺序执行它们。我对邮递员了如指掌,因此我正在寻找至少一种黑客方法来实现这一点。

创建一个文件,以加载到邮递员集合运行程序中,其结构如下:

[{
    "testSequence": ["First request name", "Second request name", "..." ],
    "anyOtherData":  "Whatever the request needs",
    "evenMoreData":  "Whatever the request needs",
    "...":           "..."
},{
    "testSequence": ["Login", "Check newsfeed", "Send a picture", "Logout" ],
    "username":  "Example",
    "password":  "correcthorsebatterystaple",
},{
    "...": "keep the structure for any other test scenario or request sequence"
}]
将所有测试序列放在该文件中,然后让邮递员在每个请求后检查列表,并决定下一步执行什么。这可以通过电子邮件来完成。G在整个集合的测试块中:

// Use the mechanism only if there is a test scenario file
// This IF prevents the block from firing when running single requests in Postman
if (pm.iterationData.get("testSequence")) {

    // Is there another request in the scenario?
    var sequence = pm.globals.get("testSequence");
    if ((sequence instanceof Array) && (sequence.length > 0)) {

        // If so, set it as the next one
        var nextRequest = sequence.shift();
        pm.globals.set("testSequence", sequence);
        postman.setNextRequest(nextRequest);

    } else {
        // Otherwise, this was the last one. Finish the execution.
        postman.setNextRequest(null);
    }
}

如果您的请求在不同的运行期间需要使用不同的数据,您可以在输入文件中定义数据,并在请求中使用这些数据。

创建一个文件以加载到Postman Collection Runner中,其结构如下:

[{
    "testSequence": ["First request name", "Second request name", "..." ],
    "anyOtherData":  "Whatever the request needs",
    "evenMoreData":  "Whatever the request needs",
    "...":           "..."
},{
    "testSequence": ["Login", "Check newsfeed", "Send a picture", "Logout" ],
    "username":  "Example",
    "password":  "correcthorsebatterystaple",
},{
    "...": "keep the structure for any other test scenario or request sequence"
}]
将所有测试序列放在该文件中,然后让邮递员在每个请求后检查列表,并决定下一步执行什么。这可以通过电子邮件来完成。G在整个集合的测试块中:

// Use the mechanism only if there is a test scenario file
// This IF prevents the block from firing when running single requests in Postman
if (pm.iterationData.get("testSequence")) {

    // Is there another request in the scenario?
    var sequence = pm.globals.get("testSequence");
    if ((sequence instanceof Array) && (sequence.length > 0)) {

        // If so, set it as the next one
        var nextRequest = sequence.shift();
        pm.globals.set("testSequence", sequence);
        postman.setNextRequest(nextRequest);

    } else {
        // Otherwise, this was the last one. Finish the execution.
        postman.setNextRequest(null);
    }
}

如果您的请求在不同的运行期间需要使用不同的数据,您可以在输入文件中定义数据,并在请求中使用这些数据。

是您使用的集合和子文件夹元素。引入这些功能是为了停止在您的请求中反复重复相同的内容,并将其提取到中心区域。它不会解决您的所有用例,但可能会有所帮助-集合和子文件夹元素对您很有用。引入这些功能是为了停止在您的请求中反复重复相同的内容,并将其提取到中心区域。它不会解决您的所有用例,但可能会有所帮助-运行JavaScript代码的唯一方法是执行请求。因此,我需要执行一个无关的请求来执行JavaScript,以加载测试序列和序列集的第一个请求。你有没有找到一种更优雅的方式来处理这个问题而不需要额外的请求?我们通常在第一个请求时运行一些没有副作用的东西,比如/ping。这不是很优雅,但是完成了任务。嗨,我最后做了类似的事情。我的第一个和最后一个请求只是加载谷歌。我使用它们作为测试启动和拆卸,在这里我做一些日志记录,设置/取消设置收集变量,等等。。。我希望有一天Postman会允许将js与请求分开运行,尽管运行JavaScript代码的唯一方法是执行请求。因此,我需要执行一个无关的请求来执行JavaScript,以加载测试序列和序列集的第一个请求。你有没有找到一种更优雅的方式来处理这个问题而不需要额外的请求?我们通常在第一个请求时运行一些没有副作用的东西,比如/ping。这不是很优雅,但是完成了任务。嗨,我最后做了类似的事情。我的第一个和最后一个请求只是加载谷歌。我使用它们作为测试启动和拆卸,在这里我做一些日志记录,设置/取消设置收集变量,等等。。。我希望有一天邮递员会允许将js与请求分开运行