SmartBear Connect 2018
Join us at SmartBear Connect 2018 on October 29th & 30th in Boston, MA.
Come meet the team behind your tools – get your ticket today!
Reply
Highlighted
Contributor
Accepted Solution

How to check WinformsObject Exists or not

Hi,

i am trying to check WinformsObject exists or not but the  below code is not working 

if(Sys.Process.WaitWinFormsObject("DisplayScheduleMessage").Exists)

{

   Sys.Process.WinFormsObject("DisplayScheduleMessage").Close();

}

else

{

   Log.Message("Window doesnt exists continue next step");

}

 

Please advise.

 

 

Thanks,

Posts: 2,035
Topics: 15
Kudos: 809
Solutions: 157
Registered: ‎07-18-2013

Re: How to check WinformsObject Exists or not

There are timing issues that can affect checking for Exists.  Please take a look here:

 

https://support.smartbear.com/testcomplete/docs/app-objects/common-tasks/checking-existence.html

Contributor

Re: How to check WinformsObject Exists or not

Thanks and even i tried giving wait , but its not working

 if(Sys.Process("*").WaitWinFormsObject("DisplayScheduleMessage", 1000).Exists)

 {

   Sys.Process("*").WinFormsObject("DisplayScheduleMessage").Close();

 

}

else

 {

   Log.Message("Programme assigned");

 

}

 

Posts: 5,634
Topics: 43
Kudos: 2,491
Solutions: 503
Registered: ‎11-30-2009

Re: How to check WinformsObject Exists or not

Keep in mind that Sys.Process('*') will return the first process it finds in the search... which may not be your application.  You need to specify what process in order to detect the Winform.

 

Also... you say, "It's not working"... can you be more specific?  What is happening? Any errors? What's in the log?  


Robert Martin
[Community Expert Group]
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.

Extensions available
Community Leaders Program
Contributor

Re: How to check WinformsObject Exists or not

Thanks!

i tried the below code and its working.

var w = Sys.Process().WaitWinFormsObject("DisplayScheduleMessage", 1000);

if(w.Exists && w.VisibleOnScreen)

{

}

else

{

}

Posts: 5,634
Topics: 43
Kudos: 2,491
Solutions: 503
Registered: ‎11-30-2009

Re: How to check WinformsObject Exists or not

Actually, I would change your line of code to

var w = Sys.Process('myApp').WaitWinFormsObject("DisplayScheduleMessage", 1000);

 

Where you replace 'myApp' with the actual process name of your application under test.  Sys.Process() will, again, not necessarily return your specific application.


Robert Martin
[Community Expert Group]
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.

Extensions available
Community Leaders Program