How to get the Test case name if smart folder is present in the testcase?

Class library usage, coding and language questions.
praneet
Posts: 38
Joined: Thu Nov 08, 2018 2:22 am

How to get the Test case name if smart folder is present in the testcase?

Post by praneet » Wed May 15, 2019 8:32 am

Hi,

I want to get the testcase name when smart folder is present in the test case.I tried using the below code.

Code: Select all

var curTestCase = (TestCaseNode)TestSuite.CurrentTestContainer;
			string tcName = curTestCase.Name;
			 TC = TestSuite.Current.GetTestContainer(tcName);
but the above code is returning the smartfolder nameinstead of test case name
Can anyone provide me the solution.Thanks in advance!! :)

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

Re: How to get the Test case name if smart folder is present in the testcase?

Post by odklizec » Wed May 15, 2019 8:44 am

Hi,

I'm using code like this (used in codemodule), which is placed anywhere in test and which returns 'root' test case name:

Code: Select all

TestModuleLeaf curModule = (TestModuleLeaf)TestModuleLeaf.Current;
string rootTCName = CommonCodeCollection.UserCodeCollection.SystemLib.GetRootTestCaseName(curModule);
And here is the actual GetRootTestCaseName method:

Code: Select all

public static string GetRootTestCaseName(TestSuiteEntry entry)
{
    string rootname = string.Empty;
    while (entry != null)
    {
        if ((entry is TestCaseNode) && (!(entry as TestCaseNode).IsRootTestCase && !(entry as TestCaseNode).IsSmartFolder))
        {
            rootname = entry.Name;
        }
            entry = entry.Parent;
    }
    return rootname;	
}
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

praneet
Posts: 38
Joined: Thu Nov 08, 2018 2:22 am

Re: How to get the Test case name if smart folder is present in the testcase?

Post by praneet » Wed May 15, 2019 10:22 am

Awesome!It works .Thank you :D

How can we get the CurrentRowIndex after getting the testcase name for the above scenario if the datasource is Excel data connector?
For eg:

Code: Select all

var curTestCase = (TestCaseNode)TestSuite.CurrentTestContainer;
			string tcName = curTestCase.Name;
			TC = TestSuite.Current.GetTestContainer(tcName);
			
			int rowId1 = TC.DataContext.CurrentRowIndex;

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

Re: How to get the Test case name if smart folder is present in the testcase?

Post by odklizec » Wed May 15, 2019 11:09 am

Hi,

You are welcome. As for the second question, I'm using code like you posted and it works OK? So if you want to use the root TC name, obtained with the code I posted, simply remove the first two lines from your code and replace tcName with rootTCName. This should do the trick.
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