private void countCompareDataResults(CommandResult result) { if (result.CompareDataResults.Count == 0) return; else { foreach (var cellResult in result.CompareDataResults) { if (cellResult == "True") totalRight++; else totalWrong++; } } }
public void CreateEntry(CommandResult result, string outputFileName) { if (outputFileName.Contains("TestSummary")) { summaryFile = true; hrefLocation = outputFileName.Remove(outputFileName.IndexOf("TestSummary")); } if (result.Command == null && !inCompareData) { //Filter out !| declares. if (result.FullCommand != null && result.FullCommand.StartsWith("!|")) return; CreateCommentEntry(result); return; } CreateCommandEntry(result); }
public HtmlOutput CreateCommandEntry(CommandResult result, int currentShift) { //Redirect children calls that are actually comments. if (result.Command == null && !inCompareData) { CreateCommentEntry(result, currentShift); return this; } //Filter out !| declares from possible children calls. if (result.FullCommand != null && result.FullCommand.StartsWith("!|")) return this; if (currentShift == 0 && tableBreak) { SetUpTable(); tableBreak = false; } if (result.Command == "BeginCompareData") { inCompareData = true; } else if (result.Command == "EndCompareData") { inCompareData = false; FinalizeCompareDataTable(); } else if (inCompareData) { //create the column titles for the database table if (result.CompareDataResults.Count == 0) CreateCompareDataColumnEntry(result, currentShift); //handle the row results for Compare Data else CreateCompareDataResultEntry(result, currentShift); return this; } if (currentShift > 0) { tableBreak = true; BreakTable(currentShift); } htmlGenerator.GenerateTableRowHeader(); for (int i = 0; i < currentShift; i++) htmlGenerator.GenerateTableColumnWithWidth(string.Empty, "5%"); string data = ""; if (summaryFile) { data = "<a href=\"file:///" + hrefLocation + result.FullCommand + ".html\">" + result.FullCommand + "</a>"; } else { data = result.FullCommand; } htmlGenerator .GenerateTableColumnWithTextColorWithBGColor("" + result.LineNumber, Colors.GeneralTextColor, Colors.TableBgColor) .GenerateTableColumnWithTextColorWithBGColor(data, Colors.GeneralTextColor, Colors.TableBgColor) .GenerateTableColumnHeaderWithWidthWithBgColor("20%", Colors.TableBgColor) .GenerateTableHeaderWithWidth("100%"); result.Parameters.ForEach(param => BuildParameter(param)); htmlGenerator.GenerateTableColumnFooter() .GenerateTableFooter(); BuildCommandResult(result); htmlGenerator.GenerateTableRowFooter(); //Unbreak table if (currentShift > 0) htmlGenerator.GenerateTableFooter(); //Create command results for child commands. result.Children.ForEach(child => CreateCommandEntry(child, currentShift + 1)); return this; }
public HtmlOutput CreateCommandEntry(CommandResult result) { return CreateCommandEntry(result, 0); }
public HtmlOutput CreateCommentEntry(CommandResult result, int currentShift) { //Filter out !| declares from possible children calls. if (result.FullCommand != null && result.FullCommand.StartsWith("!|")) return this; if (result.FullCommand != string.Empty) { htmlGenerator.GenerateTableFooter(); if (currentShift == 0) htmlGenerator.GenerateBreakline(); htmlGenerator.GenerateTableHeaderWithWidth("80%"); if (currentShift > 0) { for (int i = 0; i < currentShift; i++) htmlGenerator.GenerateTableColumnWithWidth(string.Empty, "5%"); } htmlGenerator .GenerateTableColumn(result.FullCommand) .GenerateTableFooter(); SetUpTable(); } return this; }
private void BuildCommandResult(CommandResult result) { if (!result.FullCommand.Contains("?")) { if (result.Success) { htmlGenerator.GenerateTableColumnWithTextColorWithBGColor("Success", Colors.ResultTextColor, Colors.SuccessBgColor) .GenerateTableColumnWithTextColorWithBGColor(string.Empty, Colors.GeneralTextColor, Colors.TableBgColor) .GenerateTableColumnWithTextColorWithBGColor( (result.Message == null || result.Message.Equals("Success") || result.FullCommand.Contains("<>")) ? string.Empty : result.Message, Colors.GeneralTextColor, Colors.TableBgColor); } else if (result.Ignored || result.Cond) { htmlGenerator.GenerateTableColumnWithTextColorWithBGColor("Ignored", Colors.ResultTextColor, Colors.IgnoredBgColor) .GenerateTableColumnWithTextColorWithBGColor(string.Empty, Colors.GeneralTextColor, Colors.TableBgColor) .GenerateTableColumnWithTextColorWithBGColor(string.Empty, Colors.GeneralTextColor, Colors.TableBgColor); } else if (!result.Success) { htmlGenerator.GenerateTableColumnWithTextColorWithBGColor("Failure", Colors.ResultTextColor, Colors.FailureBgColor) .GenerateTableColumnWithTextColorWithBGColor(string.Empty, Colors.GeneralTextColor, Colors.TableBgColor) .GenerateTableColumnWithTextColorWithBGColor(result.Message, Colors.GeneralTextColor, Colors.TableBgColor); } } else { htmlGenerator.GenerateTableColumnWithTextColorWithBGColor("", Colors.ResultTextColor, Colors.TableBgColor) .GenerateTableColumnWithTextColorWithBGColor(string.Empty, Colors.GeneralTextColor, Colors.TableBgColor) .GenerateTableColumnWithTextColorWithBGColor( (result.Message == null || result.Message.Equals("Success") || (result.FullCommand.Contains("<>") && !result.Message.Equals("Success"))) ? string.Empty : result.Message, Colors.GeneralTextColor, Colors.TableBgColor); } }
private void BuildParameter(CommandResult.ParameterEntry param) { string output = param.ReplacedParam; htmlGenerator.GenerateTableColumnHeaderWithWidthWithBgColor("0%", Colors.TableBgColor) .GenerateDivWithStyle(output) .GenerateTableColumnFooter(); }
public HtmlOutput CreateCompareDataResultEntry(CommandResult result, int currentShift) { string resultColor; string textForCell; //create a new row htmlGenerator.GenerateTableRowHeader(); //shift over if needed for (int i = 0; i < currentShift; i++) htmlGenerator.GenerateTableColumnWithWidth(string.Empty, "5%"); //enter the results in the row cells for (int colIndex = 0; colIndex < result.Parameters.Count; colIndex++) { if (result.CompareDataResults[colIndex] == "True") { resultColor = Colors.SuccessBgColor; textForCell = result.Parameters[colIndex].ReplacedParam; } else { resultColor = Colors.FailureBgColor; textForCell = result.Message; } htmlGenerator.GenerateTableColumnHeaderWithWidthWithBgColorWithAlignWithFontColor("0%", resultColor, "center", Colors.ResultTextColor) .GenerateDivWithStyle(textForCell) .GenerateTableColumnFooter(); } //end the row htmlGenerator.GenerateTableRowFooter(); return this; }
public HtmlOutput CreateCompareDataColumnEntry(CommandResult result, int currentShift) { //end the current table htmlGenerator.GenerateTableFooter(); //start a new table for the database table htmlGenerator.GenerateTableHeaderWithWidth("80%"); //shift the table over if needed for (int i = 0; i < currentShift; i++) htmlGenerator.GenerateTableColumnWithWidth(string.Empty, "5%"); //create the column titles for (int colIndex = 0; colIndex < result.Parameters.Count; colIndex++) { htmlGenerator.GenerateTableColumnHeaderWithWidthWithBgColorWithAlignWithFontColor("0%", Colors.CompareDataColumn, "center", Colors.GeneralTextColor) .GenerateDivWithStyle(result.Parameters[colIndex].ReplacedParam) .GenerateTableColumnFooter(); } return this; }
private void updateTestResult(CommandResult displayName) { displayName.Success = ddEditor1.TestPassed; displayName.Message = displayName.Success ? "Passed" : "Failed on line " + ddEditor1.FailureReason; this.Invoke(new MethodInvoker(delegate() { commandEditor1.ResultDisplayer.UpdateResult(displayName); })); }
private void displayNextTest(CommandResult displayName) { displayName.Command = ddEditor1.TestFront + ddEditor1.TestName; displayName.Message = "Running..."; displayName.LineNumber = ++ddEditor1.TestNum; this.Invoke(new MethodInvoker(delegate() { commandEditor1.ResultDisplayer.LogResult(displayName); })); }
private void bw_DoWork(object sender, DoWorkEventArgs e) { CommandResult displayName = new CommandResult(); bool testStarted = false; BrowserType browser = new BrowserType(); this.Invoke(new MethodInvoker(delegate() { try { browser = this.getBrowserType(); } catch (NullReferenceException ex) { return; } })); while (doDDETestsRemain() && !bw.CancellationPending) { if (!testStarted) { ddEditor1.ResetDataForNextTest(); displayNextTest(displayName); testStarted = beginNextTest(); } else if (didTestFinish()) { updateTestResult(displayName); createHtmlOutput(browser); ddEditor1.incrementPassFailCounter(); ddEditor1.concludeTest(displayName); (sender as BackgroundWorker).ReportProgress(0); testStarted = false; Thread.Sleep(500); } else //Test Running Thread.Sleep(20); } ddEditor1.createSummaryFile(browser); if (bw.CancellationPending) { displayName.Ignored = true; displayName.ModIgn = true; displayName.Message = "Stopped"; this.Invoke(new MethodInvoker(delegate() { commandEditor1.ResultDisplayer.UpdateResult(displayName); })); } }
public CommandResult(CommandResult result) { Cond = result.Cond; Command = result.Command; Children = result.Children; FileName = result.FileName; FullCommand = result.FullCommand; Ignored = result.Ignored; LineNumber = result.LineNumber; Message = result.Message; ModIgn = result.ModIgn; Parameters = result.Parameters; CompareDataResults = result.CompareDataResults; Success = result.Success; }
public void ProcessWikiCommands(string[] wikiCommands, List<BreakPoint> breakPoints, System.Threading.Thread activeThread, CommandEditorPage currentPage, bool commandLineMode, List<CommandResult> listOfResults, string fileName) { bool inComment = false; string cleanedCommand = ""; foreach (string wikiCommand in wikiCommands) { lineNumber++; Command mngrCommand = new Command(wikiCommand.TrimStart('|')); cleanedCommand = cleanCommand(wikiCommand); if (breakPoints.Count > 0) CheckForBreakPointOnLine(breakPoints, lineNumber, activeThread, currentPage); CommandResult returnResult = new CommandResult(); returnResult.FileName = fileName; returnResult.LineNumber = lineNumber; returnResult.FullCommand = mngrCommand.FullCommand; listOfResults.Add(returnResult); if (cleanedCommand.Equals(String.Empty)) { if (_finishBlockOnFailure) { TestManager.FinishBlockOnFailure = true; _finishBlockOnFailure = false; } TestManager.ResetForNewTable(); } if (!cleanedCommand.StartsWith("#") && !inComment && !cleanedCommand.StartsWith("{{{") && !cleanedCommand.StartsWith("}}}") && !isIgnoredCommand(cleanedCommand) && !TestManager.InCompareData) { if (cleanedCommand.StartsWith("!")) { if (cleanedCommand.StartsWith("!define")) { try { cleanedCommand = replaceVar(cleanedCommand); } catch (SWATVariableDoesNotExistException e) { returnResult.Success = false; mngrCommand.Passed = false; returnResult.Message = e.Message; returnResult.Command = "Could not be defined"; TestManager.LogCommand(mngrCommand); goto Exit; } WikiVariable var = new WikiVariable(cleanedCommand); if (!_variables.ContainsKey(var.Name)) _variables.Add(var.Name, var.Value); else _variables[var.Name] = var.Value; returnResult.Success = true; returnResult.Command = string.Format("Defined {0} as {1}", var.Name, var.Value); } if (cleanedCommand.StartsWith("!include")) { WikiInclude include = new WikiInclude(cleanedCommand); try { string newFileName = SWAT.FitnesseSettings.FitnesseRootDirectory.TrimEnd('\\') + "\\" + include.FilePath + "content.txt"; string[] lines = File.ReadAllLines(newFileName); //Need an intermediate slot in the results. returnResult.Command = "INCLUDE"; returnResult.FullCommand = cleanedCommand; returnResult.Success = true; returnResult.Ignored = false; ProcessWikiCommands(lines, breakPoints, activeThread, currentPage, commandLineMode, returnResult.Children, newFileName); } catch (DirectoryNotFoundException) { returnResult.Success = false; returnResult.Ignored = false; returnResult.Message = string.Format("Could not load macro at {0}", SWAT.FitnesseSettings.FitnesseRootDirectory.TrimEnd('\\') + "\\" + include.FilePath); returnResult.Command = "INCLUDE"; } } } else { //string[] sections = cleanedCommand.TrimStart('|').TrimEnd('|').Split('|'); // Remove leading pipes cleanedCommand = cleanedCommand.TrimStart('|'); // Remove last pipe. Can't use TrimEnd('|') in case we are passing empty parameters string[] sections = parseSections(cleanedCommand.Substring(0, cleanedCommand.LastIndexOf('|'))); StringCollection parameters = new StringCollection(); if (sections.Length < 1) { returnResult.Success = false; returnResult.Message = "Command is not formated correctly."; returnResult.Command = cleanedCommand; goto Exit; } string command = sections[0]; returnResult.Command = command; for (int i = 1; i < sections.Length; i++) { string replace = ""; try { replace = replaceVar(sections[i]); } catch (SWATVariableDoesNotExistException e) { parameters.Add(sections[i]); var paramEntryex = new CommandResult.ParameterEntry { OriginalParam = sections[i], ReplacedParam = sections[i] }; returnResult.Parameters.Add(paramEntryex); returnResult.Success = false; mngrCommand.Passed = false; returnResult.Message = e.Message; TestManager.LogCommand(mngrCommand); goto Exit; } parameters.Add(replace); var paramEntry = new CommandResult.ParameterEntry { OriginalParam = sections[i], ReplacedParam = replace }; returnResult.Parameters.Add(paramEntry); } if (TestManager.ShouldExecute(mngrCommand)) { try { string varKey = ""; if (command == "GetElementAttribute") { varKey = parameters[3]; parameters.RemoveAt(3); } if (command == "GetConfigurationItem") { varKey = parameters[1]; parameters.RemoveAt(1); } if (command.Contains("GetDbRecord") || command.Contains("GetDbDate") || command.Contains("GetLocation") || command.Contains("GetWindowTitle") || command.Contains("RunScriptSaveResult") || command.Contains("SetVariable") || command.StartsWith("GetSavedDbDate") || command == "GetTimerValue") { varKey = parameters[0]; parameters.RemoveAt(0); } if(command == "BeginCompareData") { TestManager.InCompareData = true; _inCompareDataIndex = 0; TestManager.InCompareDataIsCritical = false; } InvokeResult result = _invokeManager.Invoke(command, parameters); if (mngrCommand.IsInverse) { returnResult.Success = !result.Success; mngrCommand.Passed = !result.Success; } else { returnResult.Success = result.Success; mngrCommand.Passed = result.Success; } if (!mngrCommand.Passed && mngrCommand.FinishBlockOnFailure) { _finishBlockOnFailure = true; } returnResult.Cond = wikiCommand.StartsWith("|?"); //Notify the user on success. if (result.Success) { //If original command failed, now passes with inverse modifier if (mngrCommand.IsInverse) returnResult.Message = "Inverse modifier failed passing command"; else returnResult.Message = "Success"; //C# Operator == is overloaded, so Equals() method is called when used. That is why it can be used to compare Strings. if ((command == "GetElementAttribute" || command.Contains("GetDbRecord") || command == "GetDbDate" || command == "GetLocation" || command == "GetConfigurationItem") || command == "GetWindowTitle" || command == "RunScriptSaveResult" || command == "SetVariable" || command.StartsWith("GetSavedDbDate") || command == "GetTimerValue") { if (_variables.ContainsKey(varKey.ToString())) { _variables.Remove(varKey); } _variables.Add(varKey, result.ReturnValue); } if (command == "DisplayVariable" || command == "DisplayTimerValue") { returnResult.Parameters[0].ReplacedParam = result.ReturnValue; } } if (!result.Success) { if (mngrCommand.IsInverse) returnResult.Message = "Success - Inverse modifier passed failing command. Original error message: " + result.FailureMessage; else returnResult.Message = result.FailureMessage; } } catch (Exception e) { returnResult.Success = false; returnResult.Message = e.Message; if (mngrCommand.Passed && mngrCommand.FinishBlockOnFailure) { _finishBlockOnFailure = true; } } } else { returnResult.Ignored = true; returnResult.ModIgn = true; } TestManager.LogCommand(mngrCommand); } } else if (TestManager.InCompareData) { cleanedCommand = cleanCommand(wikiCommand); cleanedCommand = cleanedCommand.TrimStart('|'); string[] sections = parseSections(cleanedCommand.Substring(0, cleanedCommand.LastIndexOf('|'))); // 1. if endCompareData if (wikiCommand.Contains("EndCompareData")) { returnResult.Command = "EndCompareData"; returnResult.Success = true; mngrCommand.Passed = true; returnResult.Message = "Success"; TestManager.LogCommand(mngrCommand); TestManager.InCompareData = false; } else { //StringCollection rowParameters = new StringCollection(); for (int i = 0; i < sections.Length; i++) { string replace = ""; replace = replaceVar(sections[i]); //rowParameters.Add(replace); var paramEntry = new CommandResult.ParameterEntry { OriginalParam = sections[i], ReplacedParam = replace }; returnResult.Parameters.Add(paramEntry); } // 2. if _inCompareDataIndex = 0 we are reading the columns if (_inCompareDataIndex == 0) { _compareDatafieldNames = new List<string>(); for (int colIndex = 0; colIndex < returnResult.Parameters.Count; colIndex++) { _compareDatafieldNames.Add(returnResult.Parameters[colIndex].ReplacedParam); } } // 3. otherwise we are now looking at actual row of data else { for (int colIndex = 0; colIndex < _compareDatafieldNames.Count; colIndex++) { StringCollection parameters = new StringCollection(); int dataRowIndex = _inCompareDataIndex - 1; parameters.Add(dataRowIndex.ToString()); parameters.Add(_compareDatafieldNames[colIndex]); parameters.Add(returnResult.Parameters[colIndex].ReplacedParam); InvokeResult result = _invokeManager.Invoke("AssertRecordValuesByColumnName", parameters); if (!result.Success) returnResult.Message = result.FailureMessage; returnResult.CompareDataResults.Add(result.Success.ToString()); } } _inCompareDataIndex++; } } else { returnResult.Ignored = true; returnResult.ModIgn = false; if (wikiCommand.StartsWith("{{{")) inComment = true; if (wikiCommand.EndsWith("}}}")) inComment = false; } Exit: if (!commandLineMode) CommandProcessed(returnResult); } }