Looking for a better way to activate a button if it exists
For each of my automation tests run, I have to ensure if certain items exist, they are removed, so I can create them new. One is the LongPressableButton indicated in the following code:
longPressableButton = replayMainWindow.aoiShortcutButtonContainer.ContentPresenter5.LongPressableButton;
if (longPressableButton.Exists) {
longPressableButton.ClickR();
replayMainWindow.HwndSource_PopupRoot.PopupRoot.deleteButton.Click();
replayMainWindow.Canvas.Grid.ItemsControl.SurfacebuttonYes.Click();
}
Problem is when running the tests through TestExecute on Jenkins it always fails here with a Time expired error:
16:01:49 [TestComplete] [WARNING] Error: The execution time specified in the command line has expired..
Otherwise running it from the desktop either TestComplete or TestExecute it works (80% of the time, I also get a timeout error sometimes here too).
Any suggestions on how to improve the detection of this button?
Thanks
Exists method dose only wait for project defined waiting time.
hence you don't have individual control of timing.
In your problem it seems it take time for object to be created.
So I think it good to use FindEx method.
Other good thing is it will not fire error message so you can control in the way you need.
you can do some thing like........
longPressableButton = replayMainWindow.aoiShortcutButtonContainer.FindEx("PropName", "PropValue", 10, True, 5000) if (longPressableButton.Exists) { longPressableButton.ClickR(); replayMainWindow.HwndSource_PopupRoot.PopupRoot.deleteButton.Click(); replayMainWindow.Canvas.Grid.ItemsControl.SurfacebuttonYes.Click(); } else {Log.Warning('LongPressable not exist going for next button')}
Remember to replace propName and PropValue with actual property and values of button