/// <summary> /// Execute /// </summary> public void Execute() { object webTestObject = Activator.CreateInstance(_classType); TestcaseExecutionEventArgs args = new TestcaseExecutionEventArgs(_classType.FullName, _methodName, true); OnTestcaseExecuting(args); try { _classType.InvokeMember(_methodName, BindingFlags.InvokeMethod, null, webTestObject, new object[] { }); } catch (TargetInvocationException e) { //now what do I do? args.Passed = false; args.Exception = e.InnerException; } finally { OnTestcaseExecuted(args); //If the class implements IDisposable call the dispose method if (webTestObject is IDisposable) { ((IDisposable)webTestObject).Dispose(); } } }
private void OnTestcaseExecuting(TestcaseExecutionEventArgs e) { if (this.TestcaseExecuting != null) { this.TestcaseExecuting(this, e); } }
/// <summary> /// Called after a testcase is executed /// </summary> protected virtual void OnTestcaseExecuted(TestcaseExecutionEventArgs e) { if (TestcaseExecuted != null) { TestcaseExecuted(this, e); } }
void testcase_TestcaseExecuting(object sender, TestcaseExecutionEventArgs e) { OnTestcaseExecuting(e); BrowserCommand command = new BrowserCommand(BrowserCommand.FunctionNames.TestcaseExecuting); command.Description = "Testcase Starting (" + e.WebTestName + ")"; command.Handler.SetArguments(e.WebTestName); command.Handler.RequiresElementFound = false; CommandManager.ExecuteCommand(_threadId, command, 5); }
private void OnTestcaseExecuted(TestcaseExecutionEventArgs e) { if (e != null && e.Exception != null && e.Exception.GetType() == typeof(TimeoutException)) { throw e.Exception; } if (this.TestcaseExecuted != null) { this.TestcaseExecuted(this, e); } }
public void LogTestcaseExecuted(object sender, TestcaseExecutionEventArgs e) { if (!e.Passed) { _lightRunnerErrorLog.AppendLine("---- Testcase FAILED '" + e.WebTestName + "' ----"); _lightRunnerErrorLog.AppendLine(e.Exception.ToString()); } else { _lightRunnerErrorLog.AppendLine("---- Testcase PASSED '" + e.WebTestName + "' ----"); } }
void testcase_TestcaseExecuted(object sender, TestcaseExecutionEventArgs e) { OnTestcaseExecuted(e); string errorMessage = e.Passed ? null : FormatErrorMessage(e); BrowserCommand command = new BrowserCommand(BrowserCommand.FunctionNames.TestcaseExecuted); command.Description = "Testcase Finished (" + e.WebTestName + ")"; command.Handler.SetArguments(e.WebTestName, e.Passed, errorMessage); command.Handler.RequiresElementFound = false; CommandManager.ExecuteCommand(_threadId, command, 5); }
/// <summary> /// Create an error message for a failed test case /// </summary> /// <param name="e">Information about the failure including the exception and test case name</param> /// <returns>HTML for the error message</returns> private string FormatErrorMessage(TestcaseExecutionEventArgs e) { // Make sure we have the necessary information to create the error message if (e == null || e.Exception == null || e.Passed) { return(null); } string testName = HttpUtility.HtmlEncode(e.WebTestName); string message = HttpUtility.HtmlEncode(e.Exception.Message); // Generated HTML markup displaying the error message StringBuilder html = new StringBuilder(); // Add the header html.Append("<div style=\"font-family: 'Verdana'; font-size: 8.5pt; color: black; background-color: white; width: 100%;\">"); html.Append("<span><h1 style=\"font-size: 18pt; color: red; font-weight: normal;\">Error in Test"); if (!string.IsNullOrEmpty(testName)) { html.AppendFormat(" '{0}'", testName); } html.Append("<hr width=\"100%\" size=\"1\" color=\"silver\" /></h1>"); // Add the error message html.Append("<h2 style=\"font-size: 14pt; color: maroon; font-weight: normal;\"><i>"); html.Append(message); html.Append("</i></h2></span>"); // Add the exception details html.Append("<font face=\"Arial, Helvetica, Geneva, SunSans-Regular, sans-serif\">"); html.Append("<b style=\"margin-top: -5px;\">Exception Details: </b>"); html.AppendFormat("{0}: {1}", HttpUtility.HtmlEncode(e.Exception.GetType().FullName), message); html.Append("<br /><br />"); // Add the source code (if available) string fileName = null; int sourceLine = 0; string methodName = null; string sourceCode = GetSourceCode(e.Exception, out fileName, out sourceLine, out methodName); if (!string.IsNullOrEmpty(sourceCode)) { html.Append("<b style=\"margin-top: -5px;\">Source Error:</b> <br><br>"); html.Append("<table width=\"100%\" bgcolor=\"#ffffcc\"><tr><td>"); html.AppendLine("<code><pre style=\"font-family: 'Lucida Console'; font-size: 9pt;\">"); html.AppendLine(); html.Append(sourceCode); html.Append("</pre></code></td></tr></table><br />"); html.Append("<b style=\"margin-top: -5px;\">Source File: </b> "); html.Append(fileName); html.Append("<b style=\"margin-top: -5px;\"> Line: </b> "); html.Append(sourceLine); html.Append("<b style=\"margin-top: -5px;\"> Method: </b> "); html.Append(methodName); html.Append("<br /><br />"); } // Add the stack trace html.Append("<b style=\"margin-top: -5px;\">Stack Trace:</b> <br><br>"); html.Append("<table width=\"100%\" bgcolor=\"#ffffcc\"><tr><td>"); html.AppendLine("<code><pre style=\"font-family: 'Lucida Console'; font-size: 9pt;\">"); for (Exception ex = e.Exception; ex != null; ex = ex.InnerException) { html.AppendLine(); html.AppendFormat("[{0}: {1}]", HttpUtility.HtmlEncode(ex.GetType().FullName), HttpUtility.HtmlEncode(ex.Message)); html.AppendLine(); html.AppendLine(HttpUtility.HtmlEncode(ex.StackTrace)); } html.Append("</pre></code></td></tr></table><br />"); // Add the version information for all the necessary products html.Append("<hr width=\"100%\" size=\"1\" color=\"silver\" />"); html.Append("<b style=\"margin-top: -5px;\">Version Information:</b> "); try { html.AppendFormat("Microsoft .NET Framework Version: {0}; ", GetVersionInfo(typeof(object))); html.AppendFormat("ASP.NET Version: {0}; ", GetVersionInfo(typeof(Control))); if (TestDriverPage.SystemWebExtensionsAbstractions.SystemWebExtensionsAssembly != null) { Type extenderControl = TestDriverPage.SystemWebExtensionsAbstractions.SystemWebExtensionsAssembly.GetType("System.Web.UI.ExtenderControl"); if (extenderControl != null) { html.AppendFormat("ASP.NET AJAX Version: {0}; ", GetVersionInfo(extenderControl)); } } html.AppendFormat("LTAF Version: {0}", GetVersionInfo(typeof(WebTestMethodAttribute))); } catch (System.Security.SecurityException) { // If running under medium trust, LTAF won't have FileIO permissions to get the versioninfo. } // Add the footer html.Append("</font></div>"); return(html.ToString()); }