Page 1 of 1

RepoItemInfo cache of AbsolutePath

Posted: Tue Dec 14, 2010 4:01 pm
by martinO
Hi there

I made a little method to detect a window of my application with windowtitle. (SelfInfo is of type RepoItemInfo)
First time I invoke this method it works as expected.
After that the AbsolutePath in SelfInfo is set to "/form[@automationid='MainView']" and when I invoke the method the second time, the absolute path is set to "/form[@automationid='MainView']/form[@automationid='MainView' and @windowtext~'^somepath']" and that's why the window could not be located.

What can I do? Disable the cache on this.MyForm.UseCache doesn't work...
And this.MyForm.SelfInfo.AbsolutePath is readonly and I cannot reset this

Thanks in advance


Martin

public void SelectSolutionManagerWindowByFileName(string openedFileName)
{
  this.MyForm.SelfInfo.Path = string.Format(
    "/form[@automationid='MainView' and @windowtext~'^{0}']",
    openedFileName);
}

Re: RepoItemInfo cache of AbsolutePath

Posted: Tue Dec 14, 2010 7:07 pm
by Support Team
It looks like you change the path of the wrong repository item. I'm not 100% sure without seeing your repository, but could it be that "MyForm" has a parent folder? If so, try changing the path of the parent folder instead of changing the path of "MyForm". Changing the RepoItemInfo.Path property always changes the relative path of the item with, not its absolute path.

Regards,
Alex
Ranorex Team

Re: RepoItemInfo cache of AbsolutePath

Posted: Wed Dec 15, 2010 8:42 am
by martinO
Hi Alex

MyForm has no parent folder.
protected MyRepositoryFolders.MyAppFolder MyForm
{
    get { return MyRepositoryFolders.Instance.Form1; }
}
Is it possible just to detect the window by windowtitle? Now the error is "Ranorex.ElementNotFoundException : No element found for path '/form[@automationid='MainView']/form[@automationid='MainView' and @windowtext~'^someTitle']' within 30s."

How can I change the query just to detect with the windowtext? Something like that
public void SelectSolutionManagerWindowByFileName(string openedFileName)
{
  this.MyForm.SelfInfo.Path = string.Format(
    "/self[@windowtext~'^{0}']",
    openedFileName);
}
so I get the path '/form[@automationid='MainView']/with[@windowtext~'^someTitle']' or similar

Thanks

Martin

Re: RepoItemInfo cache of AbsolutePath

Posted: Wed Dec 15, 2010 12:21 pm
by Support Team
Hi,

following code modification should work for you:

use
this.MyForm.BasePath = string.Format("/self[@windowtext~'^{0}']", openedFileName);
instead of
this.MyForm.SelfInfo.Path = string.Format("/self[@windowtext~'^{0}']", openedFileName);
You have to disable caching too, to ensure that the right path is taken.

Kind regards,
Tobias
Support Team

Re: RepoItemInfo cache of AbsolutePath

Posted: Wed Dec 15, 2010 2:34 pm
by martinO
Hi Tobias

Thanks a lot. It works (with a little change).

Working code:
public void SetUseCache(bool useCache)
{
    this.MyForm.UseCache = useCache;
}

public void SelectSolutionManagerWindowByFileName(string openedFileName)
{
    this.MyForm.BasePath = string.Format(
      "/form[@automationid='MainView' and @windowtext~'^{0}']",
      openedFileName);
}
I invoke SetUseCache(false); at the beginning of the test and SetUseCache(true); at the end of the test to enable caching for next tests.

Maybe this codefragment helps someone other in future.

Cheers