Page 1 of 1

Create RepoItemInfo object from string

Posted: Fri Jan 08, 2010 10:25 pm
by jlowder
Hello,

I can't seem to figure out how to convert a string representation of an objectInfo object to an actual objectInfo.

I have the method:

public static void FindScrubber(RepoItemInfo scrubTestInfo)
{
}

and I want to pass in the RepoItemInfo name, but it is in string form. So I have:

string myString = "AbsoluteValueInfo", and I'm trying to call FindScrubber(myString).

It's become readily apparent that languages other than Perl actually care about types. :-) I've tried looking up types and casting etc. but can't seem to figure out how to make the conversion. How might I do this?

Thanks,

Jason

Re: Create RepoItemInfo object from string

Posted: Mon Jan 11, 2010 6:29 pm
by Support Team
jlowder wrote:I can't seem to figure out how to convert a string representation of an objectInfo object to an actual objectInfo.
Sorry, I'm not sure that I know what you mean. I guess by "string representation of an objectInfo object" you mean the RanoreXPath that identifies an UI element and you want to create a RepoItemInfo instance for that path. Am I correct?

The RepoItemInfo class is intended for use with Ranorex repositories only. If you use Ranorex repositores, Ranorex creates a RepoItemInfo object for every item/folder in the repository. You can pass these RepoItemInfo objects to the method I posted in the following thread:
http://www.ranorex.com/forum/passing-ob ... html#p4153

Creating a RepoItemInfo from a RanoreXPath directly is possible, but not that easy. I recommend you create a new item in your repository with the RanoreXPath "AbsoluteValueInfo" (at least I think that this should be a RanoreXPath).

Regards,
Alex
Ranorex Support Team

Re: Create RepoItemInfo object from string

Posted: Mon Jan 11, 2010 7:21 pm
by jlowder
Hi Alex,

I'm looking for a means to pass in a RepoItemInfo object as a string and not as the object it's self.

Lets say that I grab the text from a list item at run time. That text happens to be the object name of another object in my webpage. If I won't know the name until run time, I need to grab that string reprsentation of the object (string myString = "ObjectName"), append "Info" to it (myString = "ObjectNameInfo") and then pass it to another method that allows me to work on that RepoItemInfo object. But because I'm passing the name in as a string "ObjectNameInfo" instead of ObjectNameInfo, Ranorex won't see it as an object.

so:

I can't do this:

public static void FindScrubber(RepoItemInfo scrubTestInfo)
{
}

and pass it string "ObjectItemInfo" because type string and type RepoItemInfo aren't the same.

Likewise if I have:
public static void FindScrubber(string scrubTestInfo)
{
}

and try scrubTestInfo.Exists, that will fail because scrubTestInfo isn't of type RepoItemInfo.

So how do I convert a string to be a RepoItemInfo object? That object will already exist in the Repository too..


Did that help any or make it worse? :-)

Thanks,

Jason

Re: Create RepoItemInfo object from string

Posted: Mon Jan 11, 2010 8:08 pm
by Ciege
I'm a bit confused. If you are getting an item at runtime that may or may not be different at each runtime, would it not be safe to say that that object is not in the repository, and as such, you would not need to use a repoitem object?

If that indeed is the case, you can search for any type of element you want to yourself using a string to append to create the XPath at runtime.

Re: Create RepoItemInfo object from string

Posted: Mon Jan 11, 2010 8:11 pm
by jlowder
Hi Ciege,

No. The list at run time has a list of object names. Those names do exist in the repository as object items for other areas on the page. I think the use of it is confusing people. What I need to know how to do is using reflection(?) convert a string object into a RepoItemInfo object.

Jason

Re: Create RepoItemInfo object from string

Posted: Tue Jan 12, 2010 10:04 pm
by Support Team
So, basically you want to get the RepoItemInfo object for a repository item with a specified name. I.e. at runtime you have the name of a repository item and want to get the corresponding RepoItemInfo object. Right?

I don't know another way to do that except for using reflections. If you're familiar with .NET reflections, that should not be much of a challenge, either. Basically, you need to search the repository classes for a property with the specified name (the name of the repository item) and then get the value of that property.
If you are not familiar with .NET reflections, you might want to consider the solution ciege suggested, that is creating the RanoreXPath of the repository item "on-the-fly".

I don't exactly know the scenario you need that functionality for, so I can't judge which solution is in my opinion more suited.

Regards,
Alex
Ranorex Support Team