eric_robinson
14 years agoOccasional Contributor
Setting a timeout value for Exists method
I would like to use the Exists function to determine if a message box has appeared or not and if so, click the yes button so the document can continue loading. The message box won't always appear so I can't just wait around for it before checking a property on another window that would mean the document has loaded.
My plan was to loop 150 times and inside the loop, call messageBox.Exists and otherWindow.WaitProperty and have them both time out after 1 second, then loop again. That way, I wait for up to 5 minutes which is enough time for the otherWindow to load which would mean there was not going to be a messageBox since the MessageBox would load first.
for (i = 0; i < 150; i++)
{
if (dlgSoftwareUpdateRecommended.Exists)
{
dlgSoftwareUpdateRecommended.btnYes.ClickButton();
break;
}
//Wait for one second for the window to become focused.
isLoaded = mapWindow.WaitProperty("Focused", "True", 1000);
if (isLoaded)
break;
}
if (!isLoaded)
{
var remainingWaitTime = (150 - i) * 2000
Log.Message(remainingWaitTime, "Remaining time")
//Wait for up to remainingWaitTime for the window to become focused which would mean the document is loaded
isLoaded = mapWindow.WaitProperty("Focused", "True", remainingWaitTime);
}
My problem is, there is no timeout parameters for Exists. I don't want to change the global timeout time to 1 second.
I see there is the ability using a keyword test to change the timeout value for Exists, but that leads to another problem. I want the object I am calling Exists on to be a parameter I pass in to the keyword test, but I can't figure that out. When I use the "If Object" operation, it doesn't let me use a parameter for the operation column. The value column must be "Exists". I would like it to be parametrized so I can reuse the keyword test for other window object.
I am brand new to TestComplete so forgive me if there is an easy solution. But thanks for any input!
My plan was to loop 150 times and inside the loop, call messageBox.Exists and otherWindow.WaitProperty and have them both time out after 1 second, then loop again. That way, I wait for up to 5 minutes which is enough time for the otherWindow to load which would mean there was not going to be a messageBox since the MessageBox would load first.
for (i = 0; i < 150; i++)
{
if (dlgSoftwareUpdateRecommended.Exists)
{
dlgSoftwareUpdateRecommended.btnYes.ClickButton();
break;
}
//Wait for one second for the window to become focused.
isLoaded = mapWindow.WaitProperty("Focused", "True", 1000);
if (isLoaded)
break;
}
if (!isLoaded)
{
var remainingWaitTime = (150 - i) * 2000
Log.Message(remainingWaitTime, "Remaining time")
//Wait for up to remainingWaitTime for the window to become focused which would mean the document is loaded
isLoaded = mapWindow.WaitProperty("Focused", "True", remainingWaitTime);
}
My problem is, there is no timeout parameters for Exists. I don't want to change the global timeout time to 1 second.
I see there is the ability using a keyword test to change the timeout value for Exists, but that leads to another problem. I want the object I am calling Exists on to be a parameter I pass in to the keyword test, but I can't figure that out. When I use the "If Object" operation, it doesn't let me use a parameter for the operation column. The value column must be "Exists". I would like it to be parametrized so I can reuse the keyword test for other window object.
I am brand new to TestComplete so forgive me if there is an easy solution. But thanks for any input!