Page 1 of 1

how to check for label state change

Posted: Tue Feb 12, 2013 12:56 am
by hporter
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!

Re: how to check for label state change

Posted: Tue Feb 12, 2013 1:40 pm
by sham526
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.

Re: how to check for label state change

Posted: Tue Feb 12, 2013 4:13 pm
by Ciege
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);
}

Re: how to check for label state change

Posted: Wed Feb 13, 2013 12:53 pm
by sdaly
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);

Re: how to check for label state change

Posted: Wed Feb 13, 2013 3:57 pm
by Ciege
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...

Re: how to check for label state change

Posted: Fri Feb 15, 2013 4:29 pm
by hporter
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!

Re: how to check for label state change

Posted: Fri Feb 15, 2013 4:49 pm
by Ciege
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);
}

Re: how to check for label state change

Posted: Fri Feb 15, 2013 5:13 pm
by hporter
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.

Re: how to check for label state change

Posted: Fri Feb 15, 2013 5:33 pm
by Ciege
Hmm, a SpanTag should have an innettext attribute. I must be missing something...

Re: how to check for label state change

Posted: Fri Feb 15, 2013 7:40 pm
by hporter
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!

Re: how to check for label state change

Posted: Fri Feb 15, 2013 8:22 pm
by Ciege
Well, I don't use the repository so I can be of no help there. Sorry...

Re: how to check for label state change

Posted: Sat Feb 16, 2013 9:10 pm
by hporter
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.