public static bool UpdateTestcaseFields(IList <Tag> scenarioTags, ITestBase testCase, IEnumerable <TestCaseField> testCaseFields) { if (testCase == null || testCaseFields == null) { return(false); } var fieldMapper = UpdateMappedFields(scenarioTags, testCase, testCaseFields); if (fieldMapper.Count <= 0) { return(false); } var tags = GetUnmappedTags(scenarioTags, fieldMapper["matchedFields"]); if (tags.EndsWith(",", StringComparison.InvariantCulture)) { tags = tags.TrimEnd(','); } var tagsFieldValue = testCase.WorkItem.Fields[SyncUtil.TagsField].Value.ToString(); if (tags.Equals(tagsFieldValue, StringComparison.InvariantCulture)) { return(fieldMapper["modifiedFields"].Count > 0); } testCase.WorkItem.Fields[SyncUtil.TagsField].Value = tags; return(true); }
public void AddTest(ITestBase test) { if (!tests.Contains(test)) { tests.Add(test); } }
public TestEditInfo(ITestBase testCase, SimpleSteps simpleSteps, TestEditUserControl testEditControl) { WorkItemId = testCase.Id; TestCase = testCase; SimpleSteps = simpleSteps; TestEditControl = testEditControl; }
public BrowserWrapper(IWebDriver browser, ITestBase testClass, ScopeOptions scope) { this.browser = browser; this.testClass = testClass; ScopeOptions = scope; SetCssSelector(); }
private static void AddBackground(IHasSteps background, ITestBase testCase) { if (background == null) { return; } StepHelper.AddSteps(testCase, background.Steps, SyncUtil.BackgroundPrefix, false); }
/// <summary> /// Creates the new test step. /// </summary> /// <param name="testBase">The test case.</param> /// <param name="stepTitle">The step title.</param> /// <param name="expectedResult">The expected result.</param> /// <param name="testStepGuid">The unique identifier.</param> /// <returns>the test step object</returns> public static TestStep CreateNewTestStep(ITestBase testBase, string stepTitle, string expectedResult, Guid testStepGuid) { ITestStep testStepCore = testBase.CreateTestStep(); testStepCore.ExpectedResult = expectedResult; testStepCore.Title = stepTitle; if (testStepGuid == default(Guid)) { testStepGuid = Guid.NewGuid(); } TestStep testStepToInsert = new TestStep(false, string.Empty, testStepGuid, testStepCore); return testStepToInsert; }
public static void AddSteps(ITestBase testCase, IEnumerable <Step> steps, string prefix, bool isScenarioOutline) { if (steps == null || testCase == null) { return; } var isThen = false; foreach (var stepDef in steps) { var step = testCase.CreateTestStep(); var text = stepDef.Text; if (isScenarioOutline) { text = TransformParameters(text); } text = HttpUtility.HtmlEncode(text); var dataTable = CreateDataTable(stepDef.Argument, isScenarioOutline); /* * This was to handle the situation when, the "Then" step followed by "And" steps in which case, * they should also go to Expected Result column instead of a normal step. It should resume * populating normal steps as soon as it hits a WHEN, assuming that there won't be Givens * followed by Then */ if (stepDef.Keyword.Trim().Equals(WHEN, StringComparison.InvariantCultureIgnoreCase)) { isThen = false; } if (stepDef.Keyword.Trim().Equals(THEN, StringComparison.InvariantCultureIgnoreCase) || isThen) { isThen = true; step.ExpectedResult = text; step.ExpectedResult += dataTable; step.Title = stepDef.Keyword.Trim(); } else { step.Title = $"{prefix} {stepDef.Keyword} {text}"; step.Title += dataTable; } testCase.Actions.Add(step); } }
/// <summary> /// Searches for the RFID tag on the TestCase or SharedStep with the provided TFSID /// </summary> /// <returns>Nullable int representing RFID if any.</returns> public int?GetRFID(int tfsId) { // Get test case from id, it might be a set of shared steps ITestBase testCase = Session.workingProject.TestCases.Find(tfsId); testCase = testCase ?? this.Session.workingProject.SharedSteps.Find(tfsId); try { string rfIdTag = Parse.ExtractIdFromTags("RFID", testCase.WorkItem.Tags.Split(';')); if (rfIdTag == null) { return(null); } return(Int32.Parse(rfIdTag)); } catch (InvalidOperationException) { throw new Core.ServiceException(Core.Error.TFSTestTooManyTags); } }
/// <summary> /// Retrives all the relevant info required to copy a test from TFS to RF /// </summary> /// <param name="id">TFS tc id.</param> /// <param name="site">Required for pushing embedded steps to matching Site.</param> /// <returns></returns> public TestCaseCopyData GetCopyData(int id, Site site) { // Get test case from id, it might be a set of shared steps ITestBase testCase = Session.workingProject.TestCases.Find(id); if (testCase == null) { testCase = Session.workingProject.SharedSteps.Find(id); } if (testCase == null) { return(null); } // this test case dne anymore List <TestStepData> stepList = GetStepData(testCase.Actions, id, site); List <string> tagList = testCase.WorkItem.Tags.Split(';').ToList(); string redirectUrl = testCase.CustomFields["History"].OriginalValue.ToString(); return(new TestCaseCopyData(testCase.Title, testCase.CustomFields["Description"].Value.ToString(), tagList, stepList, redirectUrl)); }
public CinemasController(ITestBase testBase) { _testBase = testBase; }
void WriteTestCaseToExcel(ITestBase testCase, ExcelWorksheet worksheet, ITestManagementTeamProject _testProject) { worksheet.Cells[_i, 1].Style.Fill.PatternType = ExcelFillStyle.Solid; worksheet.Cells[_i, 1].Style.Fill.BackgroundColor.SetColor(Color.Yellow); worksheet.Cells[_i, 2].Style.Fill.PatternType = ExcelFillStyle.Solid; worksheet.Cells[_i, 2].Style.Fill.BackgroundColor.SetColor(Color.Yellow); worksheet.Cells[_i, 2].Style.Font.Bold = true; worksheet.Cells[_i, 3].Style.Fill.PatternType = ExcelFillStyle.Solid; worksheet.Cells[_i, 3].Style.Fill.BackgroundColor.SetColor(Color.Yellow); worksheet.Cells[_i, 3].Style.Font.Bold = true; worksheet.Cells[_i, 4].Style.Fill.PatternType = ExcelFillStyle.Solid; worksheet.Cells[_i, 4].Style.Fill.BackgroundColor.SetColor(Color.Yellow); worksheet.Cells[_i, 4].Style.Font.Bold = true; worksheet.Cells[_i, 5].Style.Fill.PatternType = ExcelFillStyle.Solid; worksheet.Cells[_i, 6].Style.Fill.PatternType = ExcelFillStyle.Solid; worksheet.Cells[_i, 6].Style.Fill.BackgroundColor.SetColor(Color.Yellow); worksheet.Cells[_i, 7].Style.Fill.PatternType = ExcelFillStyle.Solid; worksheet.Cells[_i, 7].Style.Fill.BackgroundColor.SetColor(Color.Yellow); worksheet.Cells[_i, 8].Style.Fill.PatternType = ExcelFillStyle.Solid; worksheet.Cells[_i, 8].Style.Fill.BackgroundColor.SetColor(Color.Yellow); worksheet.Cells[_i, 9].Style.Fill.PatternType = ExcelFillStyle.Solid; worksheet.Cells[_i, 9].Style.Fill.BackgroundColor.SetColor(Color.Yellow); worksheet.Cells[_i, 5].Style.Font.Bold = true; worksheet.Cells[_i, 9].Style.Font.Bold = true; //worksheet.Cells[_i, 5].Style.Font.Bold = true; worksheet.Cells[_i, 1].Value = testCase.Id.ToString(); var testResults = _testProject.TestResults.ByTestId(testCase.Id); WorkItemStore Store = _tfs.GetService <WorkItemStore>(); foreach (ITestCaseResult result in testResults) { worksheet.Cells[_i, 5].Value = result.Outcome; if (result.Outcome.ToString() == "Passed") { worksheet.Cells[_i, 5].Style.Fill.BackgroundColor.SetColor(Color.Green); } else if (result.Outcome.ToString() == "Failed") { worksheet.Cells[_i, 5].Style.Fill.BackgroundColor.SetColor(Color.Red); } else if (result.Outcome.ToString() == "NotApplicable") { worksheet.Cells[_i, 5].Style.Fill.BackgroundColor.SetColor(Color.Gray); } else if (result.Outcome.ToString() == "Blocked") { worksheet.Cells[_i, 5].Style.Fill.BackgroundColor.SetColor(Color.LightPink); } else { worksheet.Cells[_i, 5].Style.Fill.BackgroundColor.SetColor(Color.WhiteSmoke); worksheet.Cells[_i, 5].Value = "Design"; } } WorkItemCollection BugQueryResults = Store.Query( "SELECT [System.Id],[Microsoft.VSTS.Common.StackRank],[Microsoft.VSTS.Common.Priority], [System.WorkItemType],[System.Title] " + "From WorkItems " + "Where [System.TeamProject] = '" + _testProject.WitProject.Name + "'" + "AND ([System.WorkItemType] = 'Bug' OR [System.WorkItemType] = 'Requirement' ) AND [System.IterationPath] = '" + testCase.WorkItem.IterationPath + "' AND[System.State] <> 'Closed'"); /* * * foreach (FieldDefinition disp in BugQueryResults.DisplayFields) * { * * Console.WriteLine(disp.Name); * * } * */ WorkItem myitem = testCase.WorkItem; string _lastvalue = null; foreach (WorkItemLink wil in myitem.WorkItemLinks) { foreach (WorkItem disp in BugQueryResults) { if (disp.Type.Name == "Bug") { if (disp.Id == wil.TargetId) { _lastvalue += wil.TargetId.ToString() + "-" + disp.Fields["Assigned to"].Value + Environment.NewLine; } } else if (disp.Type.Name == "Requirement") { if (disp.Id == wil.TargetId) { worksheet.Cells[_i, 7].Value = disp.Fields["ID"].Value; worksheet.Cells[_i, 8].Value = disp.Fields["Title"].Value; } } } } worksheet.Cells[_i, 6].Value = _lastvalue; worksheet.Cells[_i, 9].Value = testCase.Priority; worksheet.Cells[_i, 2].Value = testCase.Title; worksheet.Cells[_i, 3].Value = "Steps:"; worksheet.Cells[_i, 4].Value = "Expected Results"; worksheet.Row(_i).OutlineLevel = 1; var j = 1; /* For download code * var wi = Store.GetWorkItem(testCase.Id); * string name =null; * Attachment attach = null; * attach = wi.Attachments.Cast<Attachment>().FirstOrDefault(x => x.Name == name); * */ foreach (ITestAction action in testCase.Actions) { var sharedRef = action as ISharedStepReference; string testAction; string expectedResult; if (sharedRef != null) { var sharedStep = sharedRef.FindSharedStep(); foreach (var testStep in sharedStep.Actions.Select(sharedAction => sharedAction as ITestStep)) { testAction = j.ToString() + ". " + ((testStep.Title.ToString().Length == 0) ? "<<Not Recorded>>" : testStep.Title.ToString()); expectedResult = ((testStep.ExpectedResult.ToString().Length == 0) ? "<<Not Recorded>>" : testStep.ExpectedResult.ToString()); WriteTestStepsToExcel(worksheet, _i, j, StripTagsCharArray(testAction), StripTagsCharArray(expectedResult)); j++; } } else { var testStep = action as ITestStep; testAction = j.ToString() + ". " + ((testStep.Title.ToString().Length == 0) ? "<<Not Recorded>>" : testStep.Title.ToString()); expectedResult = ((testStep.ExpectedResult.ToString().Length == 0) ? "<<Not Recorded>>" : testStep.ExpectedResult.ToString()); WriteTestStepsToExcel(worksheet, _i, j, StripTagsCharArray(testAction), StripTagsCharArray(expectedResult)); j++; } } //end of foreach test action _i = _i + j - 1; }
private static IDictionary <string, IList <TestCaseField> > UpdateMappedFields(IEnumerable <Tag> scenarioTags, ITestBase testCase, IEnumerable <TestCaseField> testCaseFields) { var matchedFields = new List <TestCaseField>(); var modifiedFields = new List <TestCaseField>(); foreach (var testCaseField in testCaseFields) { var tagValue = GetTagValue(scenarioTags, testCaseField.Tag, testCaseField.Prefix); if (!testCaseField.Required && tagValue.Trim().Length <= 0 && testCaseField.RequirementField != null && testCaseField.RequirementField.Trim().Length <= 0) { continue; } if (testCaseField.RequirementField != null && testCaseField.RequirementField.Trim().Length > 0) { tagValue = GetTagValue(scenarioTags, SyncUtil.REQUIREMENT_TAG_NAME, testCaseField.Prefix); var tagValues = tagValue.Split(',').Select(requirementId => FeatureHelper.GetWorkItemField(testCaseField.RequirementField, requirementId)); tagValue = tagValues.Aggregate((i, j) => $"{i},{j}"); } if (tagValue.Length > 0) { matchedFields.Add(testCaseField); } if (!testCaseField.AllowMultiple && tagValue.Contains(",")) { Logger.Error($"{testCaseField.Name} field cannot have multiple values: {tagValue}"); continue; } try { var fieldValue = testCase.WorkItem.Fields[testCaseField.Name].Value.ToString(); if (tagValue == fieldValue) { continue; } Logger.Info($"{testCaseField.Name}:{tagValue}"); testCase.WorkItem.Fields[testCaseField.Name].Value = tagValue; modifiedFields.Add(testCaseField); } catch (Exception exception) { Logger.Error(exception.Message); } } var fieldResultMapper = new Dictionary <string, IList <TestCaseField> > { { "matchedFields", matchedFields }, { "modifiedFields", modifiedFields } }; return(fieldResultMapper); }
static void Main(string[] args) { // provide collection url of tfs var collectionUri = "http://*****:*****@"C: \Users\pankagar\Downloads\Canvas.png", FileMode.Open, FileAccess.Read); var attachmentObject = _witClient.CreateAttachmentAsync(uploadStream, "Canvas.png", "Simple").Result; // create a patchdocument object JsonPatchDocument json = new JsonPatchDocument(); // create a new patch operation for title field JsonPatchOperation patchDocument1 = new JsonPatchOperation(); patchDocument1.Operation = Operation.Add; patchDocument1.Path = "/fields/System.Title"; patchDocument1.Value = "Testing Rest Api"; json.Add(patchDocument1); // create a new patch operation for priority field JsonPatchOperation patchDocument2 = new JsonPatchOperation(); patchDocument2.Operation = Operation.Add; patchDocument2.Path = "/fields/Microsoft.VSTS.Common.Priority"; patchDocument2.Value = "2"; json.Add(patchDocument2); // create testbasehelper object TestBaseHelper helper = new TestBaseHelper(); // create testbase object to utilize teststep helpers ITestBase tb = helper.Create(); // create 2 test steps ts1 and ts2 ITestStep ts1 = tb.CreateTestStep(); ITestStep ts2 = tb.CreateTestStep(); ts1.Title = "title -> title1"; ts2.Title = "title -> title2"; ts1.ExpectedResult = "expected1"; ts2.ExpectedResult = "expected2"; ts1.Description = "description1"; ts2.Description = "description2"; // adding attachment to step1 ts1.Attachments.Add(ts1.CreateAttachment(attachmentObject.Url, "CanvasImage")); // add your steps actions to testbase object tb.Actions.Add(ts1); tb.Actions.Add(ts2); // update json based on all actions (including teststeps and teststep attachemnts) json = tb.SaveActions(json); var xml = ""; /* getting xml for teststeps * xml = tb.GenerateXmlFromActions(); */ // create Test Case work item using all test steps: ts1 and ts2 var testCaseObject = _witClient.CreateWorkItemAsync(json, projectName, "Test Case").Result; int testCaseId = Convert.ToInt32(testCaseObject.Id); // get Test Case using all relations testCaseObject = _witClient.GetWorkItemAsync(testCaseId, null, null, WorkItemExpand.Relations).Result; // update Test Case if (testCaseObject.Fields.ContainsKey("Microsoft.VSTS.TCM.Steps")) { xml = testCaseObject.Fields["Microsoft.VSTS.TCM.Steps"].ToString(); tb = helper.Create(); // create tcmattachemntlink object from workitem relation, teststep helper will use this IList <TestAttachmentLink> tcmlinks = new List <TestAttachmentLink>(); foreach (WorkItemRelation rel in testCaseObject.Relations) { TestAttachmentLink tcmlink = new TestAttachmentLink(); tcmlink.Url = rel.Url; tcmlink.Attributes = rel.Attributes; tcmlink.Rel = rel.Rel; tcmlinks.Add(tcmlink); } // load teststep xml and attachemnt links tb.LoadActions(xml, tcmlinks); ITestStep ts; //updating 1st test step ts = (ITestStep)tb.Actions[0]; ts.Title = "title -> title11"; ts.ExpectedResult = "expected11"; //removing 2ns test step tb.Actions.RemoveAt(1); //adding new test step ITestStep ts3 = tb.CreateTestStep(); ts3.Title = "title -> title3"; ts3.ExpectedResult = "expected3"; tb.Actions.Add(ts3); JsonPatchDocument json2 = new JsonPatchDocument(); // update json based on all new changes ( updated step xml and attachments) json2 = tb.SaveActions(json2); // update testcase wit using new json testCaseObject = _witClient.UpdateWorkItemAsync(json2, testCaseId).Result; /* Note : If you want to remove attachment then create new patchOperation, details are available here : * https://www.visualstudio.com/en-us/docs/integrate/api/wit/work-items#remove-an-attachment */ } }
public bool Equals(ITestBase <TInclude>?other) => base.Equals(other) && other?.TestIncludes.SequenceEqual(TestIncludes) == true;
public ScheduleController(ITestBase testBase) { _testBase = testBase; }
public JsonPatchDocument BuildJsonPatchDocument(TestCase testCase) { var jsonPatchDocument = new JsonPatchDocument(); var jsonPatchOperations = new List <JsonPatchOperation>(); TestBaseHelper helper = new TestBaseHelper(); ITestBase testBase = helper.Create(); testCase.Steps.ForEach(x => { ITestStep testStep = testBase.CreateTestStep(); testStep.Title = x.Action ?? string.Empty; testStep.ExpectedResult = x.ExpectedResult ?? string.Empty; testStep.Description = x.Action ?? string.Empty; testBase.Actions.Add(testStep); }); var properties = typeof(TestCase).GetProperties(); foreach (var propertyInfo in properties.Where(x => x.Name != "Steps")) { object[] attrs = propertyInfo.GetCustomAttributes(true); foreach (object attr in attrs) { AzDevFieldReferenceAttribute azDevFieldReferenceAttribute = attr as AzDevFieldReferenceAttribute; if (azDevFieldReferenceAttribute != null) { var data = testCase.GetType().GetProperty(propertyInfo.Name).GetValue(testCase, null); if (propertyInfo.Name.Contains("AttachmentReferences")) { var castedData = data as List <AttachmentReference>; castedData.ForEach(x => { jsonPatchOperations.Add(new JsonPatchOperation { Operation = Microsoft.VisualStudio.Services.WebApi.Patch.Operation.Add, Path = azDevFieldReferenceAttribute.AzDevFieldReference, Value = new { rel = "AttachedFile", url = x.Url } }); }); } else { if (!string.IsNullOrWhiteSpace(data as string)) { jsonPatchOperations.Add(new JsonPatchOperation { Operation = Microsoft.VisualStudio.Services.WebApi.Patch.Operation.Add, Path = azDevFieldReferenceAttribute.AzDevFieldReference, Value = data }); } } } } } jsonPatchDocument.AddRange(jsonPatchOperations); jsonPatchDocument = testBase.SaveActions(jsonPatchDocument); return(jsonPatchDocument); }
public void RemoveTest(ITestBase test) { tests.Remove(test); }
public MoviesController(ITestBase testBase) { _testBase = testBase; }
public static bool UpdateTestCaseDetails(ScenarioDefinition scenarioDefinition, ITestBase testCase) { if (testCase == null) { return(false); } var scenarioDescription = scenarioDefinition?.Description?.Trim() ?? string.Empty; scenarioDescription = scenarioDescription .Replace("\n", "<br>") .Replace("\r", ""); var title = scenarioDefinition?.Name?.Trim() ?? string.Empty; var updated = false; if (testCase.WorkItem.Description.Trim() != scenarioDescription) { testCase.WorkItem.Description = scenarioDescription; updated = true; } if (testCase.Title == title) { return(updated); } testCase.Title = title; return(true); }