Page 1 of 1

How to set the string value to RepoItemInfo object?

Posted: Wed Feb 19, 2014 3:50 pm
by ChrisDavid
I want to write a user code method which takes a string value as argument and stores it into RepoItemInfo object and then gets the absolutepath of the appropriate repository item. But I couldnt convert the string to RepoItemInfo object directly. It throws the below error.
Cannot implicitly convert type 'string' to 'Ranorex.Core.Repository.RepoItemInfo' (CS0029)

This is the code I use.

public void convertString_RepoItemInfo(string argument1)
{
Ranorex.Unknown Elem = null;
RxPath repoPath = null;
RepoItemInfo item = null;
string element_Str = "";

item = argument1; //convert string to RepoItemInfo - This is where error is thrown
repoPath = item.AbsolutePath; //Gets Reposiotyr Item's absolute path
element_Str = repoPath.ToResolvedString(); //converts the repository Item's absolute path to string
Report.Info("Path is " + element_Str);

if(Host.Local.TryFindSingle(element_Str, out Elem))
{
Elem.MoveTo(3000);
Elem.Click(3000);
}
else
Report.Info("User", "Element is not found");
}

Since RepoItemInfo is read only object I could not perform this. I tried using reflection as below,
typeof(RepoItemInfo).GetField("Name", BindingFlags.Instance|BindingFlags.NonPublic).SetValue(item, argument1);

This does not throws any erro. But the string value is not set in the item object. Please suggest on How to fix this issue.

Note: Passing string value will be available as repository item in the associated Repository. Eg: Passing string value will be somethins like this. "repo.rootItem.Item1Info"

Re: How to set the string value to RepoItemInfo object?

Posted: Thu Feb 20, 2014 11:21 am
by Swisside
Hello,

I'm not sure I understand what you want to do with this method.

If you check the attached printscreen there is no way of actually passing a parameter in a RepoItemInfo. Unless I missunderstood what you mean by "stores it into RepoItemInfo Object".

Could you develop a bit ?


Regards

Swiss'

Re: How to set the string value to RepoItemInfo object?

Posted: Thu Feb 20, 2014 3:28 pm
by ChrisDavid
Hi Swisside,

I want to perform this. RepoItemInfo item = RootItem.Folder1.Item1Info;

But "RootItem.Folder1.Item1Info" will be passed as string. I want to convert that string to RepoItemInfo.

Thanks,
Chris

Re: How to set the string value to RepoItemInfo object?

Posted: Thu Feb 20, 2014 8:12 pm
by odklizec
I'm afraid, it's currently impossible to use string parameter as a repo element reference. The only way how to achieve what you want seems to be using Reflection (quite complex) or searching the repository elements. See this post and previous discussions on that subject...
http://www.ranorex.com/forum/pass-repos ... tml#p23444