在测试脚本中获取文件夹名称 [英] Obtain folder name in test script

查看:129
本文介绍了在测试脚本中获取文件夹名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Postman编写API测试。我正在按端点将它们组织到文件夹中,并根据测试用例将它们归入端点文件夹中的子文件夹中。每个端点都有多种情况,每种情况下都有后调用,这些后调用会在我要声明的csubject-endpoint调用之前设置数据。

I'm writing API tests using Postman. I'm organizing them into folders by endpoint, and subfolders by test cases within the endpoint folders. There are multiple cases for each endpoint and for each case there are post calls that set up data prior the the csubject-endpoint call that I'm making assertions against.

此套件中已经有100个电话。不幸的是,测试运行程序未在其输出中提供文件夹名称,因此很难一目了然地看到我正在查看的特定情况,例如,它报告测试失败。

I already have 100s of calls in this suite. The test runner, unfortunately, does not provide the folder names in its output, so it's difficult to see at a glance which particular case I am looking at when, for example, it reports a test fail.

是否有一种方便的方法来在其测试脚本中获取给定呼叫的文件夹名称?这样,我可以在案例名称前加上测试名称,这将使我的测试更具可读性。

Is there a convenient way to obtain the folder names for a given call in its test script? With this, I could prepend the case name to the test name, and that would make my tests vastly more readable.

推荐答案

I不要以为应用程序中有类似的东西-我可以看到的壁橱是 pm.info.requestName 函数,该函数引用测试所属的请求名称

I don't think that there is anything like that from within the application - The closet I can see is the pm.info.requestName function which references the request name that the test belongs too.

这是一个基本用例,但是您可以将其添加到测试名称中,以快速浏览一下,并针对请求执行了什么操作。

This is a basic use case but you could add this to the test name to give you a 'quick glance' and what was run against what request.

pm.test(`${pm.info.requestName} - Status code is 200`, () => {
    pm.response.to.have.status(200)
})

< a href = https://i.stack.imgur.com/DYkrC.png rel = nofollow noreferrer>

如果您看看纽曼可能有些机智可以在脚本中提取摘要对象的后面,以获取文件夹名称,但我从未这样做过。

If you take a look at Newman it might have something within the summary object that you could extract, in a script, to get the folder name but I've never done this.

这篇关于在测试脚本中获取文件夹名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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