how to check for label state change

Class library usage, coding and language questions.
hporter
Posts: 35
Joined: Wed Jan 23, 2013 4:49 pm

how to check for label state change

Post by hporter » Tue Feb 12, 2013 12:56 am

The area I'm writing a test for involves a progress label. This label updates itself during a check of a SharePoint farm. It updates with messages like:

Processing: MySPSite

which changes to:

Processing: MySecondSPSite

and so on until it goes through all sites on the SP farm. Finally, when it finishes, the label shows:

Processing has completed

Now, the processing can take anywhere from 30 sec to upwards of 45 min. and higher, based on the size of the farm. What I'm trying to do is set a Validation task at the end, that checks for successful completion. I need the automation to wait (for as long as it takes) until those words 'Processing has completed' appear in the label. In the absence of any other state changes on the UI (only the label text changes), how can I get those words to act as a trigger? I can't simply put in a delay, because the processing might take shorter or longer than the delay will allow. Any ideas? Thanks!

sham526
Posts: 34
Joined: Wed Jul 07, 2010 7:12 am
Location: Hyderabad(INDIA)

Re: how to check for label state change

Post by sham526 » Tue Feb 12, 2013 1:40 pm

u can try this :

Boolean flag_found=false;

do
{
flag_found=Validate.Exists("./form//label[@id~'.*complete$']",5000,"Check Object '{0}'",false);
} while (flag_found);

It will wait for 5Seconds every time and checks for the Id of the Label element.

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: how to check for label state change

Post by Ciege » Tue Feb 12, 2013 4:13 pm

Something very simple. (You'll need to verify the exact attribute type you want grab from the label element)

Code: Select all

while (MyLabelElement.TextValue.ToString() != "Processing has completed")
{
  Thread.Sleep(500);
}
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

User avatar
sdaly
Posts: 238
Joined: Mon May 10, 2010 11:04 am
Location: Dundee, Scotland

Re: how to check for label state change

Post by sdaly » Wed Feb 13, 2013 12:53 pm

I wouldn't use a loop without a timeout...

Am I missing something? Can't you just do?

Code: Select all

Validate.Exists("./form//label[@id~'.*complete$']",60000 * 45);

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: how to check for label state change

Post by Ciege » Wed Feb 13, 2013 3:57 pm

sdaly wrote:I wouldn't use a loop without a timeout...
Quite true... This was just a quick snippet of code to show one way how they could do what they were looking for... But if you want to extend this, I also wouldn't do something like this outside of a try/catch and a little bit more error handling...
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

hporter
Posts: 35
Joined: Wed Jan 23, 2013 4:49 pm

Re: how to check for label state change

Post by hporter » Fri Feb 15, 2013 4:29 pm

Thank you all for your replies. I get the drift of what you are suggesting, but I'm having difficulty implementing it. The label in question I've renamed ExecXML_Status, and its path in the repository is:

.//span[#'ctl00_lblStatus']

The current version of the validation involves checking the InnerText (which is a WebElement) to make sure the word "errors" does not appear there, after a delay. The validation code is:

Validate.Attribute(repo.ExecuteSavedInstructions.ExecXML_StatusInfo, "InnerText", new Regex("^((?!("+Regex.Escape("Errors")+")).)*$"));

I guess ultimately I'm wondering how to take this validation and turn it into one of the several suggestions posted to this question. Thanks again!

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: how to check for label state change

Post by Ciege » Fri Feb 15, 2013 4:49 pm

Something like this? As discussed before, you should add a timer and enclose all this with error handling...

Code: Select all

bool boolFailure = false;

while (ExecXML_StatusInfo.InnerText.ToString() != "Processing has completed")
{
  if (ExecXML_StatusInfo.InnerText.ToString().contains("error")
  {
    Report.fail("The following error occurred. " + ExecXML_StatusInfo.InnerText.ToString());
    boolFailure = true;
    break;
  }
  Thread.Sleep(500);
}
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

hporter
Posts: 35
Joined: Wed Jan 23, 2013 4:49 pm

Re: how to check for label state change

Post by hporter » Fri Feb 15, 2013 5:13 pm

That definitely makes sense, but my problem seems to be that I can't access InnerText in that fashion. It appears that I can only get to ExecXML_StatusInfo thru the repository:

repo.ExecuteSavedInstructions.ExecXML_StatusInfo

and InnerText isn't showing in the drop-down from there in the IDE. So your method makes perfect sense, but I'm hamstrung by the fact that I can't access the InnerText easily.

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: how to check for label state change

Post by Ciege » Fri Feb 15, 2013 5:33 pm

Hmm, a SpanTag should have an innettext attribute. I must be missing something...
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

hporter
Posts: 35
Joined: Wed Jan 23, 2013 4:49 pm

Re: how to check for label state change

Post by hporter » Fri Feb 15, 2013 7:40 pm

Perhaps I'm referencing it incorrectly? It's just, the only way I can think of referencing that element is through the repo. If there's another way to reference it, I'd be eager to hear it. That would certainly make things for me much easier. Thanks again!

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: how to check for label state change

Post by Ciege » Fri Feb 15, 2013 8:22 pm

Well, I don't use the repository so I can be of no help there. Sorry...
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

hporter
Posts: 35
Joined: Wed Jan 23, 2013 4:49 pm

Re: how to check for label state change

Post by hporter » Sat Feb 16, 2013 9:10 pm

I think I've figured it out - I was referring to ExecXML_StatusInfo, where it really should be just ExecXML_Status. I believe using that should get me to the InnerText element. Will retry next week.