Forum Discussion

dcfecker's avatar
dcfecker
Contributor
7 years ago
Solved

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 

2 Replies

  • NisHera's avatar
    NisHera
    Valued Contributor

    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 

    • dcfecker's avatar
      dcfecker
      Contributor

      Great solution. It's funny, but I've been looking for a way to change the timeout on my Finds. I wonder why I never saw the FindEx or FindChildEx in any of my searches.

       

      Your solution worked great! Thanks