Can I use this Ranorex path in code?

Ask general questions here.
stapes
Posts: 206
Joined: Wed Sep 16, 2015 10:55 am

Can I use this Ranorex path in code?

Post by stapes » Fri Oct 16, 2015 11:57 am

I am running tests on a Windows application using Ranorex.

I have a module that works fine when debugging, but fails when run as part of the test suite.

I am trying to pick an item from a grid.

Here is my code:

Code: Select all

public void SelectUserFromSearchResults()
        {

        	// this looks in the Search Results table for varSelectedUser and returns the index of this row as varIndex
        	
        	Ranorex .Table myTable=repo.SelectUsersOrGroups.UsersTable.SelectUsersOrGroupsAdvanced.Table282;
        	IList<Row> rows = myTable.FindDescendants<Row>();
        	int selectedIndex=-1;
        	bool found=false ;
        	foreach (Row row in rows )
        	{
        		foreach (Cell cell in row .Cells )
        		{
        			string value=cell .Text;
        			if(value.Contains (varSelectedUser))
        			{
						selectedIndex=row .Index ;
						varIndex =selectedIndex.ToString () ;
						found =true ;
						break ;
        			}
        			if(found )
        			{
        				break ;
        			}
        		}
        		if(found )
        			{
        				break ;
        			}
        	}
        	if(!found )
        	{
        		Report.Log(ReportLevel.Failure , "Search", "Validating Exists on item 'SelectUsersOrGroups.UsersTable.Table282'.", repo.SelectUsersOrGroups.UsersTable.SelectUsersOrGroupsAdvanced.Table282Info);
            
        	}
            Report.Log(ReportLevel.Info, "Validation", "Validating Exists on item 'SelectUsersOrGroups.UsersTable.Table282'.", repo.SelectUsersOrGroups.UsersTable.SelectUsersOrGroupsAdvanced.Table282Info);
            Validate.Exists(repo.SelectUsersOrGroups.UsersTable.SelectUsersOrGroupsAdvanced.Table282Info);

            Report.Log(ReportLevel.Info, "Mouse", "Mouse Left DoubleClick item 'SelectUsersOrGroups.UsersTable.SearchResultsGrid.SelectedDomainUsers' at 46;14.", repo.SelectUsersOrGroups.UsersTable.SelectUsersOrGroupsAdvanced.SelectedDomainUsersInfo);
            repo.SelectUsersOrGroups.UsersTable.SelectUsersOrGroupsAdvanced.SelectedDomainUsers.DoubleClick("46;14");
        }

    }
This last item, refered to as SelectedDomainUsers now has Ranorex path that looks like this:
table/row[@index=$varIndex]/cell[@text=$varselecteduser]
Is there any way I can refer to this directly in code?

I have added the two variables varIndex and varSelectedUser in the Recording Module, and have also added them as Parameters in the Test Case.

I don't understand. The code works a treat when I run it in isolation from the ranoprex Studio with breakpoints.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3914
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Can I use this Ranorex path in code?

Post by odklizec » Fri Oct 16, 2015 12:11 pm

Hi,

What exactly is the error you are getting? Path is not found or the click is not performed? Could you please set the Report level to Debug, run your test again and post the report with error?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

stapes
Posts: 206
Joined: Wed Sep 16, 2015 10:55 am

Re: Can I use this Ranorex path in code?

Post by stapes » Fri Oct 16, 2015 12:57 pm

My question was about whether I can refer to this directly in code:
table/row[@index=$varIndex]/cell[@text=$varselecteduser]

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3914
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Can I use this Ranorex path in code?

Post by odklizec » Fri Oct 16, 2015 1:09 pm

Yeah, it sure is possible. Check these code samples how to use xpaths directly in code:
http://www.ranorex.com/support/user-gui ... html#c3202

Path with variables must be used like this:

Code: Select all

"table/row[@index=" + varIndex + "]/cell[@text=" + varselecteduser + "]"
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

stapes
Posts: 206
Joined: Wed Sep 16, 2015 10:55 am

Re: Can I use this Ranorex path in code?

Post by stapes » Fri Oct 16, 2015 2:30 pm

Thanks. As it goes, my original code as described did work - it is just very slow, except when I run it in isolation.
When I run it as part of a suite it can take up to 3 minutes to find this.
When I run in isolation it happens instantaneously.