使用按钮多次导入同一集合的导入集合-Postman

时间:2018-12-12 14:26:49

标签: html postman postman-collection-runner

我正在使用Postman版本6.6.0,并尝试通过Run in Postman按钮导入API集合。我有一个HTML页面,如下所示:

<div id="hiddenEnv" class="nodisplay highlight highlight-attention">
   <p>
      Click the button below to import into Postman
   </p>
   <p>                        
   <div class="postman-run-button"
      data-postman-action="collection/import"
      data-postman-var-1="abcd"></div>
   <script type="text/javascript">
      (function (p,o,s,t,m,a,n) {
          !p[s] && (p[s] = function () { (p[t] || (p[t] = [])).push(arguments); });
          !o.getElementById(s+t) && o.getElementsByTagName("head")[0].appendChild((
            (n = o.createElement("script")),
            (n.id = s+t), (n.async = 1), (n.src = m), n
          ));
        }(window, document, "_pm", "PostmanRunObject", "https://run.pstmn.io/button.js"));
   </script>        
   </p>
</div>

和js代码:

$(function() {

    var lastEnv;

    function newEnv(name) {
        debugger;
        var env = {
            "id": generateUUID(),
            "name": "MyProject-" + name,
            "values": [{
                    "key": "hostenv",
                    "value": "",
                    "type": "text",
                    "enabled": true
                },
                {
                    "key": "username",
                    "value": "",
                    "type": "text",
                    "enabled": true
                },
                {
                    "key": "password",
                    "value": "",
                    "type": "text",
                    "enabled": true
                }
            ],
            "timestamp": 1544608923,
            "synced": false,
            "syncedFilename": "",
            "team": null,
            "isDeleted": false
        };
        return env;
    }

    $('#enter-creds').on('click', function(ev) {
        var options = {
            "name": "sampleBasicModal",
            "content": $("script#envModal").html(),
            onComplete: function(ev) {
                console.log(ev);
                var modal = $(ev.currentTarget).closest('.modal');
                var form = modal.find('form');
                console.log(form);

                var formArr = form.serializeArray();

                var envName = _.find(formArr, {name: 'hostenv'}).value.split('.')[0];
                var envOutput = newEnv(envName);

                var formObj = {};

                formObj.hostenv = _.find(formArr, {name: 'hostenv'}).value;   
                formObj.username = _.find(formArr, {name: 'username'}).value;
                formObj.password = _.find(formArr, {name: 'password'}).value;     

                if (!_pm('env.create', 'MyProject-' + envName, formObj)) {
                    _pm('env.replace', 'MyProject-' + envName, formObj);
                }

                lastEnv = envOutput;
                $('#shownEnv').remove();
                $('#hiddenEnv').slideDown(750);
            }
        };
        var inst = Olive.modal.show(options);

        ev.preventDefault();
    });
}); 

我可以将我的收藏集导入Postman环境。但是,同一集合会不断添加7至8次。我找不到问题所在!

修改:
我已经检查了几次,然后发现当我有多个环境时会发生此问题。

1 个答案:

答案 0 :(得分:1)

与邮递员团队成员讨论此问题后,他们发现Windows OS的邮递员存在问题,这是报告的链接

Collection getting imported multiple times when using RiP button [Windows]