how to validate a non-exist of one object

Ask general questions here.
Ruser
Posts: 24
Joined: Wed Oct 07, 2009 3:26 pm

how to validate a non-exist of one object

Post by Ruser » Wed Oct 07, 2009 3:37 pm

Ranorex is very easy to validate the existence of an object. How can Ranorex validate a non-exist of an object? I think it has to be done through the user code, correct?

For example, here is the existence validation “Validate.Exists(repo.appinterface.item1)"
How to validate the non-exist of this object?

Thanks,

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: how to validate a non-exist of one object

Post by Support Team » Wed Oct 07, 2009 4:12 pm

In the current version you can check non-exist elements as follow:
try
{
     Validate.Exists(repo.Gen2Interface.Gen2Dom.ImportSettings);
}
catch (RanorexException e)
{
     Report.Error("Element does not exist.");
}
In the upcoming V2.2 you will be able to use following code:
Validate.Exists(repo.Gen2Interface.Gen2Dom.ImportSettingsInfo);
Kind regards,
Gabor
Ranorex Support Team
.
Image

User avatar
daa
Posts: 22
Joined: Tue May 19, 2009 2:01 pm
Location: York, UK
Contact:

Re: how to validate a non-exist of one object

Post by daa » Thu Oct 08, 2009 4:52 pm

I've used one of the Find() methods to do this:

Code: Select all

        /// <summary>
        /// The function returns the (first) Element found as an Object, or NULL.
        /// </summary>
        public static Object GetObject(RxPath aRxPath, Ranorex.Duration aTimeout)
        {
            System.Collections.Generic.IList<Element> lList = Host.Local.Find(aRxPath, aTimeout);
            if (lList.Count > 0)  {
                  return lList[0];                           
            } else   {
                  return null;
            }           
         }

        public static bool Exists(RxPath aRxPath, Ranorex.Duration aTimeout)
        {
            return GetObject(aRxPath, aTimeout) != null;
        }
You can then use Exists() like any other boolean, so you can say if (!Exists(...)).

I've further used the Exists() function to get ERanorex to wait for a progress bar window to go away, by using it to control a while loop that just does a Delay() at each iteration
David Allsopp,
Test Automation Engineer, Mitrefinch Ltd.

SanMan
Posts: 151
Joined: Tue Apr 13, 2010 9:59 am

Re: how to validate a non-exist of one object

Post by SanMan » Wed May 12, 2010 10:50 am

Hi,

Could somebody give a example code, how to verify e.g. progress bar is shown and do this "while-delay()-loop" until progress bar is not shown anymore?

If I verify with Valitade.NotExists method, it will throw exception?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: how to validate a non-exist of one object

Post by Support Team » Wed May 12, 2010 11:17 am

Hi!
SanMan wrote:Could somebody give a example code, how to verify e.g. progress bar is shown and do this "while-delay()-loop" until progress bar is not shown anymore?
If I verify with Valitade.NotExists method, it will throw exception?
First you have to find out which value you want to obtain. Open Spy and track your progress bar. Now start your actions with the progress bar as you would do it with your test. If your test finished update SPY elements and take a look on Overview/General which property of item(progress bar) has changed. After this evaluation
use code like:
while(YourProgressBar.Visbile == true) //instead of Visible you can use Enabled/Valid
{
    //do some action
}
Regards,
Peter
Ranorex Support Team
.
Image