邮递员:是否可以根据先决条件脚本中检测到的条件停止执行邮递员调用? [英] Postman: Is it possible to stop a postman call from being executed based on conditions detected in pre-requisite scripts?

查看:36
本文介绍了邮递员:是否可以根据先决条件脚本中检测到的条件停止执行邮递员调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在第一次调用中使用预请求脚本为整个脚本动态生成必要的环境变量.我还希望用户在通过集合运行器运行时收到这些故障的通知,而无需查看控制台.是否可以在测试或其他替代方法中生成信息,以便在收集运行程序结果中明确显示失败?

I am using the pre-request script in the first call to dynamically generate essential environment variables for the entire script. I also want the users to be notified of those failures when running via collection runner without having to look up to the console. Is it possible to generate information in tests or some other alternative so failures are explicit in the collection runner results?

例如如果环境中没有提供ip,那么运行登录调用是没有意义的.所以我想写一个先决条件的脚本:

e.g. if the ip has not been provided in the environment, it does not make sense to run the login call. So i would like to write in a pre-requisite script:

if (!environment['IP']) {
    //do not execute any further and do not send the REST call
}

我尝试使用:

if (!environment["xyz"]) {
    tests["condtion1"]=false
}

但它给出了错误:

There was an error in evaluating pre-requisite script: tests is not defined

是否有任何解决方法 - 我不想将此代码移动到测试选项卡,因为我不想在不相关的环境条件下使代码混乱.

Is there any workaround - I don't want to move this code to the tests tab as I don't want to clutter the code there with unrelated environment conditioning.

推荐答案

throw 工作正常.(更新了@Joe White 的精彩提示)

A throw works just fine. (Updated with excellent tip from @Joe White)

if (!environment['X']) {
    throw new Error('No "X" set')
}

这会阻止 REST 调用通过.但是在收集运行器模式下,它会停止整个测试套件.

This prevents the REST call from going through. But in the collection runner mode it stops the entire test suite.

但是当与 newman collection runner 结合使用时,它工作得很好.

But when coupled with newman collection runner it works just fine.

这篇关于邮递员:是否可以根据先决条件脚本中检测到的条件停止执行邮递员调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆