Page 1 of 1

How to repeat actions until a status is met

Posted: Mon Mar 31, 2014 6:28 pm
by houseofcutler
Hi there,

I am new to Ranorex and still evaluating the product. (looks good so far). I will try to explain this as clearly as possible.

I have a situation where I need to trigger a 'job' within an MMC application console. I want to be able to wait until the job has completed to validate the status and determine whether it was successful or not.

However as this is in an MMC window the status field does not automatically refresh and so teh refresh action needs to be clicked.

I can identify all of the fields but am unsure of how to do the 'loop' I guess this is a C# Question rather than Ranorx. I have tried googling for a solution but most of this covers how to repeat actions a set number of times and or for a number of rows etc.

I believe the following steps are required:

right click, start job

Click Refresh action
check status field -
- if 'status is running' click refresh again, check status again
- if status is 'Idle' - Job was successful - do something else
- if status is Failed - Job failed - do something else

Any advise would be very much appreciated
Many thanks

Re: How to repeat actions until a status is met

Posted: Tue Apr 01, 2014 11:21 am
by houseofcutler
After a break and a sleep I was able to find my answers.

Code: Select all

 

       public void Mouse_Click_Refresh()
        {
            Report.Log(ReportLevel.Info, "Mouse", "Mouse Left Click item 'XporterConsoleRootGroupcallXporte1.Actions.Refresh' at Center.", repo.XporterConsoleRootGroupcallXporte1.Actions.RefreshInfo);
            
            string Status = repo.XporterConsoleRootGroupcallXporte1.CentreWindow.varJob_Status.Text;
                        
            Report.Info("Job Start Time:" + System.DateTime.Now.ToString());
            	
            while (String.Equals(Status, "Running"))
            {
            	repo.XporterConsoleRootGroupcallXporte1.Actions.Refresh.Click();
            	Status = repo.XporterConsoleRootGroupcallXporte1.CentreWindow.varJob_Status.Text;
            	Delay.Milliseconds(3000);
            	}

            
            Report.Info("Job Finish Time:" + System.DateTime.Now.ToString());
            
        }

        public void Validate_varJob_Status()
        {
            Report.Log(ReportLevel.Info, "Validation", "Validating AttributeEqual (Completed='Idle') on item 'XporterConsoleRootGroupcallXporte1.CentreWindow.varJob_Status'.", repo.XporterConsoleRootGroupcallXporte1.CentreWindow.varJob_StatusInfo);
            Validate.Attribute(repo.XporterConsoleRootGroupcallXporte1.CentreWindow.varJob_Status, "Text", "Idle");
        }
I also added a validation step at the end so I could pick up on any failures (not status Idle)

Re: How to repeat actions until a status is met

Posted: Mon Apr 07, 2014 4:58 pm
by Support Team
Hello houseofcutler,

I'm glad that you found a solution. Thank you for sharing your experience to the community.

Regards,
Robert