Get all children of a Test Container?

Ask general questions here.
mrt
Posts: 88
Joined: Mon Mar 16, 2020 11:31 am

Get all children of a Test Container?

Post by mrt » Fri Apr 09, 2021 1:39 pm

Dear folks,

how can I get all Test containers that are children of a parent Test Container (Test case, Smart folder) in User code?

thank you, BR mrt

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

Re: Get all children of a Test Container?

Post by odklizec » Fri Apr 09, 2021 2:21 pm

Hi,

I think you are looking for something like this?...
viewtopic.php?f=20&t=10269&p=45794
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

mrt
Posts: 88
Joined: Mon Mar 16, 2020 11:31 am

Re: Get all children of a Test Container?

Post by mrt » Mon Apr 12, 2021 9:14 am

Hi,

great, thank you!

The cast to (TestCaseNode) did the trick, now I will figure out what the AllModules contain and how to use the IsDescendant function.
I was not able to find a documentation item for the method IsDescendantOfSetupNode, where is this located?

thanks!

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

Re: Get all children of a Test Container?

Post by odklizec » Mon Apr 12, 2021 9:25 am

Hi,
I'm afraid, there is no description anywhere in the API documentation. But don't ask me how I figured it out :D it was either suggested to me by Ranorex support or I luckily found it in the list of available methods while writing/debugging this code? :D
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

mrt
Posts: 88
Joined: Mon Mar 16, 2020 11:31 am

Re: Get all children of a Test Container?

Post by mrt » Mon Apr 12, 2021 9:43 am

Haha, nice.
I assume that IsDescendantOfSetupNode() gets all items inside the Setup section (which is not what I am looking for).

After some debug-fiddling it seems like the following is what I am after:

Code: Select all

var currentTestContainer = (TestCaseNode) TestSuite.CurrentTestContainer;
var list = currentTestContainer.GetDescendantTestCases();
But this finds all Testcases and Smart folders, also the nested ones.

Code: Select all

var currentTestContainer = (TestCaseNode) TestSuite.CurrentTestContainer;
var list = currentTestContainer.GetDescendantTestCases().Where(x => x.ParentContainer == currentTestContainer); 
This way I get only those top-level TestCaseNodes which are immediate children of the currentTestContainer, which seems to be sufficient in my case.

thanks!

mrt
Posts: 88
Joined: Mon Mar 16, 2020 11:31 am

Re: Get all children of a Test Container?

Post by mrt » Mon Apr 12, 2021 9:47 am

Hmm ok, but the container itself does not contain a definition for the 'Enabled' property, only TestModuleLeaf (whatever that is) seems to have it.
I will try to cast all this stuff around. :)

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

Re: Get all children of a Test Container?

Post by odklizec » Mon Apr 12, 2021 10:47 am

Hi,

What exactly you want to achieve? Maybe you are looking for this code instead?...
replay-a-test-inside-user-code-t10087.html#p40593
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

mrt
Posts: 88
Joined: Mon Mar 16, 2020 11:31 am

Re: Get all children of a Test Container?

Post by mrt » Mon Apr 12, 2021 11:29 am

Hi,

sorry,
what I want to achieve is the implementation of powerful conditions that do not handle hardcoded strings only.

I have a parent Container, and in the first recording module of this container (preferably in setup section) I want to enable/disable child containers at runtime, depending on data source values.
Like you did, if I remember correctly.

So in one code module I want to decide which of the child containers should be enabled,
prior to this I have to disable all child containers, which initially led me to the question.

but I guess I got it working:

Code: Select all

var currentTestContainer = (TestCaseNode) TestSuite.CurrentTestContainer;
DataContext currentDataContext = GetCurrentDataContext(currentTestContainer);
// gets value of current iteration from data source in column "Type"
string currentType = currentDataContext.CurrentRow.Values[currentDataContext.Source.Columns["Type"].Index];
    		
var allChildContainers = currentTestContainer.GetDescendantTestCases().Where(x => x.ParentContainer == currentTestContainer).ToList();
			
List<TestCaseNode> allCheckedChildContainers = allChildContainers.Where(x => x.Checked == true).Select(x => x).ToList();
			
foreach (TestCaseNode tc in allCheckedChildContainers)
{
	Report.Log(ReportLevel.Info, "Select Container", "Disable Test container '" + tc.DisplayName + "'.");
	tc.Checked = false;
}

// enable only matching test container for "Type"
TestCaseNode container = (TestCaseNode)TestSuite.Current.GetTestContainer(containerName);

if (container != null)
{
	Report.Log(ReportLevel.Info, "Select Container", "Enable Test container '" + container.DisplayName + "'.");
	TestSuite.Current.GetTestContainer(containerName).Checked = true;
}
else
{
	throw new ElementNotFoundException("Test container '" + containerName + "' could not be found!'");
}
Looks quite promising on first run, I will have a closer look, but this should to I guess.

thank you!

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

Re: Get all children of a Test Container?

Post by odklizec » Mon Apr 12, 2021 12:14 pm

Nice to hear you figured it out! It looks fine from my point of view. Good luck then ;)
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

mrt
Posts: 88
Joined: Mon Mar 16, 2020 11:31 am

Re: Get all children of a Test Container?

Post by mrt » Mon Apr 12, 2021 12:38 pm

Thanks!