RanorexPath in user code

Best practices, code snippets for common functionality, examples, and guidelines.
HansSchl
Posts: 143
Joined: Wed Sep 19, 2018 10:05 am

RanorexPath in user code

Post by HansSchl » Tue Sep 15, 2020 9:26 am

Hi,

I'm trying to find a GUI item in user code. The user code knows the parent of the item inquestion via a RepoItemInfo, and constructs the relative RanorexPath to the item. But how do I apply the relative path? RepoItemInfo has no method (or at least, I failed to find it) to return items that match a specified path, like

Code: Select all

Adapter[] RepoItemInfo.FindChildren(RxPath path); // does not exist
To give you an idea what I want to achieve: I want to create a test that verifies whether a table is ordered correctly. The test clicks a column header and then tryies to find out whether the table content is ordered by this column. For this purpose I want to create a user code function

Code: Select all

VerifyColumnSort(RepoItemInfo grid, string column, string direction, string sortType)
The "grid" parameter is the repository item that represent the table view. Given this parameter, the function must find the sort column by its name (in the "column" parameter) and verify that the content is ordered according to "direction". "sortType" is used to specify alphanumeric or numeric columns.

The RanorexPath for a cell, relative to "grid", is "row/cell[accessiblename='cell_name']". An expression that matches all cells of the column is "row/cell[@accessiblename~'column_name$'] (this is no because of the peculiarities of the grid implementation).

Ranorex version is 9.3.1.

Hoping for advice!
Hans

User avatar
Stub
Posts: 515
Joined: Fri Jul 15, 2016 1:35 pm

Re: RanorexPath in user code

Post by Stub » Tue Sep 15, 2020 3:48 pm

I sometimes form a more precise RxPath when I want to get to a specific child item:

Code: Select all

RxPath rx_path = repo_item_info.AbsolutePath;
String updated_path = rx_path.ToResolvedString();
updated_path += path_to_append;
RxPath updated_rx_path = updated_path; 
I can then create a temporary RepoItemInfo using my new RxPath, and off we go to create the required Adapter.

HansSchl
Posts: 143
Joined: Wed Sep 19, 2018 10:05 am

Re: RanorexPath in user code

Post by HansSchl » Wed Sep 16, 2020 2:07 pm

So simple... 8)

HansSchl
Posts: 143
Joined: Wed Sep 19, 2018 10:05 am

Re: RanorexPath in user code

Post by HansSchl » Tue Sep 22, 2020 11:00 am

@Stub - thanks to your suggestions, I found an even smarter solution:

Code: Select all

RepoItemInfo sub_item_info = new RepoItemInfo(repo_item_info.ParentFolder, "some_name", "relative_ranorex_path", new Duration(30000), null);
I don't know what the meaning of "some_name" is - I just chose a meaningful unique name.
I guess this fails if repo_item_info is not a rooted or app folder.

User avatar
Stub
Posts: 515
Joined: Fri Jul 15, 2016 1:35 pm

Re: RanorexPath in user code

Post by Stub » Tue Sep 22, 2020 1:31 pm

My sample code was extracted from a routine I wrote to produce an RxPath object, so it didn't go on to produce the new RepoItemInfo in the same function. My parameters were the parent item and a relative path, but I munged it all together to form a complete RxPath, which I later go on to form a new RepoItemInfo from. I'll give your flavour a whirl next time I'm in that area.

I too use a meaningly name for 'some_name', and I also use the SearchTimeout from the parent item in place of the 'new Duration(30000)' parameter - same net result, most likely.