Page 1 of 1

how to validate a non-exist of one object

Posted: Wed Oct 07, 2009 3:37 pm
by Ruser
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,

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

Posted: Wed Oct 07, 2009 4:12 pm
by Support Team
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

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

Posted: Thu Oct 08, 2009 4:52 pm
by daa
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

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

Posted: Wed May 12, 2010 10:50 am
by SanMan
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?

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

Posted: Wed May 12, 2010 11:17 am
by Support Team
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