Finalize the report?

Ask general questions here.
taralex
Posts: 57
Joined: Tue Nov 04, 2008 3:50 pm
Location: Michigan
Contact:

Finalize the report?

Post by taralex » Fri Jan 27, 2012 10:16 pm

Another question about reports. I'm doing something like this:

Code: Select all

TestReport.Setup(ReportLevel.Info, "filename.xml", true);
TestReport.ReportWriteInterval = 0;
TestReport.BeginTestSuite("TestSuite");
TestReport.BeginTestCase("TestCase");
TestReport.BeginTestModule("TestModule");
if (//testmodule succeeded)
Report.Success("success");
else
Report.Failure("failed");
TestReport.EndTestModule();
if (//TestCase succeeded)
Report.Success("success")
else
Report.Failure("failed");
TestReport.EndTestTestCase();
TestReport.SaveReport();
sorry, couldn't find a way to indent the code.

This works pretty well the first time around. But if I run in again, it saves the report from the previous run, i.e. if the first time the test succeeded, I make it fail the second time, but the report still shows success. Then if I quit the exe and re-run the test, making it fail, it will show the correct report. But again, if I run the test again, this time successfully, the report will still show failure.

I was thinking that maybe there's something like EndTestSuite() command to reset the report, but there's none... What can I do here? TestReport object is static, so I can't get rid of it and create a new one...

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Finalize the report?

Post by Ciege » Fri Jan 27, 2012 10:30 pm

Are you looking for:

Code: Select all

Report.End();
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

taralex
Posts: 57
Joined: Tue Nov 04, 2008 3:50 pm
Location: Michigan
Contact:

Re: Finalize the report?

Post by taralex » Fri Jan 27, 2012 10:47 pm

indeed I was looking for something like that.

But I just tried it with the same result: only the first report is stored no matter how many times I re-run the function. To get the up-to-date report, I need to restart my exe...

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Finalize the report?

Post by Ciege » Fri Jan 27, 2012 10:59 pm

Are you overwriting your report each time? What I do is save my reports to a specified folder with a time/date stamp. Therefore there is no overwriting...
Here is a snippet from my ReportSetup method. This method is called from each of my scripts at runtime so a new folder and logfile is guaranteed to be created each time...

Code: Select all

// Get the current time & date to create a stamp for the report  
                strYear = System.DateTime.Now.Year.ToString();
                strMonth = System.DateTime.Now.ToString("MM");
                strDay = System.DateTime.Now.ToString("dd");
                strHour = System.DateTime.Now.ToString("hh");
                strMinute = System.DateTime.Now.ToString("mm");
                strSecond = System.DateTime.Now.ToString("ss");

                strDateTimeStamp = strYear + "_" + strMonth + "_" + strDay + "___" + strHour + "_" + strMinute + "_" + strSecond;
                strDateTimeStampClean = strYear + strMonth + strDay + strHour + strMinute + strSecond;

                //Check if passed in test name ends with ".XML"
                if (strTestName.EndsWith(".xml", true, null) == true)
                {
                    //Do nothing
                    LogFile = strTempReportDirectory + strDateTimeStamp + @"\" + strTestName;
                }
                else
                {
                    //Add ".XML" to the end of the test name
                    LogFile = strTempReportDirectory + strDateTimeStamp + @"\" + strTestName + ".xml";
                }

                //Check if report directory exists
                if (Directory.Exists(strTempReportDirectory + strDateTimeStamp) == false)
                {
                    //If not, create the report directory
                    Directory.CreateDirectory(strTempReportDirectory + strDateTimeStamp);
                }

                //Setup the report
                Report.Setup(ReportLevel.Debug, LogFile, true);
                Report.SystemSummary();

                if (boolUsePopUpStatusDialog == true)
                {
                    //Start a test report for on screen notifications
                    Ranorex.Core.Reporting.TestReport.Setup(ReportLevel.None, strTempReportDirectory + strDateTimeStamp + @"\" + "_DELETEME" + @"\_tempTestReport.rxlog", false);
                    Ranorex.Core.Reporting.TestReport.EnableTracingScreenshots = false;
                    Ranorex.Core.Reporting.TestReport.ReportWriteInterval = 0;
                    Ranorex.Controls.ProgressForm.Show();
                }
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

taralex
Posts: 57
Joined: Tue Nov 04, 2008 3:50 pm
Location: Michigan
Contact:

Re: Finalize the report?

Post by taralex » Fri Jan 27, 2012 11:07 pm

Now I tried to use Report.Setup(...) instead of TestReport.Setup(...)
so the code like:
Report.Setup(...);
Report.Start();
...
Report.End();

works just fine. However, I'm shown an old type report, without the fancy drop-down lines, and I want those...

taralex
Posts: 57
Joined: Tue Nov 04, 2008 3:50 pm
Location: Michigan
Contact:

Re: Finalize the report?

Post by taralex » Fri Jan 27, 2012 11:09 pm

and Ciege, I tried both overwriting the report and putting it to a new folder each time - the result is the same..

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Finalize the report?

Post by Ciege » Fri Jan 27, 2012 11:21 pm

Hmmm, I'm afraid I must be missing something because I don't understand how that could be. Don't you love technology!

When you say that "you quit the EXE" and re-run the test... What EXE are you speaking of? The log viewer, RanorexStudio, a compiled EXE of your test script?
Are you using the standard RXLOG or XML log files?
Do the time/date stamps on those files change when you re-run the test?
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

taralex
Posts: 57
Joined: Tue Nov 04, 2008 3:50 pm
Location: Michigan
Contact:

Re: Finalize the report?

Post by taralex » Mon Jan 30, 2012 10:23 pm

ok here's my code to illustrate what i'm trying to do:

Code: Select all

public void RunTests(bool success)
{

            string filePath =  Path.Combine(Application.StartupPath, "AutomatedTestsReport.xml");
            if (File.Exists(filePath))
                 File.Delete(filePath);
            TestReport.Setup(ReportLevel.Info, filePath, true);
            TestReport.StyleSheetFilename = Path.Combine(Application.StartupPath, "RanorexReport3.xsl");
            TestReport.ReportWriteInterval = 0;            
            TestReport.BeginTestSuite("Automated Tests");
            TestReport.BeginTestCase("Test case 1");
            TestReport.BeginTestModule("TestModule 1");
            if (!success)
                Report.Failure("Test failed");
            else 
               Report.Success("Test succeeded");
            TestReport.EndTestModule();
            TestReport.EndTestCase();
            TestReport.SaveReport();           
            Process htmlInDefaultBrowser = new Process();
            htmlInDefaultBrowser.StartInfo.UseShellExecute = true;
            htmlInDefaultBrowser.StartInfo.FileName = Path.Combine(CurrentReportFolder.FullName, "AutomatedTestsReport.xml");
            htmlInDefaultBrowser.Start();
}
If I do the following, I'm expecting to see one report with a successful test module entry and one report with a failed test module entry:

Code: Select all

RunTests(true);
Thread.Sleep(5000);
RunTests(false);
However, what I'm seeing is two successful reports. Am I doing somthing wrong or is it a Ranorex bug?

Correction: the above code opens two pages: one with one successful test case, and the other - with two test cases (one successful and one failed). It looks as if the data is just appended to the report.
What I'm trying to do here is to start a new report, I tried Report.End(), but it doesn't help.
Last edited by taralex on Mon Jan 30, 2012 10:51 pm, edited 1 time in total.

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Finalize the report?

Post by Ciege » Mon Jan 30, 2012 10:51 pm

After your final

Code: Select all

TestReport.SaveReport(); 
Can you add the following line and retry?

Code: Select all

ActivityStack.Clear()
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

taralex
Posts: 57
Joined: Tue Nov 04, 2008 3:50 pm
Location: Michigan
Contact:

Re: Finalize the report?

Post by taralex » Mon Jan 30, 2012 10:59 pm

Bingo!
Now it worked as I expected! I was suspecting that there should be a way to remove the TestSuiteActivity from the stack, but couldn't find an EndTestSuite() method.

Thank you very much!

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Finalize the report?

Post by Ciege » Mon Jan 30, 2012 11:09 pm

Great! Glad it worked... Just needed a brief look into your code was all...
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

taralex
Posts: 57
Joined: Tue Nov 04, 2008 3:50 pm
Location: Michigan
Contact:

Re: Finalize the report?

Post by taralex » Mon Jan 30, 2012 11:31 pm

Although... the simplified code that I showed above workes fine now, but I'm still having problems with my original code, which is a little bit more complicated.
Does it matter if I'm calling StartTestSuite() and StartTestCase() from one assembly, and then I call StartTestModule() and EndTestModule() from a different assembly, then return to the original assembly and call EndTestCase() and EndTestSuite()?

here's what I'm doing:
1. in my main exe I allow to load custom cs files with ranorex code. so I do StartTestSuite() and StartTestCase() in the main exe.
2. then I compile the provided cs file on the fly and let the user specify StartTestModule() and EndTestModule() inside their code.
3. After the user code is completed it either returns 1 or 0, or throws an exception. So if it's an exception, I do EndTestModule() in the main exe, and then do EndTestCase() and EndTestSuite() there as well. If it's 1 or 0 - I assume that the user called EndTestModule() before returning so I do EndTestCase() and EndTestSuite()...
4. at the end I show the report for the user code file.

I just wondered if I can I even do such calls from different assemblies at all...

taralex
Posts: 57
Joined: Tue Nov 04, 2008 3:50 pm
Location: Michigan
Contact:

Re: Finalize the report?

Post by taralex » Tue Jan 31, 2012 6:23 pm

I moved to a new topic, I'll try to give more details there: http://www.ranorex.com/forum/continuati ... t3038.html