Report Level - can I over ride in code?

Ask general questions here.
stapes
Posts: 206
Joined: Wed Sep 16, 2015 10:55 am

Report Level - can I over ride in code?

Post by stapes » Tue Apr 05, 2016 3:11 pm

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?

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

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

Post by krstcs » Tue Apr 05, 2016 4:02 pm

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.
Shortcuts usually aren't...

stapes
Posts: 206
Joined: Wed Sep 16, 2015 10:55 am

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

Post by stapes » Tue Apr 05, 2016 6:03 pm

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.

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

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

Post by krstcs » Tue Apr 05, 2016 8:03 pm

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
Shortcuts usually aren't...

User avatar
RobinHood42
Posts: 324
Joined: Fri Jan 09, 2015 3:24 pm

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

Post by RobinHood42 » Wed Apr 06, 2016 1:23 pm

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

stapes
Posts: 206
Joined: Wed Sep 16, 2015 10:55 am

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

Post by stapes » Wed May 04, 2016 2:37 pm

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 ());
	    }