Repo item get's destroyed in user code after relocation in repo tree

Ranorex Studio, Spy, Recorder, and Driver.
julez90
Posts: 10
Joined: Thu Apr 25, 2019 2:32 am

Repo item get's destroyed in user code after relocation in repo tree

Post by julez90 » Mon Feb 21, 2022 11:49 pm

Hello,

is it the normal behavior that repo items used and referenced in user code modules get "crushed" as soon as i'm changing the the place where it is located within the object repository?

For example when i'm moving the repo item to another simple folder on another tree level in the repo hierarchy it gets partly "destroyed" and i have to fix it manually.

See the attachment for an example.


Kindly Regards and thanks in advance
julez
Attachments
repo_item_destroyed.png
repo_item_destroyed.png (10.75 KiB) Viewed 310 times

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7425
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Repo item get's destroyed in user code after relocation in repo tree

Post by odklizec » Tue Feb 22, 2022 8:10 am

Hi,

Yes, that's quite normal behavior. Ranorex does not automatically update such referenced repo elements in code. This is why you should not use them directly in code, but instead to pass them to methods via repoiteminfo or adapter parameter, like this (just an example):

Code: Select all

public static void SearchAnElement(RepoItemInfo repoElement)
{
    if (repoElement.Exists(10000))
    {
        var foundElement = repoElement.CreateAdapter<Ranorex.Unknown>(false).FindSingle("//*[@automationid='idstring'");
        ...
    }    
}
Where repoElement should be connected with repo item of your choice. Ideally, use RepoItemInfo, but of course, you can use directly Adapter, so there is no need to convert RepoItemInfo to Adapter in code. However, it's safer to use RepoItemInfo, because if the element does not (yet) exists at a time the test enters the method (with Adapter as a parameter), it may fail due to 'element not found' exception. This does not happen in case of RepoItemInfo! So even though it's faster to use Adapter, it's safer to RepoItemInfo ;)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

julez90
Posts: 10
Joined: Thu Apr 25, 2019 2:32 am

Re: Repo item get's destroyed in user code after relocation in repo tree

Post by julez90 » Tue Feb 22, 2022 3:34 pm

Hey odkilzec,

thank you very much for your helpful reponse.

I will take a look on that :-)


KG
julez