Continuation of the topic about reports
Posted: Tue Jan 31, 2012 6:22 pm
I'm going to start a new thread since I'm not really sure if the way I described the problem initially is correct.
So I'll start from the beginning and try to give all the code and screenshots. So the post is gonna be long, I'm sorry.
Here's the function I'm calling:
Then I edit my test code to fail (return 0) and call this function again (without unloading my test script exe). Here's when things become interesting, the ActivityStack looks correct: However, when I press F5 to continue, here's what is shown in the report: Now if I uncomment the ActivityStack.Clear(); line at the end of the function, call it once (see the correct report), then call it again and see the following:
I was fighting with this thing for several days now, and it's probably something insanely simple. Can anyone stick my face into what I'm doing wrong?
So I'll start from the beginning and try to give all the code and screenshots. So the post is gonna be long, I'm sorry.
Here's the function I'm calling:
public void RunTests(string[] tsts) { //report folder will be prepared regardless of if it's UI mode or not. //the report will be shown at the end of a run of any set of tests. string reportPath = Path.Combine(Application.StartupPath, "Reports"); string date = System.DateTime.Now.Month + "-" + System.DateTime.Now.Day + "-" + System.DateTime.Now.Year +"-" + System.DateTime.Now.Hour + "-" + System.DateTime.Now.Minute + "-" + System.DateTime.Now.Second; CurrentReportFolder = Directory.CreateDirectory(Path.Combine(reportPath, date)); File.Copy(Path.Combine(Application.StartupPath, "RanorexReport3.png"), Path.Combine(CurrentReportFolder.FullName, "RanorexReport3.png"), true); File.Copy(Path.Combine(Application.StartupPath, "AVLLogo.png"), Path.Combine(CurrentReportFolder.FullName, "AVLLogo.png"), true); File.Copy(Path.Combine(Application.StartupPath, "AVLReportTemplate.xsl"), Path.Combine(CurrentReportFolder.FullName, "AVLReportTemplate.xsl"), true); string reportFilePath = Path.Combine(CurrentReportFolder.FullName, "AutomatedTestsReport.xml"); // Report.Setup(ReportLevel.Info, Path.Combine(CurrentReportFolder.FullName, "AutomatedTestsReport.xml"), true); TestReport.Setup(ReportLevel.Info, Path.Combine(CurrentReportFolder.FullName, "AutomatedTestsReport.xml"), true); TestReport.StyleSheetFilename = Path.Combine(CurrentReportFolder.FullName, "AVLReportTemplate.xsl"); TestReport.ReportWriteInterval = 0; TestReport.BeginTestSuite("Automated Tests"); foreach (string item in tsts) { foreach (AutomatedTest tst in LoadedTests) { string itemWithoutTestcases = item.Remove(item.IndexOf(" (")); if (itemWithoutTestcases == tst.Name) { // Assembly assemblyToRun; //assemblyToRun = GetAssemblyByID(tst[0].ToString()); if (tst.CompiledAssembly == null) return; Type[] types = tst.CompiledAssembly.GetTypes(); foreach (Type t in types) { foreach (object attribute in t.GetCustomAttributes(true)) { Type a = attribute.GetType(); if (a.Name == "ClassInfoAttribute") { object instance = Activator.CreateInstance(t); MethodInfo meth = t.GetMethod("StartTest"); if (meth != null) { string codeFileInRuntime = Path.Combine(Application.StartupPath, Path.GetFileName(tst.Path)); if (File.Exists(codeFileInRuntime)) File.SetAttributes(Path.Combine(Application.StartupPath, Path.GetFileName(tst.Path)), FileAttributes.Normal); if (tst.Path != Path.Combine(Application.StartupPath, Path.GetFileName(tst.Path))) //will crash if it's the same file File.Copy(tst.Path, Path.Combine(Application.StartupPath, Path.GetFileName(tst.Path)), true); TestReport.BeginTestCase(item); try { object retVal = meth.Invoke(instance, null); if ((int)retVal == 1) TestPassedActions(tst); else TestFailedActions(tst); } catch (Exception e) { if (e.InnerException != null) { WriteLog(e.InnerException.Message); //if in the test case file, the user started a test module, but it didn't finish due to an exception within the test //we'll finish it here to preserve the report integrity if (TestReport.CurrentTestModuleActivity != null) { Report.Failure(e.InnerException.Message); TestReport.EndTestModule(); } TestFailedActions(tst); } } TestReport.EndTestCase(); } else { WriteLog("Couldn't locate entry point in the loaded test."); if (this.UImode) MessageBox.Show("Couldn't locate entry point in the loaded test.\r\n Make sure your test contains a StartTest method returning 1 for success and 0 for failure."); } } } } } } } TestReport.SaveReport(); Process htmlInDefaultBrowser = new Process(); htmlInDefaultBrowser.StartInfo.UseShellExecute = true; htmlInDefaultBrowser.StartInfo.FileName = Path.Combine(CurrentReportFolder.FullName, "AutomatedTestsReport.xml"); htmlInDefaultBrowser.Start(); SetTestsRunning(false); //ActivityStack.Clear(); }I edit the test code that I load to succeed (return 1) and call this function. At this point I'm seeing the correct report at the end.
Then I edit my test code to fail (return 0) and call this function again (without unloading my test script exe). Here's when things become interesting, the ActivityStack looks correct: However, when I press F5 to continue, here's what is shown in the report: Now if I uncomment the ActivityStack.Clear(); line at the end of the function, call it once (see the correct report), then call it again and see the following:
I was fighting with this thing for several days now, and it's probably something insanely simple. Can anyone stick my face into what I'm doing wrong?