Page 1 of 1

Access Folder Name in the rxtst file

Posted: Mon Mar 26, 2012 6:37 pm
by Prad
Hi ,

How can i access the parent folder name of the test case being executed ?

since our test cases are organized by categories in the rxtst file ,
and have corresponding config files organized in the same manner,

would like avoid parsing through multiple directories to get to the correct file

Did not see a parameter in TestSuite.current for this value ?


[folder] Category 1
TestCase 1
TestCase 2
TestCase 3
....
[folder] Category 2
TestCase 1
TestCase 2
TestCase 3
....
[folder] Category 3
TestCase 1
TestCase 2
TestCase 3
....

please advice

Regards,
Prad

Re: Access Folder Name in the rxtst file

Posted: Wed Mar 28, 2012 9:53 am
by Support Team
Hi,

You can use this code to get the parent folder name, or you can use the second one to print/get the whole test suite structure:

Input this code in one of your files of the actual test case.
first:
var TC = (TestCase)TestCase.Current;
      if (TC.Parent.GetType() == typeof (TestSuiteFolder) )
      {
        var parTC = TC.Parent;
        Report.Info (TC.Parent.DisplayName);
      }
Just input the code into a UserCode file of your solution.
second:
void ITestModule.Run()
    {
      Mouse.DefaultMoveTime = 300;
      Keyboard.DefaultKeyPressTime = 100;
      Delay.SpeedFactor = 1.0;
      
      TestSuite TS = (TestSuite)TestSuite.Current;
      
      PrintChildren(TS.TestSuiteEntry, 0);
    }
    
    void PrintChildren(TestSuiteEntry entry, int depth)
    {
      String whitespaces = "";
      for(int i=0;i<depth;i++)
        whitespaces += "--";
      
      foreach(TestSuiteEntry child in entry.Children)
      {
        Report.Info(whitespaces + child.DisplayName);
        PrintChildren(child, depth + 1);
      }
    }
I have also attached the created UserCode file.

Regards,
Markus
Ranorex Support Team