Problem with code snippet

Ranorex Spy, Recorder, and Studio.
Tnimni
Posts: 49
Joined: Thu Jan 02, 2014 4:03 pm

Problem with code snippet

Post by Tnimni » Sun Apr 06, 2014 2:43 pm

Hi,

I have a custom txtBox which on a double click >> opens a form on which there is a table, there you select a value from that table and the value selected will appear on the txtBox

i wrote a method that receive the txtBox, expected form that supposed to be open and the table that i have to select the value from

problems is Ranorex hangs when entering the method, more specifically it hangs on this code snippet

Code: Select all

      /// <summary>
            /// The TableAgreementType item.
            /// </summary>
            [RepositoryItem("baf8f1fe-b09a-4e35-a692-d8d8bb5cca37")]
            public virtual Ranorex.Table TableAgreementType
            {
                get
                {
                    return _tableagreementtypeInfo.CreateAdapter<Ranorex.Table>(true);
                }
            }
i noticed that in debug mode and suspected that it happens because the "Table" is not visible on the screen, and indeed if i perform a double click and the table appears the code continue to execute.

so here is my problem
1. why is the table needs to be visible in order to "retrieve" it from repository?
2. i need 1 method to click on the field and than wait for the table to appear and than select the value, i do not wish to split it into separate methods.

is there a workaround is it a bug, or is it supposed to work like so?

Regards,
tnimni

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Problem with code snippet

Post by krstcs » Mon Apr 07, 2014 2:17 pm

This is not a bug. This is how Ranorex is designed.

When you attempt to access a repository object from a test, Ranorex will attempt to find the object on screen. In this case, the object has not been created yet, and therefore, Ranorex cannot find it and will wait until its SearchTimeout expires. This will throw an exception.

In your case, you might want to look at the API http://www.ranorex.com/Documentation/Ranorex/. You can use UserCode to get information about the object without making Ranorex try to find the object. You would want to use the ItemInfo object, not the Item object.


However, you could also use a "Delay" action in your module and delay for a few seconds after clicking the text box before attempting actions on the table dialog. This would give the system a chance to create the dialog before continuing.

You could also add a Validate Exists() action for the dialog, which would also wait until it exists, or until the timeout is reached (which would throw an exception for object not found).

So, it would look like:

1. Mouse -> Click -> txtBox
2. Delay -> 1000ms (give the system a chance to work before Ranorex checks)
3. Validate -> Exists -> tableDialog
4. <Do other stuff>
Shortcuts usually aren't...

Tnimni
Posts: 49
Joined: Thu Jan 02, 2014 4:03 pm

Re: Problem with code snippet

Post by Tnimni » Mon Apr 07, 2014 2:38 pm

Hi,

i have figured out i have to use the itemInfo

please have a look at the following code, as you can see i took the
1. repo.SfqipAgreementType.TableAgreementTypeInfo.AbsolutePath.ToString() and than used this inside the function in order to create the adapter and use it.

I wonder if this is the optimal solution, since it seems silly to have a repository item and not use it.

1st is the call to the method:

Code: Select all

Setter.SfqipWithSelect(repo.IBMS.CreateModifyMasterDeal.MainData.AgreementTypeInfo , repo.SfqipAgreementType.SelfInfo , repo.SfqipAgreementType.TableAgreementTypeInfo.AbsolutePath.ToString(), agreementType, repo.SfqipAgreementType.ButtonSelectInfo);
2nd is the method it self

Code: Select all

        public static void SfqipWithSelect(Ranorex.Core.Repository.RepoItemInfo sfqipBox, Ranorex.Core.Repository.RepoItemInfo form, string myTable, string valueToSelect,
                                           Ranorex.Core.Repository.RepoItemInfo buttonSelect)
        {
        	Ranorex.Control myControl = sfqipBox.CreateAdapter<Ranorex.Control>(true);
        	myControl.DoubleClick();
        	GeneralActions.WaitForObjectExistsAndEnabled(form, 5);
        	Table oTable = myTable;
        	Dictionary<string, string> rowToSelect = new Dictionary<string, string>();
        	rowToSelect.Add("Description", valueToSelect);
        	Getter.FindAndSelectRowFromTable(oTable, rowToSelect, true);
        	Setter.Click(buttonSelect);
        }
Regards,

Tsachi

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

Re: Problem with code snippet

Post by Support Team » Wed Apr 09, 2014 4:04 pm

Hello Tnimni

I’m glad that you found a solution, but it would be much easier to achieve your goal using one of the approaches mentioned by krstcs.

Regards,
Robert
.
Image