Page 1 of 1

Report Level - can I over ride in code?

Posted: Tue Apr 05, 2016 3:11 pm
by stapes
If my Test Suite has Report Level set to Warn (using the Right-Click menu), can I over-ride this setting in one of my Test Cases in code - for the rest of the Test Suite.

Report.CurrentReportLevel gets or sets the Current Report Level, and I have tried to do this by setting it to ReportLevel.Info in the Program.cs before running the TestSuiteRunner, but the setting does not persist.

The next Test case Continues with CurrentReportLevel=Warn.

How can I set this level & make it persist for the whole Test Suite?

Re: Report Level - can I over ride in code?

Posted: Tue Apr 05, 2016 4:02 pm
by krstcs
You will have to do it INSIDE TestSuiteRunner. When TestSuiteRunner is started, it will overwrite anything you assigned outside of it.

This means you will need to create a module that does what you want and then drop it into the SETUP section of the test suite.

You could then drop it anywhere else you need it, and even data-drive it so you can change the report level using data.

Re: Report Level - can I over ride in code?

Posted: Tue Apr 05, 2016 6:03 pm
by stapes
I have done some experiments, and it is a lot more complicated than that.

It reverts to the Test Suite default at the beginning of each Test Case.

Re: Report Level - can I over ride in code?

Posted: Tue Apr 05, 2016 8:03 pm
by krstcs
Ah, I didn't know that either. Ouch.

I guess you could still do it this way, and just drop the module in the SETUP section for each test case? But that creates more stuff to manage... :S

Re: Report Level - can I over ride in code?

Posted: Wed Apr 06, 2016 1:23 pm
by RobinHood42
Hi guys,

I guess this is possible with the following lines of code:
var ts = TestSuite.Current;
			var tc1 = (TestCase) ts.GetTestCase("TestCase");
			tc1.ReportLevel = ReportLevel.Failure;
So you can set the report level even of multiple test cases in advance.

Hope this helps.

Cheers,
Robin

Re: Report Level - can I over ride in code?

Posted: Wed May 04, 2016 2:37 pm
by stapes
This works:

Code: Select all

	    /// <summary>
	    /// sets the Current Report Level to the Global value from Run Parameter
	    /// </summary>
	    public static void SetReportLevel()
	    {
	    	// get
        	string before=Report.CurrentReportLevel.ToString();
        	Report.Info ("Get Level = " + before);
        	// set
        	Report.CurrentReportLevel=GlobalLevel ;
            Report.Info ("Set Level = " + Report.CurrentReportLevel.ToString ());
	    }