private void FixIterationNotFound(Exception exception, ITestSuiteBase source, IDynamicTestSuite targetSuiteChild, TestManagementContext targetTestStore) { if (exception.Message.Contains("The specified iteration path does not exist.")) { Regex regEx = new Regex(@"'(.*?)'"); var missingIterationPath = regEx.Match(exception.Message).Groups[0].Value; missingIterationPath = missingIterationPath.Substring(missingIterationPath.IndexOf(@"\") + 1, missingIterationPath.Length - missingIterationPath.IndexOf(@"\") - 2); Trace.WriteLine("Found a orphaned iteration path in test suite query."); Trace.WriteLine(string.Format("Invalid iteration path {0}:", missingIterationPath)); Trace.WriteLine("Replacing the orphaned iteration path from query with root iteration path. Please fix the query after the migration."); targetSuiteChild.Query = targetSuiteChild.Project.CreateTestQuery( targetSuiteChild.Query.QueryText.Replace( string.Format(@"'{0}\{1}'", source.Plan.Project.TeamProjectName, missingIterationPath), string.Format(@"'{0}'", targetTestStore.Project.TeamProjectName) )); targetSuiteChild.Query = targetSuiteChild.Project.CreateTestQuery( targetSuiteChild.Query.QueryText.Replace( string.Format(@"'{0}\{1}'", targetTestStore.Project.TeamProjectName, missingIterationPath), string.Format(@"'{0}'", targetTestStore.Project.TeamProjectName) )); } }
private void ApplyConfigurations(ITestSuiteBase source, ITestSuiteBase target) { if (source.DefaultConfigurations != null) { Trace.WriteLine(" CONFIG MNISSMATCH FOUND --- FIX AATTEMPTING", "TestPlansAndSuites"); target.ClearDefaultConfigurations(); IList <IdAndName> targetConfigs = new List <IdAndName>(); foreach (var config in source.DefaultConfigurations) { var targetFound = (from tc in targetTestConfigs where tc.Name == config.Name select tc).SingleOrDefault(); if (!(targetFound == null)) { targetConfigs.Add(new IdAndName(targetFound.Id, targetFound.Name)); } } try { target.SetDefaultConfigurations(targetConfigs); } catch (Exception) { // SOmetimes this will error out for no reason. } } }
private void SaveNewTestSuitToPlan(ITestPlan testPlan, IStaticTestSuite parent, ITestSuiteBase newTestSuite) { Trace.WriteLine( $" Saving {newTestSuite.TestSuiteType} : {newTestSuite.Id} - {newTestSuite.Title} ", "TestPlansAndSuites"); try { ((IStaticTestSuite)parent).Entries.Add(newTestSuite); } catch (TestManagementServerException ex) { Telemetry.Current.TrackException(ex, new Dictionary <string, string> { { "Name", Name }, { "Target Project", me.Target.Name }, { "Target Collection", me.Target.Collection.Name }, { "Source Project", me.Source.Name }, { "Source Collection", me.Source.Collection.Name }, { "Status", Status.ToString() }, { "Task", "SaveNewTestSuitToPlan" }, { "Id", newTestSuite.Id.ToString() }, { "Title", newTestSuite.Title }, { "TestSuiteType", newTestSuite.TestSuiteType.ToString() } }); Trace.WriteLine(string.Format(" FAILED {0} : {1} - {2} | {3}", newTestSuite.TestSuiteType.ToString(), newTestSuite.Id, newTestSuite.Title, ex.Message), "TestPlansAndSuites"); ITestSuiteBase ErrorSuitChild = targetTestStore.Project.TestSuites.CreateStatic(); ErrorSuitChild.TestSuiteEntry.Title = string.Format(@"BROKEN: {0} | {1}", newTestSuite.Title, ex.Message); ((IStaticTestSuite)parent).Entries.Add(ErrorSuitChild); } testPlan.Save(); }
public static SortedDictionary <string, string> GetAllTestCases(string suites, string planId) { SortedDictionary <string, string> lsTestCasesQuery = new SortedDictionary <string, string>(); try { ITestSuiteHelper iTSuiteHelp = proj.TestSuites; string[] suiteArray = suites.Split(','); foreach (string str in suiteArray) { ITestSuiteBase iTSB = iTSuiteHelp.Find(Convert.ToInt32(str)); ITestCaseCollection itCColl = iTSB.AllTestCases; foreach (ITestCase iTc in itCColl) { lsTestCasesQuery.Add(iTc.Id.ToString(), iTc.Title.ToString()); } } } catch (Exception ex) { lsTestCasesQuery.Add("-1", "Error. Load Project,pland and config"); } return(lsTestCasesQuery); }
private void FixQueryForTeamProjectNameChange(ITestSuiteBase source, IDynamicTestSuite targetSuiteChild, TestManagementContext targetTestStore) { // Replacing old projectname in queries with new projectname // The target team project name is only available via target test store because the dyn. testsuite isnt saved at this point in time if (!source.Plan.Project.TeamProjectName.Equals(targetTestStore.Project.TeamProjectName)) { Trace.WriteLine(string.Format(@"Team Project names dont match. We need to fix the query in dynamic test suite {0} - {1}.", source.Id, source.Title)); Trace.WriteLine(string.Format(@"Replacing old project name {1} in query {0} with new team project name {2}", targetSuiteChild.Query.QueryText, source.Plan.Project.TeamProjectName, targetTestStore.Project.TeamProjectName)); // First need to check is prefix project nodes has been applied for the migration if (config.PrefixProjectToNodes) { // if prefix project nodes has been applied we need to take the original area/iteration value and prefix targetSuiteChild.Query = targetSuiteChild.Project.CreateTestQuery(targetSuiteChild.Query.QueryText.Replace( string.Format(@"'{0}", source.Plan.Project.TeamProjectName), string.Format(@"'{0}\{1}", targetTestStore.Project.TeamProjectName, source.Plan.Project.TeamProjectName))); } else { // If we are not profixing project nodes then we just need to take the old value for the project and replace it with the new project value targetSuiteChild.Query = targetSuiteChild.Project.CreateTestQuery(targetSuiteChild.Query.QueryText.Replace( string.Format(@"'{0}", source.Plan.Project.TeamProjectName), string.Format(@"'{0}", targetTestStore.Project.TeamProjectName))); } Trace.WriteLine(string.Format("New query is now {0}", targetSuiteChild.Query.QueryText)); } }
// copied from http://automatetheplanet.com/manage-tfs-test-suites-csharp-code/ public void DeleteSuite(ITestPlan testPlan, int suiteToBeRemovedId, IStaticTestSuite parent = null) { ITestSuiteBase currentSuite = _client.TeamProject.TestSuites.Find(suiteToBeRemovedId); if (currentSuite == null) { throw new TestObjectNotFoundException(string.Format("Suite can't be found")); } // Remove the parent child relation. This is the only way to delete the suite. if (parent != null) { parent.Entries.Remove(currentSuite); } else if (currentSuite.Parent != null) { currentSuite.Parent.Entries.Remove(currentSuite); } else { // If it's initial suite, remove it from the test plan. testPlan.RootSuite.Entries.Remove(currentSuite); } // Apply changes to the suites testPlan.Save(); }
public void AddTestCasesToSuite(IEnumerable <ITestCase> testCases, ITestSuiteBase destinationSuite) { if (destinationSuite.TestSuiteType == TestSuiteType.StaticTestSuite) { IStaticTestSuite staticTestSuite = destinationSuite as IStaticTestSuite; if (staticTestSuite != null) { staticTestSuite.Entries.AddCases(testCases); } } else if (destinationSuite.TestSuiteType == TestSuiteType.RequirementTestSuite) { IRequirementTestSuite requirementTestSuite = destinationSuite as IRequirementTestSuite; if (requirementTestSuite != null) { WorkItemStore store = requirementTestSuite.Project.WitProject.Store; WorkItem tfsRequirement = store.GetWorkItem(requirementTestSuite.RequirementId); foreach (ITestCase testCase in testCases) { tfsRequirement.Links.Add(new RelatedLink(store.WorkItemLinkTypes.LinkTypeEnds["Tested By"], testCase.WorkItem.Id)); } tfsRequirement.Save(); } } destinationSuite.Plan.Save(); }
/// <summary> /// Removes all test cases information suite. /// </summary> /// <param name="currentSuite">The current suite.</param> public static void RemoveAllTestCasesInSuite(ITestSuiteBase currentSuite) { foreach (ITestCase currentTestCase in currentSuite.TestCases) { RemoveTestCaseInternal(currentTestCase, currentSuite); } }
public void ListTestCasesInSuite(ITestSuiteBase suite) { foreach (ITestCase testCase in suite.AllTestCases) { Console.WriteLine(testCase.Title); } }
/// <summary> /// Deletes the suite. /// </summary> /// <param name="suiteToBeRemovedId">The suite to be removed unique identifier.</param> /// <param name="parent">The parent.</param> /// <exception cref="System.ArgumentException">The root suite cannot be deleted!</exception> public static void DeleteSuite(ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan, int suiteToBeRemovedId, IStaticTestSuite parent = null) { // If it's root suite throw exception if (suiteToBeRemovedId == -1) { throw new ArgumentException("The root suite cannot be deleted!"); } ITestSuiteBase currentSuite = testManagementTeamProject.TestSuites.Find(suiteToBeRemovedId); // Remove the parent child relation. This is the only way to delete the suite. if (parent != null) { log.InfoFormat("Remove suite Title= \"{0}\", id= \"{1}\" from suite Title= \"{2}\", id= \"{3}\"", currentSuite.Title, currentSuite.Id, parent.Title, parent.Id); parent.Entries.Remove(currentSuite); } else if (currentSuite.Parent != null) { log.InfoFormat("Remove suite Title= \"{0}\", id= \"{1}\" from suite Title= \"{2}\", id= \"{3}\"", currentSuite.Title, currentSuite.Id, currentSuite.Parent.Title, currentSuite.Parent.Id); currentSuite.Parent.Entries.Remove(currentSuite); } else { // If it's initial suite, remove it from the test plan. testPlan.RootSuite.Entries.Remove(currentSuite); log.Info("Remove suite Title= \"{0}\", id= \"{1}\" from test plan."); } // Apply changes to the suites testPlan.Save(); }
/// <summary> /// Sets default configurations on migrated test suites. /// </summary> /// <param name="source">The test suite to take as a source.</param> /// <param name="target">The test suite to apply the default configurations to.</param> private void ApplyDefaultConfigurations(ITestSuiteBase source, ITestSuiteBase target) { if (source.DefaultConfigurations != null) { Trace.WriteLine($" Setting default configurations for suite {target.Title}", "TestPlansAndSuites"); IList <IdAndName> targetConfigs = new List <IdAndName>(); foreach (var config in source.DefaultConfigurations) { var targetFound = (from tc in targetTestConfigs where tc.Name == config.Name select tc).SingleOrDefault(); if (targetFound != null) { targetConfigs.Add(new IdAndName(targetFound.Id, targetFound.Name)); } } try { target.SetDefaultConfigurations(targetConfigs); } catch (Exception) { // SOmetimes this will error out for no reason. } } else { target.ClearDefaultConfigurations(); } }
/// <summary> /// Adds the child suite. /// </summary> /// <param name="parentSuiteId">The parent suite unique identifier.</param> /// <param name="title">The title.</param> /// <param name="canBeAdded">if set to <c>true</c> [can be added].</param> /// <returns> /// new suite unique identifier. /// </returns> public static int AddChildSuite(ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan, int parentSuiteId, string title, out bool canBeAdded) { ITestSuiteBase parentSuite = null; if (parentSuiteId != -1) { parentSuite = testManagementTeamProject.TestSuites.Find(parentSuiteId); } if (parentSuite is IRequirementTestSuite) { canBeAdded = false; return(0); } IStaticTestSuite staticSuite = testManagementTeamProject.TestSuites.CreateStatic(); canBeAdded = true; staticSuite.Title = title; if (parentSuite != null && parentSuite is IStaticTestSuite && parentSuiteId != -1) { IStaticTestSuite parentSuiteStatic = parentSuite as IStaticTestSuite; parentSuiteStatic.Entries.Add(staticSuite); log.InfoFormat("Add child suite to suite with Title= {0}, Id = {1}, child suite title= {2}", parentSuite.Title, parentSuite.Id, title); } else { testPlan.RootSuite.Entries.Add(staticSuite); log.InfoFormat("Add child suite with title= {0} to test plan", title); } testPlan.Save(); return(staticSuite.Id); }
void BtnGenerateXMLFile_Click(object sender, RoutedEventArgs e) { if (TbFileName.Text == null || TbFileName.Text.Length.Equals(0)) { MessageBox.Show("Please Enter a valid file path"); } else { if (TvSuites.SelectedValue != null) { var tvItem = TvSuites.SelectedItem as TreeViewItem; _suite = _testProject.TestSuites.Find(Convert.ToInt32(tvItem.Tag.ToString())); if (_suite != null) { WriteTestPlanToXml(_suite); } } else { MessageBox.Show("Please select a test suite"); } } }
void WriteTestPlanToXml(ITestSuiteBase rootSuite) { try { var xmlDoc = new XmlDocument(); if (rootSuite.TestSuiteType == TestSuiteType.StaticTestSuite) { WriteRootSuite(rootSuite as IStaticTestSuite, xmlDoc); } if (rootSuite.TestSuiteType == TestSuiteType.DynamicTestSuite) { WriteRootSuite(rootSuite as IDynamicTestSuite, xmlDoc); } if (rootSuite.TestSuiteType == TestSuiteType.RequirementTestSuite) { WriteRootSuite(rootSuite as IRequirementTestSuite, xmlDoc); } xmlDoc.Save(TbFileName.Text); MessageBox.Show("File has been saved at " + TbFileName.Text); } catch (Exception theException) { var errorMessage = "Error: "; errorMessage = String.Concat(errorMessage, theException.Message); errorMessage = String.Concat(errorMessage, " Line: "); errorMessage = String.Concat(errorMessage, theException.Source); MessageBox.Show(errorMessage, "Error"); } }
public void UpdateQueryConditions(ITestPlan testPlan, string testSuiteName, string replaced, string replacing) { if (string.IsNullOrWhiteSpace(testSuiteName)) { List <IDynamicTestSuite> dynamicTestSuites = new List <IDynamicTestSuite>(); ITestSuiteEntryCollection suiteCollection = testPlan.RootSuite.Entries; GetAllQueryBasedTestSuiteFromSuiteNode(suiteCollection, dynamicTestSuites); foreach (IDynamicTestSuite dynamicTestSuite in dynamicTestSuites) { UpdateQueryConditionsToSuite(dynamicTestSuite, replaced, replacing); } } else { ITestSuiteBase testSuite = GetSuites(testPlan.Name, testSuiteName) .FirstOrDefault( s => s.TestSuiteType.Equals(TestSuiteType.DynamicTestSuite)); if (testSuite == null) { throw new TestObjectNotFoundException(string.Format("Query based test suite - {0} not found", testSuiteName)); } var dynamicTestSuite = testSuite as IDynamicTestSuite; UpdateQueryConditionsToSuite(dynamicTestSuite, replaced, replacing); } }
private void GetAllTestSuitesFromSuiteNode( int rootSuiteId, ICollection <ITestSuiteBase> testSuites) { ITestSuiteBase suite = GetSuiteById(rootSuiteId); if (suite == null) { return; } testSuites.Add(suite); if (suite.TestSuiteType.Equals(TestSuiteType.StaticTestSuite)) { IStaticTestSuite staticSuite = suite as IStaticTestSuite; if (staticSuite != null) { foreach (ITestSuiteEntry testSuiteEntry in staticSuite.Entries) { GetAllTestSuitesFromSuiteNode(testSuiteEntry.Id, testSuites); } } } }
/// <summary> /// Initializes a new instance of the <see cref="TestCase" /> class. /// </summary> /// <param name="testCaseCore">The test case core object.</param> /// <param name="testSuiteBaseCore">The test suite base core object.</param> /// <param name="initializeStatus">if set to <c>true</c> [initialize status].</param> public TestCase(ITestCase testCaseCore, ITestSuiteBase testSuiteBaseCore, ITestPlan testPlan, bool initializeStatus = true) { this.ITestCase = testCaseCore; this.ITestSuiteBase = testSuiteBaseCore; this.TestCaseId = testCaseCore.Id; this.Title = testCaseCore.Title; this.Area = testCaseCore.Area; this.Priority = (Priority)testCaseCore.Priority; if (testCaseCore.OwnerTeamFoundationId != default(Guid) && !string.IsNullOrEmpty(testCaseCore.OwnerName)) { this.TeamFoundationIdentityName = new TeamFoundationIdentityName(testCaseCore.OwnerTeamFoundationId, testCaseCore.OwnerName); } this.OwnerDisplayName = testCaseCore.OwnerName; this.TeamFoundationId = testCaseCore.OwnerTeamFoundationId; this.TestSuiteId = (testSuiteBaseCore == null) ? null : (int?)testSuiteBaseCore.Id; base.isInitialized = true; this.Id = testCaseCore.Id; this.DateCreated = testCaseCore.DateCreated; this.DateModified = testCaseCore.DateModified; this.CreatedBy = testCaseCore.WorkItem.CreatedBy; if (testSuiteBaseCore != null) { this.TestSuiteTitle = testSuiteBaseCore.Title; } if (initializeStatus) { string mostRecentResult = TestCaseManager.GetMostRecentTestCaseResult(testPlan, this.Id); this.LastExecutionOutcome = TestCaseManager.GetTestCaseExecutionType(mostRecentResult); } if (ExecutionContext.TestCaseRuns.ContainsKey(this.Id)) { this.IsRunning = "R"; } }
private ITestSuiteBase CreateNewStaticTestSuite(ITestSuiteBase source) { ITestSuiteBase targetSuiteChild = targetTestStore.Project.TestSuites.CreateStatic(); targetSuiteChild.TestSuiteEntry.Title = source.TestSuiteEntry.Title; return(targetSuiteChild); }
private Thread CreateTaskThread() { return(new Thread(() => { while (true) { try { using (new ConsoleFormatter(ConsoleColor.DarkGreen, ConsoleColor.White)) { Console.WriteLine($"Refreshing data at: {DateTime.Now.ToShortTimeString()}"); } lock (handle) { using (TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(context.ApiUrl))) { ITestManagementService service = tfs.GetService(typeof(ITestManagementService)) as ITestManagementService; ITestManagementTeamProject testProject = service.GetTeamProject(context.Project); //Can extract information about the test suite from here ITestSuiteBase testSuite = testProject.TestSuites.Find(context.SuiteId); //This is a given instance of the test suite , I.E the test plan (suites can be re-used) ITestPlan testPlan = testProject.TestPlans.Find(context.PlanId); Console.WriteLine($"Test Suite: {testSuite.Title} \n Description: {testPlan.Description} \n Last Updated: {testPlan.LastUpdated}"); testPlanDataSetFactory.Initialize(testPlan, testProject, context.ApiUrl, context.Project); } } Thread.Sleep(TimeSpan.FromMinutes(context.RefreshTime)); } catch (ThreadInterruptedException) { // This is used as a way to wake up sleeping thread. } } })); }
private void BtnGenerate_Click(object sender, RoutedEventArgs e) { if (TbFileNameForExcel.Text == null || TbFileNameForExcel.Text.Length.Equals(0)) { System.Windows.MessageBox.Show("Please Enter a valid file path"); } else { // string subPath = null; // subPath = @"C:\Users\vsanoglu\Desktop\Projects\Barclays\testevidances";// your code goes here // System.IO.Directory.CreateDirectory(subPath); _i = 3; if (TvSuites.SelectedValue != null) { var tvItem = TvSuites.SelectedItem as TreeViewItem; _suite = _testProject.TestSuites.Find(Convert.ToInt32(tvItem.Tag.ToString())); if (_suite != null) { Access_Excel(_suite, _testProject); } } else { System.Windows.MessageBox.Show("Please select a test suite"); } } }
/// <summary> /// Renames the suite. /// </summary> /// <param name="suiteId">The suite unique identifier.</param> /// <param name="newName">The new name.</param> public static void RenameSuite(ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan, int suiteId, string newName) { ITestSuiteBase currentSuite = testManagementTeamProject.TestSuites.Find(suiteId); log.InfoFormat("Change Suite title from {0} to {1}, Suite Id = {2}", currentSuite.Title, newName, currentSuite.Id); currentSuite.Title = newName; testPlan.Save(); }
private void ApplyTestSuiteQuery(ITestSuiteBase source, IDynamicTestSuite targetSuiteChild, TestManagementContext targetTestStore) { targetSuiteChild.Query = ((IDynamicTestSuite)source).Query; // Postprocessing common errors FixQueryForTeamProjectNameChange(source, targetSuiteChild, targetTestStore); FixWorkItemIdInQuery(targetSuiteChild); }
/// <summary> /// Pastes the test cases to suite. /// </summary> /// <param name="testManagementTeamProject">The test management team project.</param> /// <param name="testPlan">The test plan.</param> /// <param name="suiteToAddInId">The suite automatic add information unique identifier.</param> /// <param name="clipBoardTestCase">The clip board test case.</param> /// <exception cref="System.ArgumentException">New test cases cannot be added to requirement based suites!</exception> public static void PasteTestCasesToSuite(ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan, int suiteToAddInId, ClipBoardTestCase clipBoardTestCase) { ITestSuiteBase suiteToAddIn = testManagementTeamProject.TestSuites.Find(suiteToAddInId); if (suiteToAddIn is IRequirementTestSuite) { throw new ArgumentException("New test cases cannot be added to requirement based suites!"); } IStaticTestSuite suiteToAddInStatic = suiteToAddIn as IStaticTestSuite; ITestSuiteBase oldSuite; List <TestCase> allTestCasesInPlan = null; if (clipBoardTestCase.TestCases[0].TestSuiteId != null) { oldSuite = testManagementTeamProject.TestSuites.Find((int)clipBoardTestCase.TestCases[0].TestSuiteId); } else { oldSuite = null; } foreach (TestCase currentTestCase in clipBoardTestCase.TestCases) { ITestCase testCaseCore = null; if (oldSuite is IRequirementTestSuite) { IRequirementTestSuite suite = oldSuite as IRequirementTestSuite; testCaseCore = suite.TestCases.Where(x => x.TestCase != null && x.TestCase.Id.Equals(currentTestCase.TestCaseId)).FirstOrDefault().TestCase; } else if (oldSuite is IStaticTestSuite) { IStaticTestSuite suite = oldSuite as IStaticTestSuite; testCaseCore = suite.Entries.Where(x => x.TestCase != null && x.TestCase.Id.Equals(currentTestCase.TestCaseId)).FirstOrDefault().TestCase; } else if (oldSuite == null) { if (allTestCasesInPlan == null) { allTestCasesInPlan = TestCaseManager.GetAllTestCasesInTestPlan(testManagementTeamProject, testPlan); } testCaseCore = allTestCasesInPlan.Where(t => t.TestCaseId.Equals(currentTestCase.TestCaseId)).FirstOrDefault().ITestCase; } if (!suiteToAddInStatic.Entries.Contains(testCaseCore)) { suiteToAddInStatic.Entries.Add(testCaseCore); } if (clipBoardTestCase.ClipBoardCommand.Equals(ClipBoardCommand.Cut)) { if (oldSuite is IStaticTestSuite) { IStaticTestSuite suite = oldSuite as IStaticTestSuite; suite.Entries.Remove(testCaseCore); } } } testPlan.Save(); }
private void AddChildTestCases(ITestSuiteBase source, ITestSuiteBase target, ITestPlan targetPlan) { target.Refresh(); targetPlan.Refresh(); targetPlan.RefreshRootSuite(); if (CanSkipElementBecauseOfTags(source.Id)) { return; } Trace.WriteLine(string.Format(" Suite has {0} test cases", source.TestCases.Count), "TestPlansAndSuites"); List <ITestCase> tcs = new List <ITestCase>(); foreach (ITestSuiteEntry sourceTestCaseEntry in source.TestCases) { Trace.WriteLine($"Work item: {sourceTestCaseEntry.Id}"); if (CanSkipElementBecauseOfTags(sourceTestCaseEntry.Id)) { return; } Trace.WriteLine(string.Format(" Processing {0} : {1} - {2} ", sourceTestCaseEntry.EntryType.ToString(), sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites"); WorkItem wi = targetWitStore.FindReflectedWorkItem(sourceTestCaseEntry.TestCase.WorkItem, me.ReflectedWorkItemIdFieldName, false); if (wi == null) { Trace.WriteLine(string.Format(" Can't find work item for Test Case. Has it been migrated? {0} : {1} - {2} ", sourceTestCaseEntry.EntryType.ToString(), sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites"); break; } var exists = (from tc in target.TestCases where tc.TestCase.WorkItem.Id == wi.Id select tc).SingleOrDefault(); if (exists != null) { Trace.WriteLine(string.Format(" Test case already in suite {0} : {1} - {2} ", sourceTestCaseEntry.EntryType.ToString(), sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites"); } else { ITestCase targetTestCase = targetTestStore.Project.TestCases.Find(wi.Id); if (targetTestCase == null) { Trace.WriteLine(string.Format(" ERROR: Test case not found {0} : {1} - {2} ", sourceTestCaseEntry.EntryType, sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites"); } else { tcs.Add(targetTestCase); Trace.WriteLine(string.Format(" Adding {0} : {1} - {2} ", sourceTestCaseEntry.EntryType.ToString(), sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites"); } } } target.TestCases.AddCases(tcs); targetPlan.Save(); Trace.WriteLine(string.Format(" SAVED {0} : {1} - {2} ", target.TestSuiteType.ToString(), target.Id, target.Title), "TestPlansAndSuites"); }
private void ProcessChildTestCases(ITestSuiteBase source, ITestSuiteBase target, ITestPlan targetPlan) { if (CanSkipElementBecauseOfTags(source.Id)) { return; } Trace.WriteLine(string.Format(" Suite has {0} test cases", source.TestCases.Count), "TestPlansAndSuites"); List <ITestCase> tcs = new List <ITestCase>(); foreach (ITestSuiteEntry sourceTestCaseEntry in source.TestCases) { if (CanSkipElementBecauseOfTags(sourceTestCaseEntry.Id)) { return; } Trace.WriteLine(string.Format(" Processing {0} : {1} - {2} ", sourceTestCaseEntry.EntryType.ToString(), sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites"); WorkItem wi = targetWitStore.FindReflectedWorkItem(sourceTestCaseEntry.TestCase.WorkItem, me.ReflectedWorkItemIdFieldName, false); if (wi == null) { Trace.WriteLine(string.Format(" ERROR NOT FOUND {0} : {1} - {2} ", sourceTestCaseEntry.EntryType.ToString(), sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites"); break; } var exists = (from tc in target.TestCases where tc.TestCase.WorkItem.Id == wi.Id select tc).SingleOrDefault(); if (exists != null) { Trace.WriteLine(string.Format(" EXISTS {0} : {1} - {2} ", sourceTestCaseEntry.EntryType.ToString(), sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites"); ApplyConfigurations(sourceTestCaseEntry, exists); } else { ITestCase targetTestCase = targetTestStore.Project.TestCases.Find(wi.Id); if (targetTestCase == null) { Trace.WriteLine(string.Format(" ERROR TEST CASE NOT FOUND {0} : {1} - {2} ", sourceTestCaseEntry.EntryType, sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites"); } else { ApplyConfigurations(sourceTestCaseEntry, targetTestCase.TestSuiteEntry); tcs.Add(targetTestCase); Trace.WriteLine(string.Format(" ADDING {0} : {1} - {2} ", sourceTestCaseEntry.EntryType.ToString(), sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites"); } } } if (source.TestSuiteType == TestSuiteType.StaticTestSuite && HasChildTestCases(source)) { target.TestCases.AddCases(tcs); } targetPlan.Save(); Trace.WriteLine(string.Format(" SAVED {0} : {1} - {2} ", target.TestSuiteType.ToString(), target.Id, target.Title), "TestPlansAndSuites"); }
private static void Main(string[] args) { List <string> xmlConfigFileNameArray = new List <string>(); string pathOfTestSuites = Path.Combine(AppContext.BaseDirectory, "TestSuites"); if (!Directory.Exists(pathOfTestSuites)) { Directory.CreateDirectory(pathOfTestSuites); } if (args.Length > 1) { xmlConfigFileNameArray = args.Skip(1).ToList(); } else { xmlConfigFileNameArray = Directory.GetFiles(pathOfTestSuites, "*.xml", SearchOption.TopDirectoryOnly).ToList(); } foreach (var moduleXmlFilePath in xmlConfigFileNameArray) { //moduleXmlFilePath = "D:\\TFS_REPO\\Hackathon2018_ATOM\\AurigoTest\\ModuleXYZ_TestSuite\\ModuleXYZ_TestSuite.xml"; List <string> methodsToRun = null; TestSuiteConfigFile tsConfigFile = ParseConfigXmlAndExtractTestcasesToRun(moduleXmlFilePath, out methodsToRun); var dllPath = Path.Combine(pathOfTestSuites, tsConfigFile.LibraryAssemblyName); if (!dllPath.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase)) { dllPath += ".dll"; } if (!File.Exists(dllPath)) { Console.WriteLine($"Missing dll {tsConfigFile.LibraryAssemblyName}"); continue; } try { //Load the assembly from the specified path. var MyAssembly = Assembly.LoadFrom(dllPath); var obj = MyAssembly.CreateInstance(tsConfigFile.LibraryName); ITestSuiteBase tsbase = obj as ITestSuiteBase; tsbase.RunTest(methodsToRun); } catch (Exception e) { } } }
private ITestSuiteBase CreateNewDynamicTestSuite(ITestSuiteBase source) { IDynamicTestSuite targetSuiteChild = targetTestStore.Project.TestSuites.CreateDynamic(); targetSuiteChild.TestSuiteEntry.Title = source.TestSuiteEntry.Title; ApplyTestSuiteQuery(source, targetSuiteChild, targetTestStore); return(targetSuiteChild); }
/// <summary> /// Initializes a new instance of the <see cref="TestCaseEditViewModel"/> class. /// </summary> /// <param name="editViewContext">The edit view context.</param> public TestCaseEditViewModel(EditViewContext editViewContext) { this.EditViewContext = editViewContext; this.Areas = this.GetProjectAreas(); this.ObservableTestSteps = new ObservableCollection <TestStep>(); this.GenericParameters = new Dictionary <string, Dictionary <string, string> >(); if (!this.EditViewContext.IsSharedStep) { this.ShowTestCaseSpecificFields = true; ITestSuiteBase testSuiteBaseCore = null; if (this.EditViewContext.TestSuiteId != -1) { testSuiteBaseCore = TestSuiteManager.GetTestSuiteById(TestCaseManagerCore.ExecutionContext.TestManagementTeamProject, TestCaseManagerCore.ExecutionContext.Preferences.TestPlan, this.EditViewContext.TestSuiteId); } if (this.EditViewContext.CreateNew && !this.EditViewContext.Duplicate) { ITestCase newTestCase = TestCaseManagerCore.ExecutionContext.TestManagementTeamProject.TestCases.Create(); this.TestCase = new TestCase(newTestCase, testSuiteBaseCore, TestCaseManagerCore.ExecutionContext.Preferences.TestPlan, false); } else { ITestCase testCaseCore = TestCaseManagerCore.ExecutionContext.TestManagementTeamProject.TestCases.Find(this.EditViewContext.TestCaseId); this.TestCase = new TestCase(testCaseCore, testSuiteBaseCore, TestCaseManagerCore.ExecutionContext.Preferences.TestPlan, false); } this.ObservableSharedSteps = new ObservableCollection <SharedStep>(); this.InitializeObservableSharedSteps(); this.InitializeInitialSharedStepCollection(); this.InitializeTestCaseTestStepsFromITestCaseActions(); this.AssociatedAutomation = this.TestCase.ITestCase.GetAssociatedAutomation(); this.TestBase = this.TestCase; } else { if (this.EditViewContext.CreateNew && !this.EditViewContext.Duplicate) { ISharedStep currentSharedStepCore = TestCaseManagerCore.ExecutionContext.TestManagementTeamProject.SharedSteps.Create(); this.SharedStep = new SharedStep(currentSharedStepCore); } else { SharedStep currentSharedStep = SharedStepManager.GetSharedStepById(TestCaseManagerCore.ExecutionContext.TestManagementTeamProject, this.EditViewContext.SharedStepId); this.SharedStep = currentSharedStep; } List <TestStep> innerTestSteps = TestStepManager.GetAllTestStepsInSharedStep(this.SharedStep.ISharedStep, false); this.AddTestStepsToObservableCollection(innerTestSteps); this.ShowTestCaseSpecificFields = false; this.TestBase = this.SharedStep; this.ClearTestStepNames(); } this.InitializeIdLabelFromTestBase(this.EditViewContext.CreateNew, this.EditViewContext.Duplicate); this.InitializePageTitle(); log.InfoFormat("Load Edit View with Context: {0} ", editViewContext); TestStepManager.UpdateGenericSharedSteps(this.ObservableTestSteps); }
private bool HasChildSuits(ITestSuiteBase sourceSuit) { bool hasChildren = false; if (sourceSuit != null && sourceSuit.TestSuiteType == TestSuiteType.StaticTestSuite) { hasChildren = (((IStaticTestSuite)sourceSuit).Entries.Count > 0); } return(hasChildren); }
private ITestSuiteBase CreateNewStaticTestSuit(ITestSuiteBase source) { ITestSuiteBase targetSuitChild = targetTestStore.Project.TestSuites.CreateStatic(); if (source.TestSuiteEntry.Configurations != null) { ApplyConfigurations(source, targetSuitChild); } targetSuitChild.TestSuiteEntry.Title = source.TestSuiteEntry.Title; return(targetSuitChild); }
//create test point public static ITestPoint CreateTestPoints(ITestPlan testPlan, ITestSuiteBase suite, ITestCase testcase) { try { ITestPointCollection tpc = testPlan.QueryTestPoints("SELECT * FROM TestPoint WHERE SuiteId = " + suite.Id + " and TestCaseID =" + testcase.Id); ITestPoint tp = testPlan.FindTestPoint(tpc[0].Id); return tp; } catch (Exception e) { throw e; } }
public TestObjectViewModel(ITestSuiteBase testSuite, bool includeTests = true) : base(null, true) { _includeTests = includeTests; _testObject = new TestObject(testSuite.Title, testSuite.Id, TestObjectType.Suite); _testObject.TestSuiteBase = testSuite; _testObject.TestPlanID = testSuite.Plan.Id; StructureFlow += ";" + testSuite.ToString(); CanChecked = testSuite.TestSuiteType == TestSuiteType.StaticTestSuite || testSuite.TestSuiteType == TestSuiteType.RequirementTestSuite; Thread t = new Thread(new ThreadStart(GetInternalTestCaseDetails)); t.Start(); }
public SelectableTestSuite(ITestSuiteBase testSuite) { TestSuite = testSuite; Title = testSuite.Title; }
private List<TestObjectViewModel> RecursiveSuiteCollector(TestObjectViewModel item, ITestSuiteBase suite, List<TestObjectViewModel> selectedItems) { IStaticTestSuite staticSuite = null; IDynamicTestSuite dynamicSuite = null; IRequirementTestSuite requirmentSuite = null; ITestSuiteBase suiteBase = TfsShared.Instance.SourceTestProject.TestSuites.Find(item.ID); if (suiteBase.TestSuiteType == TestSuiteType.StaticTestSuite) { staticSuite = (IStaticTestSuite)suiteBase; if (item.IsChecked) { selectedItems.AddRange(staticSuite.TestCases.Select(test => new TestObjectViewModel(test) { TestSuiteId = suite.Id })); if (staticSuite.SubSuites.Count > 0) { foreach (ITestSuiteBase subSuite in staticSuite.SubSuites) { var children = item.Children.Where(t => t.ID > 0 && t.ID == subSuite.Id); if(children.Count()>0) RecursiveSuiteCollector(children.First(), subSuite, selectedItems); } } } } else if ((suite.TestSuiteType == TestSuiteType.DynamicTestSuite) && (item.IsChecked)) { dynamicSuite = (IDynamicTestSuite)suite; selectedItems.AddRange(dynamicSuite.TestCases.Select(test => new TestObjectViewModel(test) { TestSuiteId = suite.Id })); } else if ((suite.TestSuiteType == TestSuiteType.RequirementTestSuite) && (item.IsChecked)) { requirmentSuite = (IRequirementTestSuite)suite; selectedItems.AddRange(requirmentSuite.TestCases.Select(test => new TestObjectViewModel(test) { TestSuiteId = suite.Id })); } return selectedItems; }
public void Export(string filename, ITestSuiteBase testSuite) { using (var pkg = new ExcelPackage()) { var sheet = pkg.Workbook.Worksheets.Add("Test Script"); sheet.Cells[1, 1].Value = "Work Item ID"; sheet.Cells[1, 2].Value = "Test Condition"; sheet.Cells[1, 3].Value = "Action/Description"; sheet.Cells[1, 4].Value = "Input Data"; sheet.Cells[1, 5].Value = "Expected Result"; sheet.Cells[1, 6].Value = "Actual Result"; sheet.Cells[1, 7].Value = "Pass/Fail"; sheet.Cells[1, 8].Value = "Comments"; sheet.Column(1).Width = 15; sheet.Column(2).Width = 15; sheet.Column(3).Width = 50; sheet.Column(4).Width = 15; sheet.Column(5).Width = 50; sheet.Column(6).Width = 50; sheet.Column(7).Width = 15; sheet.Column(8).Width = 20; int row = 2; foreach (var testCase in testSuite.AllTestCases) { var replacementSets = GetReplacementSets(testCase); foreach (var replacements in replacementSets) { var firstRow = row; foreach (var testAction in testCase.Actions) { AddSteps(sheet, testAction, replacements, ref row); } if (firstRow != row) { var mergedID = sheet.Cells[firstRow, 1, row - 1, 1]; mergedID.Merge = true; mergedID.Value = testCase.WorkItem == null ? "" : testCase.WorkItem.Id.ToString(); mergedID.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; mergedID.Style.VerticalAlignment = ExcelVerticalAlignment.Top; var mergedText = sheet.Cells[firstRow, 2, row - 1, 2]; mergedText.Merge = true; CleanupText(mergedText, testCase.Title, replacements); mergedText.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; mergedText.Style.VerticalAlignment = ExcelVerticalAlignment.Top; } } } var header = sheet.Cells[1, 1, 1, 8]; header.Style.Font.Bold = true; header.Style.Fill.PatternType = ExcelFillStyle.Solid; header.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(255, 226, 238, 18)); sheet.Cells[1, 1, row, 8].Style.WrapText = true; pkg.SaveAs(new FileInfo(filename)); } }
/// <summary> /// Removes the test case internal. /// </summary> /// <param name="testCaseToRemove">The test case automatic remove.</param> /// <param name="currentSuite">The current suite.</param> private static void RemoveTestCaseInternal(ITestCase testCaseToRemove, ITestSuiteBase currentSuite) { if (currentSuite != null) { log.InfoFormat("Remove Test Case with id= {0}, Title = {1} from Suite with id= {2}, Title= {3}", testCaseToRemove.Id, testCaseToRemove.Title, currentSuite.Id, currentSuite.Title); if (currentSuite is IRequirementTestSuite) { IRequirementTestSuite suite = currentSuite as IRequirementTestSuite; suite.AllTestCases.Remove(testCaseToRemove); suite.TestCases.RemoveCases(new List<ITestCase>() { testCaseToRemove }); } else if (currentSuite is IStaticTestSuite) { IStaticTestSuite suite = currentSuite as IStaticTestSuite; suite.Entries.Remove(testCaseToRemove); } } }