We are building a new experience for our SmartBear Community.
This site is now read-only. You can still browse and search as usual. Learn More
This site is now read-only. You can still browse and search as usual. Learn More
Helen's reply got me thinking... Could we just use the powers of JavaScript directly?
function test()
{
var str = "type1=12345678901234567890111&type2=3.0.00&type3=1234567811";
var strarr = str.split('&');
for (var i = 0; i < strarr.length; i++) {
var typearr = strarr[i].split('=');
Log.Message(strarr[i]);
switch (typearr[0]) {
case 'type1':
Log.Message("TYPE1: length = " + typearr[1].length);
break;
case 'type2':
Log.Message("TYPE2: length = " + typearr[1].length);
break;
case 'type3':
Log.Message("TYPE3: length = " + typearr[1].length);
break;
default:
Log.Message("unrecognized type");
break;
}
}
}
produces
If you have the Desktop module, you can use the .NET https://msdn.microsoft.com/en-us/library/ms150046(v=vs.110).aspx method to convert a query string into a name/value collection. Then you can get the parameter values as CollectionObj.Item(param_name). Note that to be able to use ParseQueryString, you need to add the System.Web assembly from the GAC to Tools > Current Project Properties > CLR Bridge.
Assuming you're using JScript, here's a sample function that shows how to use ParseQueryString and how to check the parameter length. You can call this function from your keyword tests using the Run Script Routine operation.
// JScript
/*
Usage example:
var str = "type1=12345678901234567890111&type2=3.0.00&type3=1234567811";
CheckQueryStringParameterLength(str, "type1", 23);
*/
function CheckQueryStringParameterLength(QueryString, ParamName, ExpectedLength) { var qs = dotNET.System_Web.HttpUtility.ParseQueryString(QueryString); var strValue = qs.Item(ParamName).OleValue;
var length = strValue.length; if (length == ExpectedLength) Log.Checkpoint( aqString.Format("Parameter \"%s\" has the correct length (%d).", ParamName, ExpectedLength), strValue ); else { Log.Error( aqString.Format("Parameter \"%s\" is %d characters long, but should be %d characters.", ParamName, length, ExpectedLength), strValue ); } }
Hi HKosova sorry but what does "GAC" mean?
JBSoccerbrit wrote:
Hi HKosova sorry but what does "GAC" mean?
GAC = https://msdn.microsoft.com/en-us/library/yf1d93sz(v=vs.110).aspx.
When you add .NET DLLs to your TestComplete project (in the project properties > CLR Bridge), there're options to Browse Files (add from the disk) and Browse GAC. To use the example I posted you need to add the System.Web assembly via Browse GAC.