How to get elements of repository?

Ranorex Spy, Recorder, and Studio.
valentin
Posts: 27
Joined: Thu Nov 24, 2011 2:47 pm
Location: Moscow

How to get elements of repository?

Post by valentin » Mon Nov 28, 2011 1:41 pm

Hello,
I add new app simple folder APP1 with path Base: (empty). Then I include into this folder two form elements:
FORM1 with path Base: /form[@label1]
FORM2 with path Base: /form[@label2]
Now, after some actions, I want to validate whether exist and active at least one form of which is in the folder. How I can do this?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11710
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to get elements of repository?

Post by Support Team » Mon Nov 28, 2011 3:08 pm

Hello,

I assume that you have opened your recording in Ranorex Studio. In the recording file view, there is the actions table in the upper part, in the lower part, there is your repository.

Add actions according to a repository item with drag&drop.

Simply take e.g. FORM1 with the mouse, move it to the upper part (action table), and drop it there. Now, Ranorex pops up a context menu.
Select Validate for validation or InvokeAction for activating the form.

If selecting Validate, define the way of validation (Exists, NotExists, AttributeEqual....).
If selection InvokeAction, select the action (Activate, Maximize, Minimize...).

If you also want to have some logic within your operation (if exists then activate....), you have to write this within the code. Therefore, convert your action to user code.
For more information on this, go to Code Examples.

Best Regards,
Martin
Ranorex Support Team
.
Image

valentin
Posts: 27
Joined: Thu Nov 24, 2011 2:47 pm
Location: Moscow

Re: How to get elements of repository?

Post by valentin » Tue Nov 29, 2011 8:16 am

Hello,
You misunderstood what I want.
I use Code Module...
I have repo like:

Code: Select all

    public partial class Repository1 : RepoGenBaseFolder
    {
        static Repository1 instance = new Repository1();

        /// <summary>
        /// Gets the singleton class instance representing the Repository1 element repository.
        /// </summary>
        [RepositoryFolder("35280bb3-a253-48d5-b6e0-c574a9d7725b")]
        public static Repository1 Instance {
            get { return instance; }
        }

        Repository1Folders.ExceptionFolder _exception;

        /// <summary>
        /// Repository class constructor.
        /// </summary>
        public Repository1() : base("Repository1", "", null, 1000, false)
        {
            _exception = new Repository1Folders.ExceptionFolder(this);
        }

#region Variables

#endregion

        /// <summary>
        /// The Exception folder.
        /// </summary>
        [RepositoryFolder("47cc52d4-fc5e-4056-a08f-abd17838b197")]
        public virtual Repository1Folders.ExceptionFolder Exception
        {
            get { return _exception; }
        }
    }

    /// <summary>
    /// Inner folder classes.
    /// </summary>
    public partial class Repository1Folders
    {
        /// <summary>
        /// The ExceptionFolder folder.
        /// </summary>
        [RepositoryFolder("47cc52d4-fc5e-4056-a08f-abd17838b197")]
        public partial class ExceptionFolder : RepoGenBaseFolder
        {
            RepoItemInfo _formerror1Info;
            RepoItemInfo _formerror2Info;

            /// <summary>
            /// Creates a new Exception  folder.
            /// </summary>
            public ExceptionFolder(RepoGenBaseFolder parentFolder) :
                    base("Exception", "", parentFolder, 0, false, "47cc52d4-fc5e-4056-a08f-abd17838b197")
            {
                _formerror1Info = new RepoItemInfo(this, "FormError1", "/form[@title='Title1']", 1000, null, "8594760b-fed9-4dfc-8595-57ac8271c5bc");
                _formerror2Info = new RepoItemInfo(this, "FormError2", "/form[@title='Title2']", 1000, null, "05b52f8f-8129-43d5-9c6e-b79763a38bde");
            }

            /// <summary>
            /// The FormError1 item.
            /// </summary>
            [RepositoryItem("8594760b-fed9-4dfc-8595-57ac8271c5bc")]
            public virtual Ranorex.Form FormError1
            {
                get
                {
                    return _formerror1Info.CreateAdapter<Ranorex.Form>(true);
                }
            }

            /// <summary>
            /// The FormError1 item info.
            /// </summary>
            [RepositoryItemInfo("8594760b-fed9-4dfc-8595-57ac8271c5bc")]
            public virtual RepoItemInfo FormError1Info
            {
                get
                {
                    return _formerror1Info;
                }
            }

            /// <summary>
            /// The FormError2 item.
            /// </summary>
            [RepositoryItem("05b52f8f-8129-43d5-9c6e-b79763a38bde")]
            public virtual Ranorex.Form FormError2
            {
                get
                {
                    return _formerror2Info.CreateAdapter<Ranorex.Form>(true);
                }
            }

            /// <summary>
            /// The FormError2 item info.
            /// </summary>
            [RepositoryItemInfo("05b52f8f-8129-43d5-9c6e-b79763a38bde")]
            public virtual RepoItemInfo FormError2Info
            {
                get
                {
                    return _formerror2Info;
                }
            }
        }

    }
Now, I want to check whether exist at least one element (FormError1, FormEeror2, ...) from folder Exception. For this I try to do a loop cycle to get all the elements (FormError1 , FormError2, ...) from folder Exception.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11710
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to get elements of repository?

Post by Support Team » Tue Nov 29, 2011 11:30 am

Hi,
valentin wrote:Now, I want to check whether exist at least one element (FormError1, FormEeror2, ...) from folder Exception. For this I try to do a loop cycle to get all the elements (FormError1 , FormError2, ...) from folder Exception.
You want to reflect the code of the whole repository and check if items are inside this code file? Or do you want to call the items of your repository in an user code module?
If you want to call the elements of the repository please take a look to the above mentioned link by Martin.
Otherwise you have to use reflection of .Net Framework.

Regards,
Peter
Ranorex Team
.
Image

valentin
Posts: 27
Joined: Thu Nov 24, 2011 2:47 pm
Location: Moscow

Re: How to get elements of repository?

Post by valentin » Wed Nov 30, 2011 7:21 am

I want to get collection - all info items (with type RepoItemInfo) which are in simple folder repository APP1 in a CodeModule. How I can do this?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11710
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to get elements of repository?

Post by Support Team » Wed Nov 30, 2011 11:59 am

Hi,

Am I right that you want to get all child items of a simple folder as type RepoItemInfo?

This is not possible out of the box with Ranorex Framework, you have to do this with reflection of .Net Framework.

Best Regards,
Martin
Ranorex Support Team
.
Image