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: 254
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: 254
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.

haider
Posts: 10
Joined: Mon Oct 08, 2018 2:15 pm

Re: Current test Container and Activity not working

Post by haider » Thu Jan 31, 2019 2:43 pm

Hi,

I'm facing the same issue.
What i want is to get the UserCodeModule status and it's name.

This works

Code: Select all

string tcName = TestModuleLeaf.Current.Name;
//it gives me the UserCodeModule name
But the ActivityStatus doesn't work

Code: Select all

var status = TestReport.CurrentTestContainerActivity.Status.ToString();
        	if(status== "Success")
            {  
                Report.Info(TestSuite.CurrentTestContainer.Name + " passed!");  
            }  
            else  
            {  
                Report.Info(TestSuite.CurrentTestContainer.Name + "Failed!");  
            }  
Thx in advance
Haider

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

Re: Current test Container and Activity not working

Post by odklizec » Thu Jan 31, 2019 2:56 pm

Hi,

Please answer below questions...
Are you using most recent Ranorex version? If not, please install and try most recent Ranorex 8.3.2.
At next, where exactly is placed your code? Please make sure it's located in Test Case/Test Suite TearDown section!
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

haider
Posts: 10
Joined: Mon Oct 08, 2018 2:15 pm

Re: Current test Container and Activity not working

Post by haider » Thu Jan 31, 2019 2:58 pm

I'm answering myself :D :shock: :lol:

I found this

Code: Select all

if (Ranorex.Core.Reporting.ActivityStack.Current.Status.Equals(Ranorex.Core.Reporting.ActivityStatus.Success)) {
        		Report.Info("Succes");
        	}
        	else
        		Report.Info("Fail");
It works but do you know if there's another way to put the status in a variable ?

Thx

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

Re: Current test Container and Activity not working

Post by McTurtle » Fri Feb 01, 2019 2:49 pm

Hello haider,

I guess it works if it's in the teardown ;)

You already have "Ranorex.Core.Reporting.ActivityStack.Current.Status" and "TestReport.CurrentTestContainerActivity.Status". I don't think there is more... Why would you want another way?

Regards,
McTurtle