Page 1 of 1

Create Repo Item in Code

Posted: Wed Sep 29, 2010 4:59 am
by costamesakid
I use the following code to create an instance of an Accessible Object where 'int' can change based upon other code. This works well for using some methods suck as .click, but I really want to use all the methods available. Is there a way to turn this accessible object into a repo item? Thanks

int AScount = 2;
Accessible pic1 = @"/form[@title~'^TacViewC2\ \ \ \(map:\ .*']/element/container/picture" + "[" + AScount + "]";
pic1.Click(MouseButtons.Right, "Center");

Re: Create Repo Item in Code

Posted: Wed Sep 29, 2010 1:28 pm
by Support Team
Hi,

If you want to use the RxPath in your Repository for a new element and add a variable to your RxPath, this is not possible at the moment. With Ranorex 3.0 you will have the possibility to add variables to your RxPath. A possible solution at the moment would be to add the RxPath to your repository and modify the RxPath of the element in code. If you want to use an adapter instead of "Accessible", I would suggest you to use the Ranorex.Picture for this RxPath.

Regards,
Peter
Ranorex Team

Re: Create Repo Item in Code

Posted: Wed Sep 29, 2010 5:44 pm
by Gunner1980
Support Team wrote:Hi,

If you want to use the RxPath in your Repository for a new element and add a variable to your RxPath, this is not possible at the moment. With Ranorex 3.0 you will have the possibility to add variables to your RxPath. A possible solution at the moment would be to add the RxPath to your repository and modify the RxPath of the element in code. If you want to use an adapter instead of "Accessible", I would suggest you to use the Ranorex.Picture for this RxPath.

Regards,
Peter
Ranorex Team
Can we get an example of how to modify the RxPath of the element in code and tie it to the repo item like you suggested?

We want to use the accessible name for this item as it is unique and changes every time we run the test. The number of pictures on the screen can change based on the circumstances you are running the test under.

Re: Create Repo Item in Code

Posted: Wed Sep 29, 2010 9:01 pm
by costamesakid
I have tried the following:

int AScount = 2;
Ranorex.Picture pic1 = @"/form[@title~'^TacViewC2\ \ \ \(map:\ .*']/element/container/picture" + "[" + AScount + "]";
pic1.click();


This works to click on an object, but I want to test its existence first. I would like to be able to do this:

if (pic1Info.exists())
{
// click it
}


But I am not able to compile the above code when I create the repo item within in my code. Thanks

Re: Create Repo Item in Code

Posted: Thu Sep 30, 2010 10:28 am
by Support Team
Hi,
Support Team wrote: Can we get an example of how to modify the RxPath of the element in code and tie it to the repo item like you suggested?
To change the RxPath during runtime in code please take a look to following post
http://www.ranorex.com/forum/repository ... html#p5820
costamesakid wrote:This works to click on an object, but I want to test its existence first. I would like to be able to do this:
Please use the Validation class of Ranorex. In this class you will find a method named Exists() with tons of overloads. For example I would write following code for your issue
Validate.Exists(yourRepoItem or RxPath);
yourItem.Click();
Regards,
Peter
Ranorex Team

Re: Create Repo Item in Code

Posted: Thu Sep 30, 2010 4:15 pm
by Gunner1980
I need to be able put the item I am creating as a repo item in a while loop or if statement. I also need to be able to specify the search time out.

Here is an example of how I want to utilize the item I am creating dynamically. Where repo.FormTacViewC2.PictureTrackCreateDrop is the item I want to create dynamically using the accessible name of the picture.

Code: Select all

public static void DropTrackSequence()
		{			

			Duration OrigDur1 = repo.FormTacViewC2.PictureTrackCreateDropInfo.SearchTimeout;
			repo.FormTacViewC2.PictureTrackCreateDropInfo.SearchTimeout = 2000;
			
			while (repo.FormTacViewC2.PictureTrackCreateDropInfo.Exists())	
			{
			Report.Warn("Previous track did not drop delaying 5 seconds...");
			Delay.Milliseconds(5000, false);
				
			repo.FormTacViewC2.PictureTrackCreateDrop.Click(MouseButtons.Right);
			}
			
			repo.FormTacViewC2.PictureTrackCreateDropInfo.SearchTimeout = OrigDur1;	
			
		}


I am trying to get away from using the picture because the pictures can only be identified by their index number. The accessible name is what is always unique and is how I want to identify the item I am clicking on. In my application I can have any number of pictures on the application when I start my test, I need to identify the specific picture I want to click on by the accessible name and this is not something that can be satisfied by a repo item with a regular expression. I really need to be able to create this item on the fly in the code and perform the following actions below with that item.

Re: Create Repo Item in Code

Posted: Wed Mar 23, 2011 9:25 pm
by tallahassee101
With Ranorex 3.0 you will have the possibility to add variables to your RxPath.
Can you please explain how you would solve the problem presented using Ranorex 3.0? The example "Using variables within the repository" only explains how to set the text of a rxpath to a variable, not how to insert a variable into an rxpath as costamesakid described.
int AScount = 2;
Ranorex.Picture pic1 = @"/form[@title~'^TacViewC2\ \ \ \(map:\ .*']/element/container/picture" + "[" + AScount + "]";
it looks like the Ranorex 3.0 tool only allows you to do the following through the GUI:
Ranorex.Picture pic1 = @"/form[@title=AScount]"

Re: Create Repo Item in Code

Posted: Wed Mar 23, 2011 10:10 pm
by Support Team
Hello,

in 3.0 you can use variables in the GUI, i.e. in the rxrep file:
- open the path editor for a repository item in the path (magic wand)
- there you can add a variable in one of the attributes

For a path like
"/form[@controlname='formVipApplication']/list/list/listitem[@accessiblename=$variable]"
when code is generated for the repository file $variable is replaced by the value of the variable (a string property of the class) at the moment you access the adapter class property. At his point an adapter class is generated and the element is searched repeatedly until the specified timeout has elapsed.

That corresponds to

Code: Select all

Ranorex.ListItem li = "/form[@controlname='formVipApplication']/list/list/listitem[@accessiblename="+variable+"]";
Regards,
Roland
Ranorex Support Team

Re: Create Repo Item in Code

Posted: Thu Mar 24, 2011 2:21 pm
by tallahassee101
Thank you. This example worked for me, such a better implementation!