Page 1 of 1

Pattern matching on RepoItemInfo

Posted: Mon Mar 11, 2019 5:18 pm
by jmarkman
Is it possible to perform pattern matching on RepoItemInfo objects? I'm working on a test where there might be one window or another, and I'd like to perform an action based on whichever window's RepoItemInfo is returned first. I've tried something similar to the following

Code: Select all

RepoItemInfo myCoolWindow = GetTheFirstActiveWindow();

if (myCoolWindow is MyProgramRepo.Instance.CoolWindow.SelfInfo)
{
	// do stuff
}
else if (myCoolWindow is MyProgramRepo.Instance.FunWndow.SelfInfo)
{
	// do other stuff
}
but when I try to build before running, I get a compiler error telling me that the repository Instance doesn't exist in the repository type. Is there a different way to go about pattern matching?

Re: Pattern matching on RepoItemInfo

Posted: Mon Mar 11, 2019 9:16 pm
by N612
Would using an RxPath which returns both windows work? If only one exists at a time, then the RxPath will only return the one. If both exist at the same time, then Ranorex will return the first one. If you want the second one, use an index:

Use second returned item (fails if only one item exist):

Code: Select all

/dom[@domain='www.ranorex.com' or @domain='www.google.com'][2]
or select the last returned (works even if only one item exists):

Code: Select all

/dom[@domain='www.ranorex.com' or @domain='www.google.com'][-1]
From here, you can use a Validate or GetAttributeValue method to verify which window exists and perform the specific actions desired. e.g.:

Code: Select all

string winTitle = formRun.Self.GetAttributeValue<string>("title");
if (winTitle == "Run")
	Report.Info("Window 1!");
else if (winTitle == "Run_2")
	Report.Info("Window 2!");