Wait for a change before validation?

Ask general questions here.
hubilation
Posts: 5
Joined: Mon Jun 04, 2012 6:24 pm

Wait for a change before validation?

Post by hubilation » Mon Jun 04, 2012 6:32 pm

I'm currently writing tests for a search/browse page that allows the user to filter results by different criteria. Once the user applies the filter, we have an AJAX call to refresh the content without loading the page. At the top of the page we have an item count that reflects how many results were returned given the filters. We use this item count to compare to our SQL queries to ensure that each filter is returning the correct amount of items. We have an issue here though, before that filter is applied, the count exists already (reflecting total count without any filters). The count only updates after the inventory is displayed on screen. In some cases when the system is running slowly, the validation runs before the count is updated, causing the validation to fail.

Is there some way that I can store the original value, and then not proceed through the test until the value changes into something else? Or should I just do an excessively long wait time to deal with slowness?

Thanks!

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

Re: Wait for a change before validation?

Post by Ciege » Mon Jun 04, 2012 7:07 pm

Is there some way that I can store the original value, and then not proceed through the test until the value changes into something else?
Sure, you need to write some code to do it though. Write some code that grabs the current value, store it as strOriginal.
Then in a while loop, grab the text again and store it as strCurrent. While strCurrent == strOriginal, loop... else break.

Pseudo code to follow:

Code: Select all

string strOriginal = FindSingle(myValueRXPath)
string strCurrent = FindSingle(myValueRXPath)
while (strCurrent = strOriginal)
{
strCurrent = FindSingle(myValueRXPath)
}
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...

hubilation
Posts: 5
Joined: Mon Jun 04, 2012 6:24 pm

Re: Wait for a change before validation?

Post by hubilation » Mon Jun 04, 2012 10:24 pm

Thank you for the response. I think this will work for me. However, one question, what exactly do I need to put in place of myValueRXPath. Does it need to be what's contained in the "Path" column in the repository, or can it simply be the name that I've given the object?

edit: I assumed FindSingle was a Ranorex method, I guess it's not? When I run it's telling me it doesn't exist in the current context, I'm using the following libraries:

using Ranorex;
using Ranorex.Core;
using Ranorex.Core.Testing;

I guess it's part of the Element class? Not sure how to instantiate it as it doesn't have a default constructor (or so it seems. I'm just a BA and not exactly an expert at C# or reading API Documentation)
Last edited by hubilation on Mon Jun 04, 2012 10:47 pm, edited 1 time in total.

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

Re: Wait for a change before validation?

Post by Ciege » Mon Jun 04, 2012 10:46 pm

I guess I could have done better with my pseudo code... I kind of just hammed it out quickly. Do something like this...

Code: Select all

Ranorex.Text OriginalText = MyFormObject.FindSingle(myValueRXPathToMyTextObject)
So you are finding (FindSinlge) withing your Form (MyFormObject) to the path of the tect (myValueRXPathToMyTextObject) with that form.
Then you can get the text property of that text object.

I don't use the repository so I am not sure how this changes by using a repository object.
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...

hubilation
Posts: 5
Joined: Mon Jun 04, 2012 6:24 pm

Re: Wait for a change before validation?

Post by hubilation » Mon Jun 04, 2012 10:52 pm

The field is not within a Form. It's just a Span tag in a Div tag. I'm not sure what you mean by MyFormObject, should that be referencing something I've already created, or is that a completely arbitrary name?

hubilation
Posts: 5
Joined: Mon Jun 04, 2012 6:24 pm

Re: Wait for a change before validation?

Post by hubilation » Mon Jun 04, 2012 11:09 pm

Okay, after searching around, I've found some examples of FindSingle. But I'm still having issues. Here's my code:

Ranorex.Text strOriginal = Host.Local.FindSingle("/dom[@domain='testurl']//span[@id='cars-found-label']", 10000);
Ranorex.Text strCurrent = Host.Local.FindSingle("/dom[@domain='testurl']//span[@id='cars-found-label']", 10000);
while(strCurrent == strOriginal)
{
strCurrent = Host.Local.FindSingle("/dom[@domain='testurl']//span[@id='cars-found-label']", 10000);
}

I don't get any build errors, but when I get to this step in my validation, I get the following error:

The element does not support the required capability 'text'.

When I "jump to," it goes to the first line of what I just posted.

hubilation
Posts: 5
Joined: Mon Jun 04, 2012 6:24 pm

Re: Wait for a change before validation?

Post by hubilation » Mon Jun 04, 2012 11:43 pm

I've got it figured out. Thanks to your initial responses and some searching through the website, with a whole bunch of trial and error.

Rather than store an "Original" value, I decided to just store the count prior to filtering.

Ranorex.SpanTag strCurrent = Host.Local.FindSingle("/dom[@domain='testurl']//span[@id='cars-found-label']", 10000);
Report.Log(ReportLevel.Info, "Vehicle count is currently " + strCurrent.InnerText);
string initialCount = DatabaseHelper.ReturnRowCount("query for basic inventory search");
while(strCurrent.InnerText == initialCount)
{
Report.Log(ReportLevel.Info, "Waiting for count to update before validation");
strCurrent = Host.Local.FindSingle("/dom[@domain='testurl']//span[@id='cars-found-label']", 10000);
}

The reason storing the original value wasn't working for me was that if at the very beginning of this step, the system was actually running quickly, then both original and current values would be the same, and the loop would never break. With specifying my basic query, I know for a fact that the current value shouldn't be the same when I want to continue.

I threw those two Report logs in so I could ensure that at the time this is being run, I was actually entering the loop, and I did!

Thanks again, Ciege!

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

Re: Wait for a change before validation?

Post by Ciege » Mon Jun 04, 2012 11:46 pm

OK, I didn't realize you were working in a DOM object rather than a form... Plus, this is a Span object not a Text object. So try this...

Code: Select all

Ranorex.Span strOriginal = Host.Local.FindSingle("/dom[@domain='testurl']//span[@id='cars-found-label']", 10000);
Ranorex.Span strCurrent = Host.Local.FindSingle("/dom[@domain='testurl']//span[@id='cars-found-label']", 10000);
while(strCurrent.innertext == strOriginal.innertext)
{
strCurrent = Host.Local.FindSingle("/dom[@domain='testurl']//span[@id='cars-found-label']", 10000);
}
The .innertext may not be the proper attribute, check it out with RanorexSpy to verify that innertext holds the text you are looking for, or if it happens to be another attribute (like text) or 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...

User avatar
artur_gadomski
Posts: 207
Joined: Mon Jul 19, 2010 6:55 am
Location: Copenhagen, Denmark
Contact:

Re: Wait for a change before validation?

Post by artur_gadomski » Thu Jun 07, 2012 9:56 am

Keep in mind that with this kind of loop if one day the filter will not work, the value will not change, the loop will never break, and so your test will never end. I like to put a simple counter to terminate the loop after some time.

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

Re: Wait for a change before validation?

Post by Ciege » Thu Jun 07, 2012 3:13 pm

Great point. I've been so heads down in trying to help him with his issue that I missed some of the elegant points of coding.
Thanks!
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...