Current test Container and Activity not working

Ask general questions here.
kumprave5
Posts: 33
Joined: Wed Jul 18, 2018 9:55 pm

Current test Container and Activity not working

Post by kumprave5 » Fri Aug 03, 2018 3:33 pm

My Code

I got the below code from this old post but it is not working (test-suite-error-behavior-t2064.html). Throws error "cannot convert from 'Ranorex.Core.Reporting.ITestContainerActivity' to 'Ranorex.Core.Reporting.Activity'

Code: Select all

namespace Workshop.Web
{
    [TestModule("56FB755F-1C85-4E07-B4FB-3BDF6D0B9435", ModuleType.UserCode, 1)]
    public class TearDownMethod : ITestModule
    {
        public TearDownMethod()
        {    
        }
        public static void search(Activity act)
        {	 
        	static public Activity failed = null;
        	 foreach (Activity child in act.Children)    
                {  
                    if (child is TestModuleActivity)  
                    {  
                            if (child.Status == Ranorex.Core.Reporting.ActivityStatus.Failed)  
                            {
                            	failed = child;    
                            }   
                    }  
                    else  
                        search(child);  
                } 
        }
        
        public void TestFail()  
        {  
              TearDownMethod.search(TestReport.CurrentTestContainerActivity);  
              if (TearDownMethod.search. != null)    
                  {    
                        Report.Info("Failure in this test case");  
                  } 
        }  

         void ITestModule.Run()
         {
        	TestFail();
          }
            
   }
}

McTurtle
Posts: 191
Joined: Thu Feb 23, 2017 10:37 am
Location: Benedikt, Slovenia

Re: Current test Container and Activity not working

Post by McTurtle » Tue Aug 07, 2018 3:21 pm

Hello kumprave5,

This is very old code. Furthermore, it might have already been superseded by some new feature... Would you care to explain the exact use case in more detail?

Regards,
McTurtle

kumprave5
Posts: 33
Joined: Wed Jul 18, 2018 9:55 pm

Re: Current test Container and Activity not working

Post by kumprave5 » Tue Aug 07, 2018 3:29 pm

For example: I have 2 smart folder and under each smartfolder there are 4 test cases and under each test case there are 10 modules. Now, i want to know which module passed or failed, test case passed or failed under each smartfolder.

Today, I tried below mentioned code, but in this status and TestResult.Passed are not type compatible.
var status = TestReport.CurrentTestModuleActivity.Status;
if(status == TestResult.Passed)
{
LogUtility._info("I am passed");
}

McTurtle
Posts: 191
Joined: Thu Feb 23, 2017 10:37 am
Location: Benedikt, Slovenia

Re: Current test Container and Activity not working

Post by McTurtle » Thu Aug 09, 2018 3:45 pm

kumprave5,

You could do the following
void ITestModule.Run()
		{
			var status = TestReport.CurrentTestContainerActivity.Status.ToString();
			if(status == "Success")
			{
				Report.Info(TestSuite.CurrentTestContainer.Name + " passed!");
			}
			else
			{
				Report.Info(TestSuite.CurrentTestContainer.Name + "Failed!");
			}
			
			var recordings_Statuses= TestReport.CurrentTestContainerActivity.Children;
		
			
			foreach (Activity child in recordings_Statuses)
			{
				Report.Info(child.Status.ToString());
			}
			
		}
You need to call this in the teardown because the statuses of the recordings are known by then.

Does this help?

Regards,
McTurtle

kumprave5
Posts: 33
Joined: Wed Jul 18, 2018 9:55 pm

Re: Current test Container and Activity not working

Post by kumprave5 » Thu Aug 09, 2018 4:30 pm

Yes, it worked for me. Thank you so much.