LoadRunner a Transaction contains redirection problems

When users log in or access restricted resources, they often encounter redirection. In this case, a Trasaction of LoadRunner will include two or even more requests. How to split it?

Use the following configuration (LR12.5 provides JS to write Web-HTTP/HTML scripts, and my mother no longer has to worry that I will vomit when I look at C):
web.setOption("MaxRedirectionDepth", "0");


then write a loop
lr.saveString('http//redirect.com','location');
	var httpResult ="";
	var i = 0;
web.setOption("MaxRedirectionDepth", "0", "LAST");
	do {
		lr.message("Start---->");
	

		web.regSaveParamEx({
			paramName : 'httpCode',
			lb : 'HTTP/1.1 ',
			rb : ' ',
			notFound : 'warning',
			scope : 'Headers'
		});
		web.regSaveParamEx({
			paramName : 'location',
			lb : 'Location: ',
			rb : '\r\n',
			notFound : 'warning',
			scope : 'Headers'
		});
		var transactionName ='tt'+i;
		lr.message(transactionName);
		lr.startTransaction(transactionName);
		lr.message("Visiting URL: " + reqURL);
		web.url({
			name : 'idm' + i,
			url : '{location}',
			recContentType : 'text/html'
		});
		lr.message("Redirect URL is: " + lr.evalString("{location}"));
		httpResult = lr.evalString("{httpCode}");
		lr.endTransaction(transactionName, lr.AUTO)
		i++;
		lr.message("END<----");
	} while (httpResult == "302");



The principle is that once you find that the HTTP response code is 302, you can parse the response header, find the place to jump, save it, and do it in a loop.

In addition, the following API can be used to directly obtain the return code of the last HTTP request, without having to match and parse it every time:
web.getIntProperty(web.HTTP_INFO_RETURN_CODE);


In addition, there is a problem with the parsing of JS code: web.setOption("MaxRedirectionDepth", "0") in LR12.5. I just asked the LR Team yesterday. It is a problem with JS support. JS is just a skin on the outside. , the implementation inside is actually the C thing that is called, and as a result, there is a BUG when implementing this API. Only web.setOption("MaxRedirectionDepth", "0", "LAST")

is supported in API implementation .

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326762200&siteId=291194637