How to set the string value to RepoItemInfo object?

Experiences, small talk, and other automation gossip.
ChrisDavid
Posts: 7
Joined: Wed Feb 19, 2014 3:27 pm

How to set the string value to RepoItemInfo object?

Post by ChrisDavid » Wed Feb 19, 2014 3:50 pm

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"

Swisside
Posts: 92
Joined: Thu Oct 10, 2013 10:40 am

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

Post by Swisside » Thu Feb 20, 2014 11:21 am

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'
You do not have the required permissions to view the files attached to this post.
A simple thank you always does wonders !

ChrisDavid
Posts: 7
Joined: Wed Feb 19, 2014 3:27 pm

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

Post by ChrisDavid » Thu Feb 20, 2014 3:28 pm

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

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

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

Post by odklizec » Thu Feb 20, 2014 8:12 pm

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
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