How to store repository objects for later use

Class library usage, coding and language questions.
carsonw
Posts: 178
Joined: Tue Nov 08, 2011 10:01 pm

How to store repository objects for later use

Post by carsonw » Wed Apr 18, 2012 9:17 pm

Our design approach depends on being able to store object repository references for later use. We can definitely change our approach if necessary, but this approach has a number of advantages and I hope it's not working because of something I'm not understanding rather than some sort of limitation.

I'll do the best I can to explain what we're doing and how it's failing.

When interfacing with our UI, we use classes that represent a fairly generic type (such a "TextField" or "ComboBox" etc. that inherit from even more generic types (such as "Field").

These types get added to "Sections" (a collection of Fields), which get added to "Pages" (a collection of Sections).

We then have virtual methods that can be overridden to implement certain functionalities. This approach allows us to very quickly set up methods which can set and verify large amounts of fields very easily across different applications and so forth.

The problem is this - if we try to add the repository object to our class, we have to be on the page where the object exists to do so, if we're not, it says the object cannot be found. Conceptually, this did not make sense to us because we thought we were just adding the object repository reference, rather than the actual object itself.

However, it seems that when referring to the xPath in the repository, Ranorex is actually trying to use the object itself.

Now, if we are on the page when we try and add the objeects to our class, it's fine. However, if we navigate away from the page, and use the same object to verify some results later, the object again cannot be found - even though you can find it in the spy.

To me, it seems like the object is retrieved every time and some attributes are added "live", so when you try and refer to it later, it no longer matches (even though the xPath is the same and the object can be found with the Spy).

Here is a sample of what it looks like:

Code: Select all

switch (kvp.Key) 
			{
			   case WUCreditLimits.SPOTTRANSACTION:
				this.fields.Add(new WUMoneyField(WUMPPApp.WUGetRepository().WUMppHome.Customer.PayablesSettings.CreditLimits.Limits.TextSpotLimit, kvp, moneyFormat));
			   break;
                         }


public WUMoneyField(Ranorex.InputTag textFieldObject, KeyValuePair<string, object> testField, string format) : base (textFieldObject, testField)
		{
			this.format = format;
		}
		
		/// <summary>
		/// Sets the field value to the passed in the constructor.
		/// </summary>
		public override void SetWUField()
		{						
			if (testField.Value == "*")
			{
				Random randomDecimal = new Random();					
				testField = new KeyValuePair<string, string>(testField.Key, randomDecimal.Next().ToString());
				((Ranorex.InputTag)repObject).Value = testField.Value;
				((Ranorex.InputTag)repObject).Click();
			}
			else
			{				
				base.SetWUField();
			}						
		}
Again, this works great as long as we never leave the page. If we leave the page, the entire system falls apart.
One solution I was thinking of was to add the xPath of the object instead of the actual object, and then creating it in the set/verify methods. I'll see if that approach works...

But there's something I'm not understanding about how repository objects are managed during runtime that's preventing this from working as is now.

Any insights would be much appreciated!

Carson.

carsonw
Posts: 178
Joined: Tue Nov 08, 2011 10:01 pm

Re: How to store repository objects for later use

Post by carsonw » Thu Apr 19, 2012 1:30 am

As an update to this, I've found a work around by using the path and getting the object each time - that's the good news.

The bad news is that there is no way to touch an object in the repository during runtime without actually having the object visible on the screen. This is frustrating, because I all I want to do is get the path that's stored in the repository so I can use Host.Local.FindSingle but I can't get the path (i.e. WUMPPApp.WUGetRepository().WUMppHome.Customer.PayablesSettings.CreditLimits.Limits.TextSpotLimit.GetPath()) without having the object visible.

I don't get it - is there any way to access and use the path that's in the repository so I can get my own objects when I want (so I can make references to them before they are visible).

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: How to store repository objects for later use

Post by Support Team » Fri Apr 20, 2012 11:18 am

carsonw wrote:The bad news is that there is no way to touch an object in the repository during runtime without actually having the object visible on the screen. This is frustrating, because I all I want to do is get the path that's stored in the repository so I can use Host.Local.FindSingle but I can't get the path (i.e. WUMPPApp.WUGetRepository().WUMppHome.Customer.PayablesSettings.CreditLimits.Limits.TextSpotLimit.GetPath()) without having the object visible.
For sure this is possible, you just have to use the info item of your repo item. For example
repo.NewAppFolder.NewItemInfo.AbsolutePath.ToString()
Regard,
Peter
Ranorex Team

carsonw
Posts: 178
Joined: Tue Nov 08, 2011 10:01 pm

Re: How to store repository objects for later use

Post by carsonw » Fri Apr 20, 2012 7:20 pm

This is great! Thanks so much, this is a huge help. You saved our design (which we really liked!) :)