Click here to Skip to main content
Click here to Skip to main content

Tagged as

TFS 2011 API–How to Get Exploratory Testing And Feedback Manager Session Information Programmatically

, 13 Dec 2011
Rate this:
Please Sign up or sign in to vote.
  In this blog post I’ll show you how to use the TFS 2011 API to get the Exploratory Testing & Feedback Manager session information programmatically. Introduction TFS 2011 includes Exploratory Testing and Feedback Manager, the first empowers the testers to explore the application and second empow

 

In this blog post I’ll show you how to use the TFS 2011 API to get the Exploratory Testing & Feedback Manager session information programmatically.

Introduction

TFS 2011 includes Exploratory Testing and Feedback Manager, the first empowers the testers to explore the application and second empowers the stake holders to explore the application. This rhymes a bit… that’s because… under the hood both use the same infrastructure to drive and store the session information. If you try to run both at the same time on a machine you will run in to the following warning message.

image

Note both Feedback manager and Exploratory testing store the results in the table [Tfs_DefaultCollection].[dbo].[tbl_Session] in the TFS operational database.

image

Note - Any direct interaction (including select statements) against the TFS operational databases is strongly discouraged by the Product Team. All such interactions should be done through the TFS SDK.  

How to get the Exploratory Session and Feedback Manager Session programmatically using TFS API…

Download Working Demo… Or follow the steps below,

image

1. Add references

<span style="color: blue">using </span>Microsoft.TeamFoundation.Client;
<span style="color: blue">using </span>Microsoft.TeamFoundation.TestManagement.Client;

 

2. Connect to TFS and select a Team Project

<span style="color: blue">private </span>TfsTeamProjectCollection _tfs;
<span style="color: blue">private string </span>_selectedTeamProject;

<span style="color: blue">private void </span>ConnectToTfsAndPickAProject()
{
     <span style="color: green">// Connect to TFS and pick team project
     </span>TeamProjectPicker tfsPP = <span style="color: blue">new </span>TeamProjectPicker(TeamProjectPickerMode.SingleProject, <span style="color: blue">false</span>);
     tfsPP.ShowDialog();
     <span style="color: blue">this</span>._tfs = tfsPP.SelectedTeamProjectCollection;
     <span style="color: blue">this</span>._selectedTeamProject = tfsPP.SelectedProjects[0].Name;
 }

3. Get access to Session Helper

<span style="color: green">// Get the Session Helper 
</span><span style="color: blue">var </span>tms = _tfs.GetService<ITestManagementService>();
<span style="color: blue">var </span>sessionHelper = tms.GetTeamProject(_selectedTeamProject).<font style="background-color: #ffff00">SessionHelper</font>;

4. Now use the session helper to query for the session Information, for example in the snippet below I am simply getting all sessions,

<span style="color: green">// Get Session by Query
</span><span style="color: blue">var </span>sessionByQuery = sessionHelper.Query(<span style="color: #a31515">"Select * from Session"</span>);
dataGridView1.DataSource = sessionByQuery.ToList();
dataGridView1.AutoGenerateColumns = <span style="color: blue">true</span>;
<span style="color: green">// I could write a more specific query
</span><span style="color: blue">var </span>sessionQueryExample = sessionHelper.Query(<span style="color: #a31515">"Select * from Session where TestPlanId =3"</span>);
 

BONUS – Go one step further...

5. Get Session Information by Link Id: In the Links section in a Bug you can see the test results attachment, you can use the ‘FindByLinkId’ method to get the details of that session programmatically.

<span style="color: green">// Get Session details for a bug raised during session testing
            // 1. Get the bug 
            </span><span style="color: blue">var </span>qBug = <span style="color: #a31515">@"SELECT 
                            [System.Id], 
                            [System.Links.LinkType], 
                            [System.WorkItemType], 
                            [System.Title], 
                            [System.State], 
                            [Custom.TestingTour],
                            [Microsoft.VSTS.Common.Priority] 
                        FROM WorkItems 
                        WHERE [System.TeamProject] = '@project'  
                            AND  [System.WorkItemType] = 'Bug'"
                </span>.Replace(<span style="color: #a31515">"@project"</span>, _selectedTeamProject);

            <span style="color: green">// Get the Wi Store service
            </span><span style="color: blue">var </span>wis = _tfs.GetService<WorkItemStore>();

            <span style="color: blue">var </span>queryBug = <span style="color: blue">new </span>Query(wis, qBug);
            <span style="color: blue">var </span>bugs = queryBug.RunQuery();

            <span style="color: green">// 2. Get the Uri of the session from the bug
            </span><span style="color: blue">foreach </span>(WorkItem bug <span style="color: blue">in </span>bugs)
            {
                <span style="color: blue">foreach </span>(Link l <span style="color: blue">in </span>bug.Links)
                {
                    <span style="color: blue">if </span>(l.ArtifactLinkType != <span style="color: blue">null </span>&& l.ArtifactLinkType.Name == <span style="color: #a31515">"Test Result"</span>)
                    {
                        <span style="color: green">// 3. Get Session Information By URI
                        </span><span style="color: blue">var </span>sessionByUri = sessionHelper.<font style="background-color: #ffff00">FindByLink(</font><span style="color: blue">new </span>Uri(((ExternalLink)l)<font style="background-color: #ffff00">.LinkedArtifactUri</font>));
                    }
                }
            }

 

 

Download the working demo.

You might also enjoy reading => How to customize Process Template In TFS 2011.

Hope you enjoyed this post! Remember to subscribe to http://feeds.feedburner.com/TarunArora.

Enjoy In love

 

Share this post :

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Tarun_Arora
Software Developer (Senior) Avanade
United Kingdom United Kingdom
Solution Developer - C# .NET, ALM
 
Tarun Arora is a Microsoft Certified professional developer for Enterprise Applications. He has over 5 years of experience developing 'Energy Trading & Risk Management' solutions using Microsoft Technologies. Tarun has great passion for technology and travel (not necessarily in the same order)!
Follow on   Twitter

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web04 | 2.8.140814.1 | Last Updated 14 Dec 2011
Article Copyright 2011 by Tarun_Arora
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid