Where did Application go?

Class library usage, coding and language questions.
Skarlso
Posts: 27
Joined: Thu Aug 07, 2008 9:11 am

Where did Application go?

Post by Skarlso » Wed Jan 21, 2009 3:01 pm

Hi!

I'm trying to find out, what Application was converted into...

could you post please some example on... How to get Application.sleep... and Application.SendKeys(), and Application.ErrorAsException = false... And such?

Thanks,
Gergely.

Edit:

To be clear.. I have a method that waits for a string to appear in a given control. This looks like this:

Code: Select all

public bool WaitforStringToAppear(Control control, string toBeFound, string window, int maxTimeToWait) 
		{
			
			
			Application.ErrorAsException = false;
			bool found = false;
			
			form = Application.FindFormTitle(window, SearchMatchMode.MatchRegExp, true, 10000);
			form.Focus();			
			
			System.DateTime start = System.DateTime.Now;
			
			// While the start time + maxTimeToWait is bigger then the 
			// current time, the process shell sleep.
			while (!found && start.AddMilliseconds(maxTimeToWait) > DateTime.Now)
			{
				Element child = control.Element.FindChildValue(toBeFound, SearchMatchMode.MatchRegExp);
				if ( child != null )
				{
					found = true;
				} 
				else
				{
					Application.Sleep(1);
				}
			}
			
			Application.ErrorAsException = true;
			return found;
		}	
Now i have no idea how this should look like under 2.0 :S

And also i have a waitforcontroltoappear..

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Post by Support Team » Wed Jan 21, 2009 4:23 pm

There is no Application Class or similar in Ranorex 2.0.

Instead App.Sleep() you can use:
System.Threading.Thread.Sleep(1000);

For SendKeys:
Ranorex.Keyboard.Press()

Code: Select all

public static bool WaitforStringToAppear(Element elem, string searchString, int maxTimeToWait)
{
		
           
    	System.DateTime timeToWait = System.DateTime.Now.AddMilliseconds(maxTimeToWait);
        bool found = false;
           
        while(timeToWait > System.DateTime.Now)
        {
          	string elemText = elem.GetAttributeValue("Text").ToString();
           	if(elemText.Equals(searchString.ToString()))
           	{
           		found = true;
           		break;
           	}
           		
            System.Threading.Thread.Sleep(1000);
        }
    		
        return found;
}
There is no Application.ErrorAsException functionality in Ranorex 2.0 yet.
But if you want to search for something over a period e.g. look if button exists and click it, u can catch the exception in the while loop like:

Code: Select all

private static void TryingClickButtonFinish(Ranorex.Button buttonFinish)
        {

            while (buttonFinish == null)
            {
                try
                {
                    System.Threading.Thread.Sleep(5000);
                    buttonFinish = SetupRepository.FormRanorex_20_Setup.ButtonFinish;
                    break;
                }
                catch
                {
                    continue;
                }
            }
            buttonFinish.Click();
            return
        }
Regards,
Christian
Ranorex Support Team

Skarlso
Posts: 27
Joined: Thu Aug 07, 2008 9:11 am

Post by Skarlso » Wed Jan 21, 2009 4:30 pm

Thanks Christian!

Skarlso
Posts: 27
Joined: Thu Aug 07, 2008 9:11 am

Post by Skarlso » Wed Jan 21, 2009 4:44 pm

Mmm... Btw... What is SetupRepository and finishbutton20 ? :D

Aaannd... I don't really know but, you are searching in an Elemenent for a value like Text. But i give a Control as parameter because my Element is a Static Text for which i'm waiting to appear. So i don't have the Element when i'm calling this function. I have only the control in which the element will appear with the text toBeFound..

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Post by Support Team » Wed Jan 21, 2009 5:00 pm

In Ranorex 2.0 there is an even simpler way of waiting for objects to appear. Image there's a static text you are waiting for having an RxPath of "pathToMyText" (you get the RxPath using RanorexSpy). Then you can search for this text specifying a timeout (e.g. 5000 milliseconds) like that:

Code: Select all

Form form = "pathToMyApplication";
Text elem = form.FindSingle<Text>("pathToMyText", 5000);
Regards,
Alex
Ranorex Support Team

Skarlso
Posts: 27
Joined: Thu Aug 07, 2008 9:11 am

Post by Skarlso » Wed Jan 21, 2009 5:02 pm

Wow :O I will definitely look into this! And as i see this it works with just everything even controls, because they are on xpath too... This looks very promising!

Thanks Alex!!

Regards,
Gergely.