chriscc
3 years agoContributor
Hi NisHera , TestQA1 , MLoetscher
I seen this post and thought it might be addressed with a function. I wrote it in jscript/javascript, so it might need translated if using other languages.
It allows you to define arrays for the propNames, propValues. Of course, you might want to compare different properties differently, so it has an array to specify those too. Additionally you might want to specify different case sensitivity and waitTimes for each property. If you don't provide a comparator, case sensitivity, or wait time then it will use default values (cmpEqual, true and 1000 ms respectively).
A test function is provided below this code...just specify your object and arrays.
I hope this helps.
function waitForProperties(obj, propNames, propValues, propCompareOperators, caseSensitives, waitTimes)
{
try
{
if (obj == null)
throw new Error("obj not valid");
if (propNames == null)
throw new Error("propNames not valid");
if (propValues == null)
throw new Error("propValues not valid");
if (propNames.length != propValues.length)
throw new Error("propNames and propValues lengths not equal");
for (var i = 0; i < propNames.length; i++)
{
if (!aqObject.IsSupported(obj, propNames[i]))
throw new Error("property not supported", propNames[i]);
var passedPropValue = propValues[i];
var objPropValue = aqObject.GetPropertyValue(obj, propNames[i]);
var comparer = cmpEqual;
// what operator do we have
if (propCompareOperators != null && propCompareOperators[i] != null)
comparer = propCompareOperators[i];
var caseSensitive = true;
if (caseSensitives != null && caseSensitives[i] != null)
caseSensitive = caseSensitives[i];
var waitTime = 2000;
if (waitTimes != null && waitTimes[i] != null)
waitTime = waitTimes[i];
var sanity = 0;
while (!aqObject.CompareProperty(objPropValue, comparer, passedPropValue, caseSensitive, lmNone))
{
if (sanity > waitTime / 1000)
{
Log.Error("Property didn't validate - objectProperty: " + objPropValue + " passedProperty: " + passedPropValue + " comparer: " + comparer);
break;
}
Delay(waitTime);
sanity++
}
}
}
catch(e)
{
Log.Error("Exception in waitForProperties", e.description);
}
}
function waitForPropertiesTest()
{
var obj = YOUROBJECT;
var propNames = new Array("Exists", "IsOpen", "Index");
var propValues = new Array(true, false, 1);
var propCompareOperators = new Array(cmpEqual, cmpNotEqual, cmpGreaterOrEqual);
var caseSensitives = null; //new Array(false, false, false);
var waitTimes = null; //new Array(5000, 5000, 5000);
waitForProperties(obj, propNames, propValues, propCompareOperators, caseSensitives, waitTimes)
}
Related Content
- 6 years ago
- 8 years ago