Creating a bug when test fails in E2E

In one of the earlier post, we saw how to customize the E2E workflow to automatically create a bug on hitting a test failure. This post enhances the scenario further by taking a snapshot of the environment after the test run and attaching a link to the snapshot to the newly created bug.

Attached is the customized xaml that you can download and use directly, after checking-in the XAML to your source control and creating a new build definition based on that.

Let me go through the additional things I have done on top of what is explained in the previous post :

1. Drag and drop the activity "SnapshotLabEnvironment" from "TeamFouundation Lab Management activities" section in addition to the "OpenWorkItem" activity.


2. Define two new string variables in the scope of the "Sequence" and name them "LocalForwardLinkID" and "LocalsnapshotID".


3. Let's take a look at the "SnapshotLabEnrionment" activity .

This activity takes the "LabEnvironmentUri" and "SnapshotName" as input parameters and snapshots the given environment and returns the ID of the newly taken snapshot. In addition it has an output parameter called SnapshotChainID.

For "LabEnvironmentUri" input parameter, specify the variable LabEnvironmentUri ( the value for which would have been already set in the workflow).

Specify some value for "SnapshotName" input parameter. The snapshot I have given is "TestRunFailureSnapshot" + DateTime.Now.Ticks.ToString. The date time is appeneded to ensure uniqueness of snapshot name.

Assign the return value and the out parameter value of the snapshotLabEnvironment activity to LocalSnapshotID and LocalForwardLinkID respectively.


4. Next step is to pass on the snapshot detail to the newly created bug. As described in this post, it is possible to create Environment /Snapshots links if we know their IDs.

So let's compose a url for the newly taken snapshot and write that url in the bug description and we are done :)

Specify the below value for the "Comment" parameter of the "OpenWorkItem" activity.

String.Format("Snapshot of the environment when the test run happened is : <a href=""lvr://ConnectToFwdLink/?CollectionUri={0}&ForwardLink={1}"">here</a>", LabWorkflowParameters.EnvironmentDetails.TfsUrl, LocalForwardLinkID)

The above string is essentially the url for the newly taken snapshot composed using its ID . It is surrounded by a HREF tag to make it appear as a hyperlink in the bug.

5. Run the build and the new bug will be created when the test run fails. The new bug will look something like below.


6. Clicking on the "here" hyperlink from the history section in the bug will pop up the below dialog where can you chose to revert to the snapshot and debug your failure.


Cheers !