private static string StepToBugMarkdown(RhinoTestStep testStep) { // setup action var action = "*" + testStep.Action.Replace("{", "\\\\{") + "*\\r\\n"; // setup var expectedResults = Regex .Split(testStep.Expected, "(\r\n|\r|\n)") .Where(i => !string.IsNullOrEmpty(i) && !Regex.IsMatch(i, "(\r\n|\r|\n)")) .ToArray(); var failedOn = testStep.Context.ContainsKey(ContextEntry.FailedOn) ? (IEnumerable <int>)testStep.Context[ContextEntry.FailedOn] : Array.Empty <int>(); // exit conditions if (!failedOn.Any()) { return(action); } // build var markdown = new List <string>(); for (int i = 0; i < expectedResults.Length; i++) { var outcome = failedOn.Contains(i) ? "{panel:bgColor=#ffebe6}" : "{panel:bgColor=#e3fcef}"; markdown.Add(outcome + expectedResults[i].Replace("{", "\\\\{") + "{panel}"); } // results return(action + string.Join("\\r\\n", markdown)); }
private static RhinoTestStep GetTestStep(JToken testStep) { // constants const string Pattern = @"{{(?!\$).*?}}"; // 1st cycle var rhinoStep = new RhinoTestStep { Action = $"{testStep["fields"]["Action"]}".Replace(@"\{", "{").Replace(@"\[", "[").Replace("{{{{", "{{").Replace("}}}}", "}}"), Expected = $"{testStep["fields"]["Expected Result"]}".Replace(@"\{", "{").Replace(@"\[", "[").Replace("{{{{", "{{").Replace("}}}}", "}}") }; // 2nd cycle: action var matches = Regex.Matches(rhinoStep.Action, Pattern); foreach (Match match in matches) { rhinoStep.Action = ReplaceByMatch(rhinoStep.Action, match); } // 3rd cycle: action matches = Regex.Matches(rhinoStep.Expected, Pattern); foreach (Match match in matches) { rhinoStep.Expected = ReplaceByMatch(rhinoStep.Expected, match); } // get return(rhinoStep); }
/// <summary> /// Converts test management test case interface into a RhinoTestCase. /// </summary> /// <param name="testCase">Test case token (from Jira response) to convert.</param> /// <returns>RhinoTestCase object.</returns> public static RhinoTestCase ToRhinoTestCase(this JToken testCase) { // initialize test case instance & fetch issues var onTestCase = new RhinoTestCase(); // apply context onTestCase.Context ??= new Dictionary <string, object>(); onTestCase.Context[nameof(testCase)] = testCase; // fields: setup var priority = GetPriority(testCase); // fields: values onTestCase.Priority = string.IsNullOrEmpty(priority) ? onTestCase.Priority : priority; onTestCase.Key = $"{testCase["key"]}"; onTestCase.Scenario = $"{testCase.SelectToken("fields.summary")}"; onTestCase.Link = $"{testCase["self"]}"; // initialize test steps collection var testSteps = testCase.SelectToken("..steps"); var parsedSteps = new List <RhinoTestStep>(); // iterate test steps & normalize action/expected foreach (var testStep in testSteps.Children()) { var step = new RhinoTestStep { Action = $"{testStep["action"]}".Replace("{{", "{").Replace("}}", "}").Replace(@"\{", "{").Replace(@"\[", "["), Expected = $"{testStep["result"]}".Replace("{{", "{").Replace("}}", "}").Replace(@"\{", "{").Replace(@"\[", "[") }; // normalize auto links (if any) step.Action = NormalizeAutoLink(step.Action); step.Expected = NormalizeAutoLink(step.Expected); // normalize line breaks from XRay var onExpected = step.Expected.SplitByLines(); step.Expected = string.Join(Environment.NewLine, onExpected); // apply step.Context[nameof(testStep)] = testStep; parsedSteps.Add(step); } // apply to connector test steps onTestCase.Steps = parsedSteps; return(onTestCase); }
/// <summary> /// Gets an update request for XRay test case result, under a test execution entity. /// </summary> /// <param name="testStep">RhinoTestStep by which to create request.</param> /// <param name="outcome">Set the step outcome. If not provided, defaults will be assigned.</param> public static object GetUpdateRequest(this RhinoTestStep testStep, string outcome) { // setup var inconclusiveStatus = testStep.GetCapability(AtlassianCapabilities.InconclusiveStatus, "ABORTED"); // set outcome var onOutcome = testStep.Actual ? "PASS" : "FAIL"; if (!string.IsNullOrEmpty(outcome) && outcome != "PASS" && outcome != "FAIL" && outcome != inconclusiveStatus) { onOutcome = outcome; } // set request object return(new { Id = $"{testStep.Context["runtimeid"]}", Status = onOutcome, Comment = testStep.Exception == null ? null : $"{{noformat}}{testStep?.Exception}{{noformat}}", ActualResult = $"{{noformat}}{testStep.ReasonPhrase}{{noformat}}" }); }
/// <summary> /// Converts a RhinoTestStep into XRay compatible markdown which can be placed in any /// description type field. /// </summary> /// <param name="testStep">RhinoTestStep to convert.</param> /// <returns>XRay compatible markdown representation of this RhinoTestStep.</returns> public static string BugMarkdown(this RhinoTestStep testStep) { return(StepToBugMarkdown(testStep)); }
private static bool IsWebAppAction(RhinoTestStep testStep) { return(Regex.IsMatch(input: testStep.Action, pattern: "(?i)(go to url|navigate to|open|go to)")); }