cancel
Showing results for 
Search instead for 
Did you mean: 

Ignore object in TestComplete if it is not on screen?

mcaffrey
New Contributor

Ignore object in TestComplete if it is not on screen?

I'm trying to write a module in python that opens menu items, and closes them in a .NET application. For some menu items, closing the window triggers an alert box. When I put the object into TestComplete it tries to find it even when it's not on screen causing my test to fail. Here's an example:

 

def MyTest():

  # Objects mapped in TestComplete, and a list of items to click

  mainPage = Sys.Process("MyApplication").WinFormsObject("MyApp")

  alertBox = Sys.Process("MyApplication").WinFormsObject("AlertBox")

  items = ['Item1', 'Item2', 'Item3', 'Item4']

 

  # Open each item, and close it with hotkey. If the alertbox is visible click 'Yes' to close. 

  for i in range(0, len(items)):

    mainPage.Click(items(i))

    mainPage.Keys("[Esc]")

    if alertBox.Visible:

      alertBox.Click("Yes")

 

I've tried setting the Alert Box to visible, onscreen, and exists. If it's not on the screen the test fails. Does anyone know how to get around this? My actual script involves close to a dozen menu items, and a few dozen sub-items so adding in the Alert box to each one is tedious along with making it difficult to maintain since the Alert Box can be in different menus. Anyone know a way how to get TestComplete to ignore an object if it's not onscreen?

 

I don't understand why it keeps trying to find it. Even if I only click items without the alert box it still fails since it keeps trying to find the object.

4 REPLIES 4
Marsha_R
Community Hero

Re: Ignore object in TestComplete if it is not on screen?

Well, it's looking because you told it to.  Once you say If Visible, TC is going to hunt that box down and it either finds it or says sorry couldn't find it and gives up.   

 

What I would do is give TC explicit instructions on what to do if it can't find the box. So, something like (I don't know your syntax so you will have to fix that)

 

if alertBox.Visible:

      alertBox.Click("Yes")

else

      log.message ("no alert box this time")

 

 

 

 

AlexKaras
Community Hero

Re: Ignore object in TestComplete if it is not on screen?

Hi,

 

Refer, for example, to https://community.smartbear.com/t5/TestComplete-General-Discussions/Unable-to-handle-the-error-using... for the explanation of the difference between .WinFormsObject() and .WaitWinFormsObject().

In your case you need to correct the following:

a) Check/wait for the alert box to appear using .WaitXXX() call;

b) Check if alert box exists by checking its .Exists property;

c) Optionally, if needed, you may check if alert box is visible on screen (.Visible property);

d) Proceed as required according to the above verification result.

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
tristaanogre
Community Hero

Re: Ignore object in TestComplete if it is not on screen?

What @AlexKaras said. 😉

Basically, when looking for ANY object that may or may not be exist and there's no guarentee of it, you should be using the appropriate WaitNNN commands to do so.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
mcaffrey
New Contributor

Re: Ignore object in TestComplete if it is not on screen?

I ended up using this solution before seeing your reply, and it worked. Thank you.

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors