How to set different timeouts for same element

Best practices, code snippets for common functionality, examples, and guidelines.
bygones
Posts: 31
Joined: Fri Nov 27, 2015 11:32 am

How to set different timeouts for same element

Post by bygones » Mon Nov 30, 2015 1:08 pm

Hi,

I have an element that I like to set different timeouts in different tests. But when I add the element to my test suite via the repository and set the timeout, all same elements in all other test suites are also updated with that timeout.

Is it possible to set the timeout individually ?

Thanks

I'm using Ranorex 5.4.3.26106

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

Re: How to set different timeouts for same element

Post by Support Team » Thu Dec 03, 2015 1:24 pm

Hi bygones,
The Searchtimeout is stored directly in the RepositoryItem.
In order to set the timeout individually per item you need to write a short userCode action. This action should contain the following lines of code
public void ModifySearchTimeOut(Ranorex.Core.Repository.RepoItemInfo RepositoryObject)
{
Duration oldTimeout;
Duration newTimeout=2000;
		
oldTimeout = RepositoryObject.SearchTimeout; //Save defaultTimeout
RepositoryObject.SearchTimeout=newTimeout; //Set new Timeout
//Do some things
RepositoryObject.SearchTimeout=oldTimeout; //Restore defaultTimeout
}
Now you can call this action within your recording module. As parameter you need to select the corresponding RepositoryItem
For example:
ActionTable_UserCode_SetTimeout.png
ActionTable_UserCode_SetTimeout.png (4.71 KiB) Viewed 768 times
Hope that helps.

Regards,
Markus (S)
.
Image

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

Re: How to set different timeouts for same element

Post by krstcs » Fri Dec 04, 2015 2:49 pm

Or, you could do the easy thing:

Create multiple copies of the repo item and change the timeouts of each to what you need. Just make sure to rename the items so you know which one you are using.

You can have as many repo items as you want all pointing to the same SUT element.
Shortcuts usually aren't...

bygones
Posts: 31
Joined: Fri Nov 27, 2015 11:32 am

Re: How to set different timeouts for same element

Post by bygones » Sat Dec 05, 2015 8:47 am

Thanks for the answers - I think krstcs answer fits my use case best.

User avatar
jasoncleo
Posts: 37
Joined: Mon Jun 08, 2015 7:37 am

Re: How to set different timeouts for same element

Post by jasoncleo » Wed Dec 16, 2015 4:13 am

Hi ByGones,

Depending on whether you write your tests via Code Modules or the Recording Modules.

Recording Modules
If you're using the Recording Modules, then perhaps krstcs' suggestion is easiest. However the potential issue is that it'll increase your maintenance overhead down the track if the developers modify the UI. Instead of having one of each UI item to change, you now have several instances of some UI elements that need to be looked up and modified, possibly across different UI repositories.

The other thing to remember, is that in your UI repository, the timeout is cumulative as you move through the Rooted folders to the UI element.

Ultimately though, I don't have a better suggestion.

Code Modules
This offers you the greatest flexibility and there are a number of ways of tacking this:
  • 1. You can use the .Exists() method of the UI element Info, and pass your own duration to it.
    2. You could even write your own static method which takes a RXPath and timespan. (RXPath is obtained from the AbsolutePath property of the UI element Info). The benefit of this is you could also add in checks for visibility, or enabled, and that makes just a single call. You can also decide whether you have it just return a bool or throw exceptions based on your choice of failure handling.

bygones
Posts: 31
Joined: Fri Nov 27, 2015 11:32 am

Re: How to set different timeouts for same element

Post by bygones » Fri Dec 18, 2015 10:28 am

thanks for the posts - I will consider doing this via Code Modules