API - TestContainer use as var

Class library usage, coding and language questions.
lyubenov
Posts: 2
Joined: Tue Dec 12, 2017 9:17 am

API - TestContainer use as var

Post by lyubenov » Tue Dec 12, 2017 9:27 am

Hi All,

The purpose of the below is to write a text file with the result of specific case. It works ok, when I specify the GetTestContainer to be equal to specific test case. (in the example it is "testercho"), but I would like to use the code as universal end recording through my test suite. I tried with "TestSuite.Current.Name, but it is not giving me the TestContainer name. What is the proper api call for this?

Thanks,
Lyubo.

Code: Select all

public static void Output2()
        {   
			     	
           string result = "";
    
            if(TestSuite.Current == null){
           	using (StreamWriter writer =
                  new StreamWriter("C:\\ovca\\null.txt"))
           {
              writer.WriteLine("test suite is null");
           		                 return;
           }
           }
           //ITestContainer iCase = TestSuite.Current.GetTestContainer("testercho"); // It works ok, when Testcontainer is hardcoded
           ITestContainer iCase = TestSuite.Current.GetTestContainer(TestSuite.Current.Name); // Here, I try with TestSuire current, but it is not the proper entry
            int testrunID = 666;
           if(iCase == null){
           	result = "iCase is Nullable";
           }
           else{
          
           	if(iCase.Status == Ranorex.Core.Reporting.ActivityStatus.Failed){
              result = "Failed"; }
           if(iCase.Status == Ranorex.Core.Reporting.ActivityStatus.Success){ 
              result = "Passed"; }
           }
           
           using (StreamWriter writer =
                  new StreamWriter("C:\\ovca\\"+ TestSuite.Current.Name +".TXT"))
           {
              writer.WriteLine(testrunID);
              writer.WriteLine(result);              
           }
        }
    
     
    
    }
}

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

Re: API - TestContainer use as var

Post by odklizec » Wed Dec 13, 2017 8:47 am

Hi,

This code should help:

Code: Select all

var curTestCase = (TestCaseNode)TestSuite.CurrentTestContainer; 
string curTCName = curTestCase.Name; 
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

lyubenov
Posts: 2
Joined: Tue Dec 12, 2017 9:17 am

Re: API - TestContainer use as var

Post by lyubenov » Wed Dec 13, 2017 10:39 am

odklizec wrote:Hi,

This code should help:

Code: Select all

var curTestCase = (TestCaseNode)TestSuite.CurrentTestContainer; 
string curTCName = curTestCase.Name; 
You rule,
Thank you! :)