在Postman中使用多次/表单数据点击方法的上传文件的预请求脚本2次 [英] Pre request script of upload file with multipart/form-data hitting method 2 times in Postman

查看:552
本文介绍了在Postman中使用多次/表单数据点击方法的上传文件的预请求脚本2次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理API项目,并与Postman一起编写测试用例,以实现自动化以检查API状态。在这里,我有一个上传方法,用户必须将文件上传到服务器,并需要检查服务器是否返回适当的响应。

I'm working with API project and writing test cases with Postman for automation to check API status. Here I have one upload method in which user has to upload a file to the server and need to check if the server returns an appropriate response.

Upload方法接受带有来自邮递员的multipart / form-data,我在下面的屏幕上通过:

Upload method accepting the request with multipart/form-data, from Postman I'm passing as below screen:

我相信,要编写一个测试用例,我需要编写一个请求前脚本。

I believe that in order to write a test case, I need to write a pre-request script.

pm.sendRequest({
    url: pm.environment.get("baseURL") + '/document/upload',
    method: 'POST',
    header: [{
        "key": "Authorization",
        "value": pm.environment.get("authorization"),
        "type": "text",
    }],
    body: {
        mode: 'formdata',
        formdata: [{
            "key": "file",
            "type": "binary",
            "src": "C:\Users\Desktop\api.pdf"
        }]
    }
}, function(err, res) {
    console.log(res);
}); 

但是,该方法被击中两次,是否有任何想法使其正确并且仅被击中一次?

However, the method is getting hit two times, any thoughts to make it correct and hit only once?

推荐答案

我仔细阅读了文档,发现问题出在哪里。我在使用Runner运行收集程序时遇到了问题,在寻找了一种处理文件上传的方法之后,我终于来到了纽曼,在这种情况下,这似乎很容易。但是,仍不清楚如何在使用Runner运行时上传文件!

I have gone through the docs and figured it out that what is the issue. I was facing issue while running collection using Runner, after searching out a way to handle file uploading, I came to Newman finally, which seem easy for such scenarios. However, it's still unclear how to upload file while running using Runner!

根据上述评论:


出于安全原因,邮递员赛跑者没有不支持直接上传
的文件。查找Github线程
此处

这篇关于在Postman中使用多次/表单数据点击方法的上传文件的预请求脚本2次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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