Best way to search by text in a gridview

Class library usage, coding and language questions.
puntapret
Posts: 34
Joined: Fri Sep 14, 2012 11:05 am

Best way to search by text in a gridview

Post by puntapret » Tue Jan 07, 2014 11:06 am

Hello,

I'm using the latest Ranorex Studio 4.1.3.16547.

We are using a Telerik RadGrid to show hundreds of lines, in one of our test, we are looking for a specific username.

The problem is, it seems that if the row is not visible in the screen, the method TryFindSingle can not find the row.

The full path of the object :
/dom[@domain='XXXX.XXXXXX.com']//object[#'silverlightObject']/form[@name='Silverlight Control']/?/?/container[@automationid='Navigation']/container[@automationid='SalesBOFrame']/table[@automationid='GridView']//element[@automationid='Row_11']/?/?/text[@Name=' TOTO World']

Since in my repositories, i already create a path :
SalesBORepository.Instance.Portal.SilverlightObject.SalesBOFrame.GridView

I used this :
UIAutomation obj = null;

// it will work since it's visible in screen SalesBORepository.Instance.Portal.SilverlightObject.SalesBOFrame.GridView.TryFindSingle<UIAutomation>
("//?/?/?/text[@Name=' TOTO World']", out obj )

// it doesn't work since it's not visible on screen
SalesBORepository.Instance.Portal.SilverlightObject.SalesBOFrame.GridView.TryFindSingle<UIAutomation>
("//?/?/?/text[@Name=' TOTO World 1000']", out obj )

How should i do it ? Is there any elegant way to find an object in a grid view on a specific column (and not Row) ?

Thanks in advance

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Best way to search by text in a gridview

Post by krstcs » Tue Jan 07, 2014 2:31 pm

Windows (and especially .NET, which Telerik is based on) uses a method known as "Lazy Loading" to store tables, lists, etc., when they are too long to fit in the defined view/screen area. This means that the software only fetches the information for those rows that are visible. For any rows that are not visible it only creates a place-holder object. This allows the system to know that there should be an object there, but it doesn't have to allocate space for the full object until it becomes visible.

Since Windows doesn't present the information, Ranorex can't see any information about those rows. There is nothing Ranorex can do about it, unfortunately.

You will need to have Ranorex scroll down (or over) in the list (I use the keyboard, but you could use the mouse to click on the scroll bar) until the object you are looking for is actually visible, and then you can have Ranorex interact with the object.
Shortcuts usually aren't...

puntapret
Posts: 34
Joined: Fri Sep 14, 2012 11:05 am

Re: Best way to search by text in a gridview

Post by puntapret » Tue Jan 07, 2014 3:14 pm

Thank you for the reply krstcs.

So if i understand correctly, i should iterate until the row with the value that i'm looking for can be found on the screen ?

A question to the Ranorex Team, do you have a scroll to element helper like this one http://www.ranorex.com/forum/how-to-scr ... t1521.html that work for silverlight ?

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Best way to search by text in a gridview

Post by krstcs » Tue Jan 07, 2014 3:44 pm

Yes, that is correct. You need to iterate over the table rows until the row is actually visible.

I don't believe they have any method like that, so, more than likely, you will need to create your own methods that do what you need and then call them in user code.
Shortcuts usually aren't...

puntapret
Posts: 34
Joined: Fri Sep 14, 2012 11:05 am

Re: Best way to search by text in a gridview

Post by puntapret » Tue Jan 07, 2014 4:44 pm

Thanks again krstcs,

I finally used an iteration.

At first , i used Mouse.ScrollWheel, weirdly, when i put -20 or -500, i didn't find any difference, the scroll wheel is still so slow and just moving 3-4 lines down. Is it normal ? or i missed something ?

Finally i used the DoubleClick on the scrolldown button. It's faster than the scroll wheel.

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Best way to search by text in a gridview

Post by krstcs » Tue Jan 07, 2014 6:06 pm

I would recommend not using mouse interactions for this particular issue, unless absolutely necessary because they are sometimes not as reliable or repeatable, depending on the system you are using, the mouse settings, resolution, etc. And, you should be able to just do a Click (not a DoubleClick).

The scroll wheel interaction is also not as robust as you might expect in these situations, so I would stay away from that as well.

I would recommend using keyboard actions as they are more consistent and controllable.

So you would set focus to your item (the table, or at least the first row), then "Press" the {Down} key until the item you wanted was in view. This is slower than doing a page at a time, but it is much more consistent and reliable (which, to me, should be the overriding goal of automation, but your mileage may vary...). If your table doesn't accept keyboard input, then you might be forced to use the mouse though.

I have had to do similar things for drop-down lists because the browsers don't all support them the same way. I made a method that would decide whether to move up or down and then do that until it found the item, or reached the end of the list (which would cause a failure).
Shortcuts usually aren't...

puntapret
Posts: 34
Joined: Fri Sep 14, 2012 11:05 am

Re: Best way to search by text in a gridview

Post by puntapret » Wed Jan 08, 2014 10:00 am

krstcs wrote:I would recommend not using mouse interactions for this particular issue, unless absolutely necessary because they are sometimes not as reliable or repeatable, depending on the system you are using, the mouse settings, resolution, etc. And, you should be able to just do a Click (not a DoubleClick).

The scroll wheel interaction is also not as robust as you might expect in these situations, so I would stay away from that as well.

I would recommend using keyboard actions as they are more consistent and controllable.

So you would set focus to your item (the table, or at least the first row), then "Press" the {Down} key until the item you wanted was in view. This is slower than doing a page at a time, but it is much more consistent and reliable (which, to me, should be the overriding goal of automation, but your mileage may vary...). If your table doesn't accept keyboard input, then you might be forced to use the mouse though.

I have had to do similar things for drop-down lists because the browsers don't all support them the same way. I made a method that would decide whether to move up or down and then do that until it found the item, or reached the end of the list (which would cause a failure).
Thank you for the explanation.

Well, the table itself doesn't accept keyboard input. So i think i'm stuck with the mouse interactions.

How do i detect that i'm already on the end of the list ? I realized just now that if i can not find the object, it will indefinitely doing the click down, since i didn't check if it's already on the end of the list. And at this time, i didn't know how to do it.

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Best way to search by text in a gridview

Post by krstcs » Wed Jan 08, 2014 2:33 pm

If you have access to the developers, you might want to sit down with them and explain why they should put keyboard binds on their elements. This not only helps you with testing, but could help customers/users as they would have multiple ways of navigating your application. It also helps you be in compliance with applicable accessibility requirements (handicapped accessible, etc.). They may say no, but if you can give them a good explanation as to the amount of time it will save you in testing, they may see the value.


As for the problem at hand, you are probably going to need to check to see if the index of the last visible row is the same as the index of the last row in the table's dummy structure.

Even though the table doesn't give you the data in the rows, it should still have a row count, or have place-holder rows for all of the non-visible rows. You would need to compare those values in user code to make sure you have gone through the whole table.

Also, remember that if you get to the end and don't find what you are looking for, you probably need to report that as an error in Ranorex.


As an aside, any time you don't find something you expect, given the inputs in your test, you should know it is an error, there should be no guess work in testing. It may not be a bug, and could just be a test problem, but you should always assume the worst, just in case. Just my opinion though. :D
Shortcuts usually aren't...

puntapret
Posts: 34
Joined: Fri Sep 14, 2012 11:05 am

Re: Best way to search by text in a gridview

Post by puntapret » Wed Jan 08, 2014 3:05 pm

krstcs wrote: As for the problem at hand, you are probably going to need to check to see if the index of the last visible row is the same as the index of the last row in the table's dummy structure.
Thank you, i will try to speak with our UI developper.

This is what is weird, everytime i do a GridView.Rows.Count, i only got 0. That's why i said, i still can not find a way to compare indexes.

We use telerik radgrid.

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Best way to search by text in a gridview

Post by krstcs » Wed Jan 08, 2014 3:12 pm

Can you post a snapshot of the application under test? I might be able to see something you missed.

If you can't, no worries.

http://www.ranorex.com/support/user-gui ... files.html
Shortcuts usually aren't...

puntapret
Posts: 34
Joined: Fri Sep 14, 2012 11:05 am

Re: Best way to search by text in a gridview

Post by puntapret » Thu Jan 09, 2014 9:53 am

krstcs wrote:Can you post a snapshot of the application under test? I might be able to see something you missed.

If you can't, no worries.

http://www.ranorex.com/support/user-gui ... files.html
Will do it today or at the latest tomorrow. Thanks for your help :)

puntapret
Posts: 34
Joined: Fri Sep 14, 2012 11:05 am

Re: Best way to search by text in a gridview

Post by puntapret » Thu Jan 09, 2014 11:33 am

Here is the snapshot of the gridview, this is my first time saving a snapshot, i hope it's good
Attachments
RanorexUserList.rxsnp
(135.69 KiB) Downloaded 135 times

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Best way to search by text in a gridview

Post by krstcs » Thu Jan 09, 2014 2:40 pm

OK, looking at what you sent, I see the rows under an Element called "PART_GridViewVirtualizationPanel". I can see 19 of them, with the last being not visible.

You could just do a count of the child elements of the PART_GridViewVirtualizationPanel and then iterate through them.

Code: Select all

/dom[@domain='ecos2.externis.com']
 //table[@automationid='GridView']
     /container[@automationid='PART_ItemsScrollViewer']
        /element[@automationid='PART_GridViewVirtualizingPanel]
            /element[@automationid='Row_0' and @classname='GridViewRow']
So, you could, for instance, get all elements that have the following path: "/element[@classname='GridViewRow']". Do a Find(RxPath) from your PART_GridViewVirtualizationPanel object using that string as the path to find, then get the Count from that collection.


You could also just loop through the collection, setting focus to the current row on each loop, which might bring the invisible rows up to a visible area. That might be the best way to do it.

So, assuming the Table/Container object is in the repo at Portal/Table, you could do:

Code: Select all

public void TestMethod()
{
        List<Element> rows = repo.Portal.Table.PARTGridViewVirtualizingPanel.FindDescendants<Element>("element[@classname='GridViewRow']");
        	
        foreach (Element row in rows) {
        	row.Focus();
        	//check the row here...
        	//...and do whatever...
        }
}
Shortcuts usually aren't...

puntapret
Posts: 34
Joined: Fri Sep 14, 2012 11:05 am

Re: Best way to search by text in a gridview

Post by puntapret » Fri Jan 10, 2014 10:51 am

Thanks for the code.

The problem is, there are 260 rows from the database, and in the PART_GridViewVirtualizationPanel, we can only saw 19.

And i use this code :

Code: Select all

// find the virtualizing panel
UIAutomation virtualPanel = SalesBORepository.Instance.Portal.SilverlightObject.SalesBOFrame.GridView.FindSingle<UIAutomation>
                ("?/?/element[@automationid='PART_GridViewVirtualizingPanel']");
            
// find the descendants
            var rows = virtualPanel.FindDescendants<UIAutomation>("element[@classname='GridViewRow']");
           
I can't use Element like your code, it throw me an error everytime that Ranorex.Core.Element can not be used as T parameters in generic method FindSingle<T>, no implicit conversion between Ranorex.Core.Element to Ranorex.Adapter.

I'm still learning Ranorex by trial and error, so i apologize if i seems don't understand some basic stuff

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Best way to search by text in a gridview

Post by krstcs » Fri Jan 10, 2014 2:26 pm

Ah, well then that complicates things. :D

Do you have access to the database from your test? If you don't you should, at least read access, if for no other reason than to validate what your SUT is displaying/doing. If you do, you could use that to determine what elements should be there and the count.


On the other part, you might try WebElement instead. You are right, Element is not an adapter. My bad there.


And, I have been using Ranorex for 3 years and I'm still learning stuff, so no worries! :D
Shortcuts usually aren't...