Page 1 of 1

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

Posted: Wed May 15, 2019 8:32 am
by praneet
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!! :)

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

Posted: Wed May 15, 2019 8:44 am
by odklizec
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;	
}

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

Posted: Wed May 15, 2019 10:22 am
by praneet
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;

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

Posted: Wed May 15, 2019 11:09 am
by odklizec
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.