Postman Get value of url 请求参数做测试

Postman Get value of url request parameter to do a test

我正在尝试从获取请求参数中获取 url。

如何从环境变量构建请求URL

在预请求脚本中urlwfsservice 和 orderid 是从环境变量中设置的

{{urlwfsservice}}/v1/merchantorders/{{orderId}}/BoardingActivities.updateMerchantToHub.REQUEST/details/

使用时

var urlnew =request.url;
console.log(request.url);

我将此输出作为变量名称而不是实际值或 url

{{urlwfsservice}}/v1/merchantorders/{{orderId}}/BoardingActivities.updateMerchantToHub.REQUEST/details/

我怎样才能得到像下面这样简单的输出url?

var simpleurl = “https://dev-someweburl.com/v1/merchantorders/ZN2aB/BoardingActivities.updateMerchantToHub.REQUEST/details/”;

完成预请求脚本代码

// how to Construct request URL from environment variables
console.log("logging url");
var urlnew =request.url;
console.log(urlnew);
//var url = "https://dev-someweburl.com/v1/merchantorders/ZN2aB/BoardingActivities.updateMerchantToHub.REQUEST/details/";
var retryDelay = 200;
var retryLimit = 5;

function isProcessingComplete(retryCount) {
    pm.sendRequest(urlnew, function (err, response) {
        if(err) {
            // hmmm. Should I keep trying or fail this run? Just log it for now.
            console.log(err);
        } else {
            // I could also check for response.json().results.length > 0, but that
            // would omit SUCCESS with empty results which may be valid
            if(response.json().auditRecords.length === 0) {
                if (retryCount < retryLimit) {
                    console.log('Job is still PENDING. Retrying in ' + retryDelay + 'ms');
                    setTimeout(function() {
                        isProcessingComplete(++retryCount);
                    }, retryDelay);
                } else {
                    console.log('Retry limit reached, giving up.');
                    postman.setNextRequest(null);
                }
            }
        }
    });
}

isProcessingComplete(1);
console.log(pm.variables.replaceIn(pm.request.url.toString()))

您可以使用 replaceIn 方法将变量替换为其实际值。也可以使用下午。因为 pm 是新的 api 或 postman

中的语法