<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Have Computer Will Code</title>
	<atom:link href="http://www.havecomputerwillcode.com/blog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.havecomputerwillcode.com/blog</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sun, 06 May 2012 10:19:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Pronto v1.5 Released (Productivity Tool for Automating MTM Test Cases)</title>
		<link>http://www.havecomputerwillcode.com/blog/?p=810</link>
		<comments>http://www.havecomputerwillcode.com/blog/?p=810#comments</comments>
		<pubDate>Sun, 06 May 2012 10:12:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ALM]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[BrekIT]]></category>
		<category><![CDATA[MsTest]]></category>
		<category><![CDATA[MTM]]></category>
		<category><![CDATA[Pronto]]></category>
		<category><![CDATA[Test Automation]]></category>
		<category><![CDATA[VS2010]]></category>
		<category><![CDATA[VSX]]></category>

		<guid isPermaLink="false">http://www.havecomputerwillcode.com/blog/?p=810</guid>
		<description><![CDATA[Pronto lets you create test stubs (including data binding and documentation) for your manual MTM Test Cases in C# or VB.Net by dragging those test cases onto your source file. You can then use Pronto&#8217;s Bulk Associated Automation Assistant to associate many of your test methods with your MTM test cases in one go. Uses [...]]]></description>
			<content:encoded><![CDATA[<p>Pronto lets you create test stubs (including data binding and documentation) for your manual MTM Test Cases in C# or VB.Net by dragging those test cases onto your source file. You can then use Pronto&#8217;s Bulk Associated Automation Assistant to associate many of your test methods with your MTM test cases in one go. Uses might include: automating acceptance tests or creating Keyword/Action Word Frameworks. The application can be downloaded directly from Visual Studio Gallery <a href="http://visualstudiogallery.msdn.microsoft.com/cb6d0506-5239-4085-abf3-c3f6c01e3459" target="_blank">here</a>.</p>
<p><b>Changes to v1.5<b>:</p>
<p>• All fragment generators are now freely editable T4 text files<br />
• Create new generators and customize the fragments easily (docs and samples included)<br />
• Fixed a few bugs</p>
<p>After downloading, Unblocking the file (right click -&gt; Properties), installing the VSIX and restarting Visual Studio, ensure that the Pronto window is visible:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-12-12-Stage0.png" alt="" /></div>
<p>Assuming you already have a WorkItem query in Team Explorer that returns Test Cases, just Drag and Drop that query onto the Pronto window to get a list of Test Cases:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-12-12-Stage1.png" alt="" /></div>
<p>To create your method stubs and help with documentation, either Drag &#8216;n&#8217; Drop or Right Click/Copy the Test Cases and Shared Steps and paste directly into your Unit Test:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-12-12-Stage2.png" alt="" /></div>
<p>Notice how the method stub, data binding parameters, test steps and title are all generated for you automatically (this is customizable).</p>
<p>After building your solution manually, open up the Bulk Associated Automation Assistant (the &#8220;Sheep&#8221; icon). It will discover your tests and correlate the MTM Test Case ID with the WorkItem Id on your test method:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-12-12-Stage3.png" alt="" /></div>
<p>Now you can optionally associate them all in one go without leaving VS2010.</p>
<p>This application has been tested on Visual Studio 2010 Professional (first release) and Visual Studio 2010 Ultimate (SP1, FP2, Rollups). Providing your process template integrates with MTM from a Test Automation perpsective &#8211; ie: supports &#8216;Associated Automation&#8217;, has an &#8216;Automated&#8217; automation status and contains &#8216;Shared Steps&#8217; and &#8216;Test Case&#8217; template types, in theory, depending on the alignment of the stars, the phase of the moon and the direction of the wind, Pronto should just work.</p>
<p>Enjoy!</p>
<p><a href="http://social.msdn.microsoft.com/profile/grey%20ham/?ws=usercard-mini" target="_blank">Grey Ham</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.havecomputerwillcode.com/blog/?feed=rss2&#038;p=810</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Adding &#8216;VERIFY&#8217; to MsTest (&#8216;ASSERT&#8217;-but-carry-on-if-it-fails)</title>
		<link>http://www.havecomputerwillcode.com/blog/?p=888</link>
		<comments>http://www.havecomputerwillcode.com/blog/?p=888#comments</comments>
		<pubDate>Mon, 23 Jan 2012 11:23:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ALM]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[CodedUI]]></category>
		<category><![CDATA[MsTest]]></category>
		<category><![CDATA[Test Automation]]></category>
		<category><![CDATA[VS2010]]></category>

		<guid isPermaLink="false">http://www.havecomputerwillcode.com/blog/?p=888</guid>
		<description><![CDATA[Updated source code is here (2012-Jan-28: I forgot to include the Verify Exception in the original source ) If you&#8217;ve ever used the likes of GTEST for C++ unit testing, you will be familiar with the ASSERT and VERIFY semantics: ASSERT &#8211; bail out of a test as soon as a condition is false (ie: [...]]]></description>
			<content:encoded><![CDATA[<p>Updated source code is <a href="http://www.havecomputerwillcode.com/blog/Downloads/2012-01-12-VerifyTest.cs" target="_blank">here</a> (2012-Jan-28: I forgot to include the Verify Exception in the original source <img src='http://www.havecomputerwillcode.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  )</p>
<p>If you&#8217;ve ever used the likes of GTEST for C++ unit testing, you will be familiar with the ASSERT and VERIFY semantics:</p>
<ul>
<li>ASSERT &#8211; bail out of a test as soon as a condition is false (ie: NULL Pointer)</li>
<li>VERIFY &#8211; acknowledge that a condition is false but continue with the test anyway and get as far as you can. The test still technically failed but more information was gleamed.</li>
</ul>
<p>Verify is ideal for functional / UI / UAT Automation because it lets the test get as far as it can and elicit as much information as possible before the test completes and a summary of failures are reported: it&#8217;s more useful for a developer to know that 5 numeric fields on a form are invalid instead of just one. A colleague pointed out recently that various UI Automation tools tend to implement similar semantics using &#8216;LogFail&#8217; or similar statements &#8211; however, as a developer/tester I find the &#8216;Verify&#8217; semantics more fitting but they are not part of MsTest.</p>
<p>In this rather long post, I will put Verify into MsTest by wrapping Assert.AreEqual with Verify.AreEqual (for all samples here, this is just an ordinary VS2010 Unit Test). I will provide nothing but a bare-bones implementation here (and I&#8217;ve just noticed the code prettifier I use has messed up some of the snippets on this post&#8230; please see the source code above for the complete code).</p>
<p>When you do this:</p>
<pre class="brush: c-sharp">	Assert.AreEqual(1,0)</pre>
<p>The unit test fails immediately. We want to do this:</p>
<pre class="brush: c-sharp">	Verify.AreEqual(1, 0)</pre>
<p>Where the failure is &#8216;noted&#8217; but the test continues: but when the test completes, if there were verification failures in the test, we need to throw an exception so that the unit testing framework designates the verification failures as a test failure. How to do this in MsTest? There&#8217;s a few hurdles to cross!</p>
<p><strong>Syntax</strong><br />
All Assert methods are static. Like so:</p>
<pre class="brush: c-sharp">	Assert.AreEqual(...)</pre>
<p>Assertions have no state &#8211; a failure is propagated to the test host immediately so static methods are a good fit. Verification failures on the other hand will &#8216;accumulate&#8217; so we need to preserve state. For this post I have chosen to go the &#8216;instance&#8217; route so here is a simple Verify class:</p>
<pre class="brush: c-sharp">public class Verify
{
	public Verify()
	{
		Exceptions = new List();
	}
	public void AreEqual(int left, int right)
	{
		...
	}

	public readonly List Exceptions;
}</pre>
<p>However: you can implement Verify methods using thread local storage and static methods but I am trying to keep this long post shorter!</p>
<p>The key is the implementation of the Verify methods: all an Assertion does is throw an exception when a condition is false so all we have to do is sink &amp; record that exception by wrapping it with our Verify calls:</p>
<pre class="brush: c-sharp">public class Verify
{
    ....
    public void AreEqual(int left, int right)
    {
	try
	{
		Assert.AreEqual(left, right);
	}
	catch(UnitTestAssertException ex)
	{
		Exceptions.Add(ex);
	}
    }
}</pre>
<p>If the assertion fails; we essentially &#8216;note&#8217; the failure but continue. Putting it all together, we might have a test like this:</p>
<pre class="brush: c-sharp">protected Verify Verify;

[TestInitialize]
public void Init()
{
	this.Verify = new Verify();
}

[TestMethod]
public void Pointless()
{
	Verify.AreEqual(1,2);
	Verify.AreEqual(3,3);
	Verify.AreEqual(3,4);
}</pre>
<p>NOTE: Even though Verification violations occurred, as far as the Unit Testing framework is concerned the test technically passed &#8211; no exceptions were thrown by the Unit Test! So we need to check for verification violations in the Cleanup method and then throw our own Exception if Verifications were logged during the test.</p>
<p>When executing that test, we have two Verification errors. But what to do with them? If we are running Pointless with Associated Automation within MTM, we want the test to fail; MTM has no concept of a Warning or a Partial Failure. The test either passes or fails so from MTM&#8217;s perspective unit tests should exhibit the same behavior. The Verifications are only useful for troubleshooting, logging and triage so they need to appear in the final log / TRX. If we are running the tests within Visual Studio as a Unit Test, we still need the test to fail for the same reason as above to integrate with the toolchain. How to do this? The easiest place to look for any logged verification failures is in the [TestCleanup] method. If you throw an exception in TestCleanup, the exception/failure is still associated with the Unit Test that has just run (ie: the method containing the Verify methods):</p>
<pre class="brush: c-sharp">[TestCleanup]
public void Cleanup()
{
	if(Verify.Exceptions.Count &gt; 0)
	{
		throw Verify.Exceptions.First();
	}
}</pre>
<p>The unfortunate side effect of this is that the exception/stack trace in the Test Results / TRX file looks like it came from Cleanup method and not the test itself. Clicking through takes you to the common Cleanup method which is kind of annoying:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2012-01-12-StackCleanup.png" alt="" /></div>
<p>But we can fix that.</p>
<p><strong>CHECKPOINT:</strong>We can accumulate verification failures during a unit test and throw an exception in TestCleanup if any verification failures occured. The exception we manually throw could contain a description of every verification encountered so far (for this post: I am dealing with only the first exception and I am keeping message formatting as simple as possible).</p>
<p>But what if the Unit Test contains ASSERTIONS *AND* Verifications? Like so:</p>
<pre class="brush: c-sharp">[TestMethod]
public void Pointless()
{
	Verify.AreEqual(1,2);
	Assert.AreEqual(3,3);
	Verify.AreEqual(3,4);
}</pre>
<p>I have decided that the Assertion gets &#8216;priority&#8217; &#8211; it is that exception/assertion we want to propagate &#8216;out&#8217; to the unit testing framework. We can determine if a &#8216;real&#8217; Assertion or Exception was thrown in the Unit Test by looking at the CurrentTestOutcome property:</p>
<pre class="brush: c-sharp">public TestContext TestContext { get; set; }

[TestCleanup]
public void Cleanup()
{
	if(TestContext.CurrentTestOutcome == UnitTestOutcome.Passed)
	{
                // If we only have Verify failures, as far as MsTest is concerned, the test will pass! So we need to spoof a failure...
 		if(Verify.Exceptions.Count() &gt; 0)
		{
			throw Verify.Exceptions.First();
		}
	}
}</pre>
<p>Easy! So we can comfortably mix assertions and verifications in a single functional test and it will &#8220;just work&#8221; as far as the tool chain is concerned; if a real assertion happens, that one gets propagated. In C++/GTEST, an ASSERT is used to validate a pointer (little need to go on if its NULL&#8230;!) and VERIFY is then used for individual properties. In a functional test, an ASSERT might look for a key component of a page; and the VERIFY calls for fields for example. It depends if it fits what you are trying to do. Use your judgement. This will not be suitable in all circumstances.</p>
<p><strong>Fixing the Stack</strong><br />
As stated, if we throw an exception from TestCleanup, the stack trace looks like this:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2012-01-12-StackCleanup.png" alt="" /></div>
<p>That&#8217;s not good enough! It shows the Cleanup method itself, not the actual line of code where the Verify call was made. Thanks to the .Net designers, this is easy to fix though <img src='http://www.havecomputerwillcode.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  If you examine System.Exception, you can override two key properties: Message and StackTrace (and there&#8217;s a section for each in the TRX file) Yes &#8211; as you can override the stack trace text, you can &#8216;inject&#8217; a stack trace into an exception and fool anything that interprets that exception about its source &#8211; such as the TRX viewer. And it&#8217;s easy to get the stack trace. Just do this:</p>
<pre class="brush: c-sharp">	string stack = Environment.GetStackTrace();</pre>
<p>Trivial! But we will be getting the stack trace in our Verify method&#8230; we need to &#8216;unwind&#8217; a bit. To &#8216;pop&#8217; a few lines we just do this:</p>
<pre class="brush: c-sharp">List t = new List(Environment.StackTrace.Split(delims, StringSplitOptions.None));

// 'Pop' a few lines
t.RemoveRange(0, 2);

// Reconstruct
string stack = String.Join("\r\n", t);</pre>
<p>With this, we can &#8216;inject&#8217; a stack trace into our exception. The only way I could find to do this is to create a custom exception class (gives us more flexibility&#8230;) and override its virtual StackTrace property. So it makes sense for our new exception to wrap the original exception and delegate every other call to it (where possible):</p>
<pre class="brush: c-sharp">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace HaveCompTest
{
    // Might as well derive from the unit test exception baseclasses... and you should probably use InnerException : - )
    public class MyVerifyWrapperException : UnitTestAssertException
    {
        // Pass in the original assertion exception
        public MyVerifyWrapperException(UnitTestAssertException utex, string spoofedStackTrace)
        {
            OriginalException = utex;
            SpoofedStackTrace = spoofedStackTrace;
        }

        public override System.Collections.IDictionary Data { get { return this.OriginalException.Data; }}
        public override string Message { get { return OriginalException.Message; }}
        public override string Source { get { return OriginalException.Source; }}

        public override string StackTrace { get { return SpoofedStackTrace; } }

        public readonly System.Exception OriginalException;
        public readonly string SpoofedStackTrace;
    }
}</pre>
<p>Getting there! So now when we wrap our original Assert.AreEqual call with our Verify.AreEqual call, we can create our new exception type with the StackTrace we want:</p>
<pre class="brush: c-sharp">try
{
            Assert.AreEqual(left, right);
}
catch(UnitTestAssertException ex)
{
            string[] delims = new string[] { "\r\n" };
            List t = new List(Environment.StackTrace.Split(delims, StringSplitOptions.None));
            // Choose how many lines to strip...
            t.RemoveRange(0, 3);
            string stack = String.Join("\r\n", t);

            // The stack trace now looks like it was thrown directly within the test method itself instead of here.
            MyVerifyWrapperException e = new MyVerifyWrapperException(ex, stack);
            _Exceptions.Add(e);
}</pre>
<p>KOOL! So now when we throw our verify exception in [TestCleanup] like so, in the TRX viewer we see this:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2012-01-12-StackCleanup2.png" alt="" /></div>
<p>Clicking through takes us straight to the location of the Verify failure.</p>
<p>DONE!</p>
<p><strong>Putting it all together</strong></p>
<p>The source code for a simple skeleton class can be found <a href="http://www.havecomputerwillcode.com/blog/Downloads/2012-01-12-VerifyTest.cs" target="_blank">here</a> (just add it to an ordinary MsTest Unit Test).</p>
<p><strong>Tips</strong></p>
<p>You&#8217;ll need to wrap all the Assert.XXX calls&#8230; a delegate is your friend when doing this&#8230; () =&gt; { Assert.AreEquals(&#8230;) }</p>
<p>The error message says &#8216;Assert.&#8217; in TRX. Modify the ErrorMessage in MyVerifyWrapperException to say Verify&#8230;</p>
<p>You might want a clickthrough to all Verifications in the Stack Trace view&#8230;</p>
<p>If mixed Assertion / Verification failures occur within  a test, you might still want the Verifications to show up in TRX&#8230;</p>
<p>Use Thread Local Storage to implement static Verify syntax so they are similar to Assert&#8230;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.havecomputerwillcode.com/blog/?feed=rss2&#038;p=888</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>User Account Control Automation Assistant [UacAA] released</title>
		<link>http://www.havecomputerwillcode.com/blog/?p=764</link>
		<comments>http://www.havecomputerwillcode.com/blog/?p=764#comments</comments>
		<pubDate>Sun, 06 Nov 2011 12:14:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[BrekIT]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[CodedUI]]></category>
		<category><![CDATA[Test Automation]]></category>
		<category><![CDATA[UAC]]></category>
		<category><![CDATA[UacAA]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[VS2010]]></category>

		<guid isPermaLink="false">http://www.havecomputerwillcode.com/blog/?p=764</guid>
		<description><![CDATA[I have released the first version of User Account Control Automation Assistant [UacAA] that can be downloaded here: Key features include: Programmatically automate the User Account Control [UAC] elevation and credential dialog boxes on the standard or secure desktop on Vista and Windows 7 (x64/x86) Requires no tweaking to your environment, no digital certificates, no [...]]]></description>
			<content:encoded><![CDATA[<p>I have released the first version of User Account Control Automation Assistant [UacAA] that can be downloaded <a href="http://www.brekit.com/uacaa-about" target="_blank">here</a>:<br />
<a href="http://www.brekit.com/uacaa-about" target="_blank">
<div id="centeredimage" align="center"><img src="http://www.brekit.com/templates/beez_20/images/personal/UacBanner.png" alt="Automate the dismissal of UAC from any scripting or .Net programming language" /></div>
<p></a></p>
<p>Key features include: </p>
<ul>
<li>Programmatically automate the User Account Control [UAC] elevation and credential dialog boxes on the standard or secure desktop on Vista and Windows 7 (x64/x86)</li>
<li>Requires no tweaking to your environment, no digital certificates, no modifications to your UAC settings and no application manifest modifications. Install and go!</li>
<li>Can be driven from any programming language or scripting environment &#8211; including C#, VBScript, Perl, PowerShell or (if you&#8217;re really hard) C++. Extensive samples are provided in C# and VBScript.</li>
<li>Dialogs can be automated by any user at any privelege level &#8211; ideal where elevated applications need to be launched as part of a test. </li>
</ul>
<p>UacAA might be handy for: <br/></p>
<ul>
<li>Launching elevated applications as part of your automated test suite to modify the environment between tests.</li>
<li>Integration / smoke testing where UI automation is not a primary objective but where User Account Control automation is required.</li>
<li>Testing your application behaves correctly under Uac!</li>
<li>Running your integration tests on an isolated P2V-SOE production clone without making any changes to the environment whatsoever.</li>
<li>Reducing the number of snapshots and virtual machine baselines that need to be managed.</li>
<li>Automating security-related tests that were previously manual in nature.</li>
</ul>
<p>How it works:<br/></p>
<ul>
<li>Set an expectation that a User Account Control dialog box is to be displayed and indicate what to do when it is &#8211; such as enter credentials and Confirm it.</li>
<li>Do something that requires elevation such as launching an application.</li>
<li>In the background, UacAA is monitoring for the presence of the UAC dialog &#8211; if it appears, the dialog will be automated according to your expectation so that your application can continue. </li>
<li>Optionally ask UacAA what it has just done and the kind of dialog that was displayed (elevation vs credentials) and the desktop on which it appeared (standard or secure)</li>
</ul>
<p>Known limitations:<br/></p>
<ul>
<li>This version will automate only one dialog per expectation &#8211; it is currently not possible to say &quot;enter these credentials and select Confirm whenever UAC dialogs appear from now on&quot;</li>
</ul>
<p>Microsoft <a target="_blank" href="http://social.msdn.microsoft.com/Forums/en-US/windowssecurity/thread/674b4951-1c6e-400a-838e-dc72c672a12c/">has provided a way of automating User Account Control by leveraging its UI Automation technologies</a> &#8211; but this involves UAC modifications, installation of digital certificates and an application with UIAccess rights for UI automation. This level of security is clearly required in production environments where trust (obtained via the certificate) is paramount because otherwise we would back in the days of the &#8220;shatter attack&#8221; (UAC appears on the Secure Desktop to prevent exactly that kind of attack!). <br/><br/>In test environments &#8211; where free text passwords tend to lay around with wanton abandon <img src='http://www.havecomputerwillcode.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  &#8211; you just want the <em>darn dialog to go away</em> but to otherwise retain UAC. <br/><br/>UacAA lets you do this.<br />
<br/>Where the Microsoft supported way is convenient, it should be adopted. Where it is inconvenient, or where perhaps integration testing is the objective and no infrastructure or applications are around to facilitate UI automation easily, UacAA might fit the bill. UacAA should only be used on test environments and never installed on server or systems where arbitrary content from the Internet can be executed. <br/><br/>UacAA must absolutely not be used as a hackey-wackey way of executing scripts that require elevation on desktop systems!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.havecomputerwillcode.com/blog/?feed=rss2&#038;p=764</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automating the Integration of VmWare with Microsoft Test Manager and Lab Center: Part 6 – Changes for Visual Studio 2010 Service Pack 1</title>
		<link>http://www.havecomputerwillcode.com/blog/?p=725</link>
		<comments>http://www.havecomputerwillcode.com/blog/?p=725#comments</comments>
		<pubDate>Fri, 25 Mar 2011 15:26:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ALM]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Build-Deploy-Test]]></category>
		<category><![CDATA[Lab Center]]></category>
		<category><![CDATA[Microsoft Test Manager]]></category>
		<category><![CDATA[MTM]]></category>
		<category><![CDATA[TFS]]></category>
		<category><![CDATA[TFS 2010]]></category>
		<category><![CDATA[VmWare]]></category>
		<category><![CDATA[VS 2010]]></category>

		<guid isPermaLink="false">http://www.havecomputerwillcode.com/blog/?p=725</guid>
		<description><![CDATA[PLEASE NOTE: This is for Visual Studio 2010. An updated version for Visual Studio 2011 will be available when I get around to it (consider subscribing to my blog for updates or look out for the VS11 tag on the right&#8230;) Mid-way through the series, Visual Studio Service Pack 1 was released. How amusing! So [...]]]></description>
			<content:encoded><![CDATA[<p><b>PLEASE NOTE:</b> This is for <b>Visual Studio 2010</b>. An updated version for Visual Studio 2011 will be available when I get around to it <img src='http://www.havecomputerwillcode.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  (consider subscribing to my blog for updates or look out for the VS11 tag on the right&#8230;)</p>
<p>Mid-way through the series, Visual Studio Service Pack 1 was released. How amusing! So this is an update to incorporate the Service Pack 1 changes.</p>
<p>See Part 5 for the Source Code and scripts.</p>
<p><strong>DISCLAIMER!</strong></p>
<p>Do not use this code under any circumstances (should just about cover the possibilities!).</p>
<p>I am using an undocumented API in order to construct the Physical Environment in Lab Center and set up the Test Controller Topology. I have tested the registered environments using MTM, use it often and come to no grief. My Lab Center and TFS system appears to be stable. But you use this at your own risk! At the very least, it would be sensible to do a full back up of your TFS Installation and ideally test this prior to production deployment. Use at your own risk <img src='http://www.havecomputerwillcode.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h3></h3>
<p>Parts 1, 2, 4, 5 are the same: nothing changes. The only changes you will need to make are down to the installation automation in Part 3.</p>
<p>I will not be providing an updated script to do this but if you have been following the series and want to stick to the same structure, you need to make Service Pack 1 available under the VisualStudioGumpf directory by unpacking your ISO there:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-24-ServicePack1.png" alt="" /></div>
<p>You will probably also need to create a new BAT file to launch &#8220;setup.exe /passive&#8221; from the Service Pack 1 location. Drop this into your Golden VM at the usual place:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-24-Scripts.png" alt="" /></div>
<p>And then write a new function to launch that from PowerShell.</p>
<pre class="brush: powershell">InstallServicePack1 $VmWareConnectionParameters $VmWareClonedImageLocation "$DomainName\$DomainUsername" $DomainPassword $VisualStudioGumpfUnc;</pre>
<p><strong>Troubleshooting</strong><br />
If you get problems &#8211; try it manually first! The only part where I do anything undocumented is to create the Physical Environment. If you happen to get a situation where you can do this registration process manually, but not automatically, please let me know so that I can fix it <img src='http://www.havecomputerwillcode.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><strong>Source Code Changes</strong><br />
I have no idea how many lines of white powder I had up my nose when I wrote this comment:</p>
<pre>// I am not going to check this here but only one machine in an environment can be of a given role.
Dictionary agentsToAdd = new Dictionary();
Dictionary machineRoleInfo = new Dictionary();</pre>
<p>But it is clearly wrong!</p>
<p>Apart from having to install Service Pack 1, I haven&#8217;t had to make any changes: the environment still gets created and all appears normal. You should be able to target your created environment from MTM:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-24-MTMTarget.png" alt="" /></div>
<p>And run your Unit Tests, Integration Tests and CodedUI Tests on it:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-24-CodedUI.png" alt="" /></div>
<p>Tchau!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.havecomputerwillcode.com/blog/?feed=rss2&#038;p=725</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Automating the Integration of VmWare with Microsoft Test Manager and Lab Center: Part 5 &#8211; Registering a new Physical Environment with TFS / Lab Center</title>
		<link>http://www.havecomputerwillcode.com/blog/?p=702</link>
		<comments>http://www.havecomputerwillcode.com/blog/?p=702#comments</comments>
		<pubDate>Thu, 17 Mar 2011 10:57:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ALM]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Build-Deploy-Test]]></category>
		<category><![CDATA[Lab Center]]></category>
		<category><![CDATA[Microsoft Test Manager]]></category>
		<category><![CDATA[MTM]]></category>
		<category><![CDATA[TFS]]></category>
		<category><![CDATA[TFS 2010]]></category>
		<category><![CDATA[VmWare]]></category>
		<category><![CDATA[VS 2010]]></category>

		<guid isPermaLink="false">http://www.havecomputerwillcode.com/blog/?p=702</guid>
		<description><![CDATA[PLEASE NOTE: This is for Visual Studio 2010. An updated version for Visual Studio 2011 will be available when I get around to it (consider subscribing to my blog for updates or look out for the VS11 tag on the right&#8230;) This series of posts will show you how to provision VmWare machines, install Test [...]]]></description>
			<content:encoded><![CDATA[<p><b>PLEASE NOTE:</b> This is for <b>Visual Studio 2010</b>. An updated version for Visual Studio 2011 will be available when I get around to it <img src='http://www.havecomputerwillcode.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  (consider subscribing to my blog for updates or look out for the VS11 tag on the right&#8230;)</p>
<p>This series of posts will show you how to provision VmWare machines, install Test Controllers and Test Agents, register those with TFS and construct a Physical Environment within Lab Center so that it can be targeted by Microsoft Test Manager. All automatically using PowerShell (and VmRun.EXE):</p>
<li><a href="http://www.havecomputerwillcode.com/blog/?p=593" target="_blank">Part 1 &#8211; Introduction.</a></li>
<li><a href="http://www.havecomputerwillcode.com/blog/?p=641" target="_blank">Part 2 &#8211; Provisioning a new VmWare machine using Vix and joining a domain. </a></li>
<li><a href="http://www.havecomputerwillcode.com/blog/?p=660" target="_blank">Part 3 &#8211; Automating the installation of the Test Controller and Test Agent.</a></li>
<li><a href="http://www.havecomputerwillcode.com/blog/?p=683" target="_blank">Part 4 &#8211; Automating the configuration and registration of the Test Controller and Test Agent with TFS</a>.</li>
<li><b>Part 5 &#8211; Automating the creation of a Physical Enviroment in Lab Center.</b></a>(<a href="http://www.havecomputerwillcode.com/blog/Downloads/2011-03-18-VmWare-HaveComputerWillCodeDotCom-Part5.1.zip" target="_blank">Source Code</a>) [Updated: Removed comment]</li>
<li><a href="http://www.havecomputerwillcode.com/blog/?p=725" target="_blank">Part 6 &#8211; Service Pack 1 Notes</a></li>
<p>Build-Deploy-Test with VmWare is a superset of this so I will tackle that after this series.</p>
<p>See Part 2 for Requirements (PowerShell, Vix etc.).</p>
<h3> </h3>
<p><b>DISCLAIMER!</b><br />
Do not use this code under any circumstances (should just about cover the possibilities!). </p>
<p>I am using an undocumented API in order to construct the Physical Environment in Lab Center and set up the Test Controller Topology. I have tested the registered environments using MTM, use it often and come to no grief. My Lab Center and TFS system appears to be stable. But you use this at your own risk! At the very least, it would be sensible to do a full back up of your TFS Installation and ideally test this prior to production deployment. In particular: <b><s>this has not yet been tested with Visual Studio 2010 Server Pack 1</s></b> (it has now, and it appears to work as well as pre-SP1) but use at your own risk <img src='http://www.havecomputerwillcode.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>In future, if and when Microsoft provides a way to create Phyical environments and construct Test Controller / Test Agent hierarchies programmatically, <i>this is the only stage you will have to change</i> in this series. Everything else you have done as part of this series still applies. </p>
<p><b>Background</b><br />
That aside: this is the <b>REALLY AWESOME PART!</b>! Before going on, consider provisioning a brand new virtual machine using the scripts at the end of Part 4. </p>
<p>There are no <a href="http://social.msdn.microsoft.com/Forums/is/vststest/thread/2a9b8965-6578-4fed-8ef2-66b58889ebaf" target="_blank">officially supported APIs</a> to manage the Test Controllers and Test Agents in TFS. This is unfortunate because it stops you creating Physical Environments and constructing your Test Controller / Test Agent hierarchies on the fly. You proceed at your own risk!</p>
<p>The Test Controllers and Test Agents are all written in .Net and  Microsoft has a tendency to make all of its classes &#8216;internal&#8217; so you cannot reuse them willy-nilly. I like this approach: rather than obfuscating their code they are polite enough to let us wander around their work if we need to in order to troubleshoot or find out WTF is going on. It&#8217;s a pragmatic solution between opening things up to all and sundry and having to support their firstborn for life. </p>
<p>The code we need to invoke to construct our Test Controller and Test Agent hierarchies is stored in &#8216;internal&#8217; classes so we need to find a way of instantiating those classes and invoking their methods. </p>
<p>A major help is that IL has no concept of &#8216;internal&#8217;: it is the compiler that enforces that contract opening up all kinds of creative possibilities! But that aside, you can create internal classes from other libraries just by using reflection like so:</p>
<pre class="brush: c-sharp">
System.Reflection.Assembly controllerAssembly = System.Reflection.Assembly.LoadFile(theAssemblyPath);
Type controllerTestEnvironmentType = controllerAssembly.GetType(theFullyQualifiedTypeName);

object testEnvironment = controllerTestEnvironmentType.InvokeMember("", System.Reflection.BindingFlags.CreateInstance, null, controllerTestEnvironmentType, null);
</pre>
<p>&#8230;and you can get hold of properties, invoke private and protected methods and everything else you want using nothing more than reflection. But in .Net 4.0 there is an easier way! The &#8216;dynamic&#8217; keyword will leave property and method resolution until runtime. Think of it as IDispatchEx from the COM World or expandos in JavaScript. It is very cool because <a href="http://amazedsaint.blogspot.com/2010/05/accessprivatewrapper-c-40-dynamic.html" target="_blank">by wrapping an internal type you can treat it like any other object</a>. I use the code from that link verbatim but there&#8217;s a lot of extra stuff you can do with that if you put in the time. </p>
<p>The reason I am mentioning it? Because you will see it in my code when I invoke the internal or private Test Controller classes:</p>
<pre class="brush: c-sharp">
            dynamic controllerConnectionManagerWrapper = new AccessPrivateWrapper(controllerConnectionManager);

            controllerConnectionManagerWrapper.UpdateTestEnvironment(testEnvironment);
</pre>
<p><b>Manually creating a Physical Environment using a UI</b><br />
The source code this time includes all of the scripts and some supporting Visual Studio 2010 Solutions <i>that you will have to build yourself</i>:</p>
<li>The AgentHelpers library creates physical environments in Lab Center and sets up the Test Controller / Test Agents ready for use in that environment.</li>
<li>A crude UI Application (PhysicalEnvironments) that uses the library to create physical environments in Lab Center</li>
<li>A command line application called AgentInteraction.EXE is used to set up the environments as part of the PowerShell script</li>
<p>The first thing we need to do is to make sure you can manually construct Physical Environments using my User Interface because it drives the underlying TFS libraries. If not: not much point going on!</p>
<p>Assuming you have heeded the disclaimer, you will need to add references to several standard TFS API&#8217;s including: </p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-18-References.png"></div>
<p>The interesting three are:</p>
<li>Microsoft.TeamFoundation.Lab.Activites &#8211; in C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\TeamLab\Microsoft.TeamFoundation.Lab.Activities.dll</li>
<li>Microsoft.VisualStudio.QualityTools.ControllerObject &#8211; in C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.QualityTools.ControllerObject\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.QualityTools.ControllerObject.dll</li>
<li>Microsoft.VisualStudio.QualityTools.ExecutionCommon &#8211; in C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.VisualStudio.QualityTools.ExecutionCommon.dll</li>
<p>It is important you set *ALL* of those DLL&#8217;s to &#8216;Copy local: True&#8217; for the Reference. You will need to add them to AgentInteraction and PhysicalEnvironments as well. </p>
<p>Now run the PhysicalEnvironments application and you will see a glorious &#8216;Graham UI&#8217;. I loathe arty-farty work and I loathe writing User Interfaces so much, and have consistently done such a bad job of it, that I never get asked to write them any more (mission accomplished!). Select the TFS Team Project Collection / Team Project and observe what happens:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-18-Controllers.png"></div>
<p>This UI is listing all of the Test Controllers on the left: that is the same list you see when you create a new environment in Lab Center and are asked to select the Test Controller you want to create the environment on:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-18-LabControllers.png"></div>
<p>When you select one of the Test Controllers (such as Moo1250) you will see the list of Agents available. This list is identical to what you can see in Lab Center as well:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-18-LabAgents.png"></div>
<p>So we have all of the information we need to start constructing Physical Environments. Enter a new name for the Physical Environment you want to create &#8211; such as &#8220;WooHOO&#8221; &#8211; tick the single Agent, enter a sensible Role name, and select &#8220;Create New Environment&#8221;:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-18-ManualCreate.png"></div>
<p>Your UI will now gloriously lock up for about a minute (I provide no UI Cues) whilst Lab Center does whatever it needs to do to create your environment. Assuming all went well (you&#8217;ll know when focus returns to your window) you should be able to see your environment in Lab Center:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-18-ManualSuccess.png"></div>
<p>AWESOME! So we have all the bits and pieces. </p>
<p>Before going on, delete the environment in Lab Center and then continue. </p>
<p><b>Automating the creation of a Physical Environment using PowerShell</b><br />
The PowerShell script obviously doesn&#8217;t use the User Interface but I have created a dirty, hackey-wackey Console application called &#8216;AgentInteraction.EXE&#8217; that is only moderately unforgiving of command line mistakes but can be used to drive the registration process. </p>
<p>To set this up to work, create a new subdirectory under VisualStudioGumpf called AgentInteraction and drop these DLL&#8217;s (AgentHelpers/bin/Debug), AgentInteraction.EXE and anything pulled in as part of the build into it:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-18-AgentInteraction.png"></div>
<p>Assuming you have removed the Test Controller and everything from Lab Center, you should be able to execute code like this:</p>
<pre class="brush: powershell">
# Obtain a list of all Agents known to a Test Controller
\\10.0.0.1\VisualStudioGumpf\AgentInteraction\AgentInteraction.EXE Command=ListAgents TestControllerUri="MOO1251.WOOHOO.COM:6901"

# To create an environment on the Test Controller MOO1251 and with a single Agent called MOO1251 with a Role of 'Desktop Client' you would execute:
\\10.0.0.1\VisualStudioGumpf\AgentInteraction\AgentInteraction.EXE command=RegisterEnvironment testcontrolleruri="MOO1251.WOOHOO.COM:6901" TeamProjectName="TestSample" EnvironmentName="My New Environment" Agents="MOO1251,The Web Server"
</pre>
<p>&#8230; and see your environment created in Lab Center from PowerShell:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-18-AutoSuccess.png"></div>
<p>Kool!</p>
<p><b>Automation Summary</b><br />
Assuming everything is in place, you should now be able to dynamically provision new virtual machines in VmWare, install the Test Controllers and Test Agents, register them with TFS and create a new Physical Environment on a whim. The key differences for this post are:</p>
<pre class="brush: powershell">

# ... variables from previous stages

# The Team Project Name we want to register the environment with and the environment name
$TeamProjectName = "TestSample";
$EnvironmentName = "My Brand New Environment";
$MachineRole = "Database Server";

# ...

# STAGE 5: Create the Environment
# It can take a while for the VM to spin up and the Test Controller + Test Agent to come online... so use the RETRYCOUNT here.
Invoke-Expression "$VisualStudioGumpfUnc\AgentInteraction\AgentInteraction.EXE command=RegisterEnvironment testcontrolleruri=$($MachineName).$($DomainName):6901 TeamProjectName=`"$TeamProjectName`" EnvironmentName=`"$EnvironmentName`" Agents=`"$MachineName,$MachineRole`" RetryCount=10";

Agents=`"$MachineName,$MachineRole`" ";
</pre>
<p>As a final test, set it as a targettable environment in MTM and run your Tests:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-18-MTM.png"></div>
<p>Mission Accomplished! However&#8230; there is an anomoly! When I went into the Test Controllers view and clicked a Test Controller, I noticed that duplicate Test Controller names appeared for those that were put on Virtual Machines that I had provisioned:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-18-DnsClashLab.png"></div>
<p>At first I thought it was some SID issue with the cloned virtual machine but it appears to be down to a legacy DNS Issue:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-18-DnsClash.png"></div>
<p>I was able to repeat this 100%. If you remove the legacy DNS Record (ie: for Moo1400 which is a virtual machine I purged) and restart MTM, the problem goes away (I wasn&#8217;t able to repeat it after this).</p>
<p>So I guess you need to purge the DNS Record as well as the Computer from your Active Directory when you throw away an environment. </p>
<p>L8r!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.havecomputerwillcode.com/blog/?feed=rss2&#038;p=702</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Automating the Integration of VmWare with Microsoft Test Manager and Lab Center: Part 4 – Registering the Test Controller and Test Agent with Tfs</title>
		<link>http://www.havecomputerwillcode.com/blog/?p=683</link>
		<comments>http://www.havecomputerwillcode.com/blog/?p=683#comments</comments>
		<pubDate>Tue, 15 Mar 2011 09:43:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ALM]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Build-Deploy-Test]]></category>
		<category><![CDATA[Lab Center]]></category>
		<category><![CDATA[Microsoft Test Manager]]></category>
		<category><![CDATA[MTM]]></category>
		<category><![CDATA[TFS]]></category>
		<category><![CDATA[TFS 2010]]></category>
		<category><![CDATA[VmWare]]></category>
		<category><![CDATA[VS 2010]]></category>

		<guid isPermaLink="false">http://www.havecomputerwillcode.com/blog/?p=683</guid>
		<description><![CDATA[PLEASE NOTE: This is for Visual Studio 2010. An updated version for Visual Studio 2011 will be available when I get around to it (consider subscribing to my blog for updates or look out for the VS11 tag on the right&#8230;) This series of posts will show you how to provision VmWare machines, install Test [...]]]></description>
			<content:encoded><![CDATA[<p><b>PLEASE NOTE:</b> This is for <b>Visual Studio 2010</b>. An updated version for Visual Studio 2011 will be available when I get around to it <img src='http://www.havecomputerwillcode.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  (consider subscribing to my blog for updates or look out for the VS11 tag on the right&#8230;)</p>
<p>This series of posts will show you how to provision VmWare machines, install Test Controllers and Test Agents, register those with TFS and construct a Physical Environment within Lab Center so that it can be targeted by Microsoft Test Manager. All automatically using PowerShell (and VmRun.EXE):</p>
<li><a href="http://www.havecomputerwillcode.com/blog/?p=593" target="_blank">Part 1 &#8211; Introduction</a>.</li>
<li><a a href="http://www.havecomputerwillcode.com/blog/?p=641" target="_blank">Part 2 &#8211; Provisioning a new VmWare machine using Vix and joining a domain. </a><s>(Source Code)</s> [See Part 5]</li>
<li><a a href="http://www.havecomputerwillcode.com/blog/?p=660" target="_blank">Part 3 &#8211; Automating the installation of the Test Controller and Test Agent.</a><s>(Source Code)</s> [See Part 5]</li>
<li><b>Part 4 &#8211; Automating the configuration and registration of the Test Controller and Test Agent with TFS.</b></li>
<li><a href="http://www.havecomputerwillcode.com/blog/?p=702" target="_blank">Part 5 &#8211; Automating the creation of a Physical Enviroment in Lab Center.</a> (Source Code)</li>
<li><a href="http://www.havecomputerwillcode.com/blog/?p=725" target="_blank">Part 6 &#8211; Service Pack 1 Notes</a></li>
<p>Build-Deploy-Test with VmWare is a superset of this so I will tackle that after this series.</p>
<p>See Part 2 for Requirements (PowerShell, Vix etc.).</p>
<h3> </h3>
<p>After installing the Test Controller and Test Agents and ensuring the patch level matches our baseline, we need to automate the registration of the Test Controller with TFS and automate the registration of the Test Agent with the Test Controller. </p>
<p><b>Manually registering the Test Controller</b><br />
Before going on I will assume you have created a new Virtual Machine by running the scripts created in Stage 2 and installed the Test Controller and Test Agent in Stage 3. We will use that as a baseline. Use the snapshot and restore functionality of VmWare liberally here &#8211; that&#8217;s what it is for!</p>
<p><i>Checkpoint 1 &#8211; Machine with Test Controller and Test Agent installed but not configured</i><br />
There <a href="http://msdn.microsoft.com/en-us/library/ff458709.aspx" target="_blank">are</a> a lot of <a href="http://msdn.microsoft.com/en-us/library/ms243155.aspx" target="_blank">possiblities</a> and topologies when setting up environments, test controllers and test agents. For this series I am creating a single VmWare machine that will contain both the Test Controller *AND* the Test Agent. </p>
<p>If you&#8217;ve set up a Test Controller before you will be familiar with this user interface. Launch it from within your Virtual Machine:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-17-TestControllerUI.png"></div>
<p>There are so many moving parts and opportunities for failure so large that the best way to identify issues with the script is to do everything manually first. So&#8230; </p>
<p>Enter the parameters and make sure the configuration works if you do it manually:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-17-TestControllerSuccess.png"></div>
<p>If the operation was successful you will be able to see the Test Controller in Lab Center:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-17-TestControllerLabCenter.png"></div>
<p>If you cannot see the controller in Lab Center at this point, you need to work out why. There is little point going on. The first thing to do is to disable the Firewall on your provisioned virtual machine or add an exception for the Test Controller application to see if that helps: this is usually the problem (my batch file in the source code package adds an exception using netsh). Otherwise, the possibilities are too many to mention here. Whatever changes you make you will either need to put into the PowerShell script or backpatch into your baseline VmWare image and re-provision. </p>
<p>The User Interface Application used to configure the Test Controller above is called &#8216;TestControllerConfigUI.EXE&#8217;. If you hunt around on your virtual machine disk you will find one called &#8216;TestControllerConfig.EXE&#8217; that lives in the same directory. &#8216;TestControllerConfig.EXE&#8217; is what we use to automate setting those parameters. </p>
<p>Now revert to <i>Checkpoint 1</i> in the VM. To Undo (unregister) the Test Controller from Lab Center, do this first within your Virtual Machine. </p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-17-TestControllerUnregister.png"></div>
<p>We will now automate the Test Controller registration using the command line tool:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-17-TestControllerAutoRegister.png"></div>
<p>I have no idea what can take so long: but it does. </p>
<p>Assuming that works you can confirm the Test Controller has registered itself with TFS by reopening Lab Center and seeing your Test Controller in all its glory:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-17-TestControllerLabCenter.png"></div>
<p>GOOD! We now have everything in place to register the Test Controller with Lab Center. If you needed to make any changes to your virtual machine to get this working (such as modifying the Firewall settings) you either need to make that part of your Virtual Machine baseline or you need modify the scripts I have written to create Firewall exceptions on the fly. </p>
<p>Finally, to ensure this is going to work from VMRUN.EXE, execute this (after copying across the Guest/Script batch files from the attached source code into the Virtual Machine C:\Scripts directory as usual):</p>
<p>VmWare Server:</p>
<pre class="brush: powershell">
vmrun.exe -T server -h https://localhost:8333/sdk -u Administrator -p whatever -gu WOOHOO\Administrator -gp whatever runProgramInGuest "[VmWareImages] Golden XP Pro Service Pack 3/Golden XP Pro Service Pack 3.vmx" "C:\Windows\System32\CMD.EXE" /C C:\scripts\ConfigureTestController.BAT http://WIN-TSKURFCLU7G.WOOHOO.COM:8080/Tfs/DefaultCollection WOOHOO.COM\TfsTest whatever SomeOtherText
</pre>
<p>VmWare Workstation:</p>
<pre class="brush: powershell">
vmrun.exe -T ws -gu WOOHOO\Administrator -gp whatever runProgramInGuest "[VmWareImages] Golden XP Pro Service Pack 3/Golden XP Pro Service Pack 3.vmx" "C:\Windows\System32\CMD.EXE" /C C:\scripts\ConfigureTestController.BAT http://WIN-TSKURFCLU7G.WOOHOO.COM:8080/Tfs/DefaultCollection WOOHOO.COM\TfsTest whatever SomeOtherText
</pre>
<p>Note the addition of &#8216;SomeOtherText&#8217; to the end. For some inexplicable reason, one less parameter than usual was being passed through to the Batch file from VMRUN.EXE. I have no idea why, but adding another one to the end fixed it. Bizarre!</p>
<p><b>Manually registering the Test Agent</b><br />
<i>Checkpoint 2 &#8211; Test Controller Installed and Registered with Lab Center. Test Agent Installed but not Registered with Test Controller.</i><br />
Now we just need to do the same thing for the Test Agent. We know the Test Controller works so we just need to register our Test Agent with it so we can add that Agent to new environments in Lab Center. Open up the Test Agent Configuration Tool and set up the parameters you want. I am going to run this as an interactive process (not a service) so I&#8217;ll point out the difference later when we automate it:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-17-AgentManual.png"></div>
<p>Notice we are using &#8216;localhost&#8217; to talk to the Test Controller we installed earlier on the same machine. If you are provisioning multiple machines here, you obviously point it to where your Test Controller is installed <img src='http://www.havecomputerwillcode.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Once again, do that manually to check it works and troubleshoot any issues. To check that we are getting visibility over our Test Controllers and Agents we can now go into Lab Center, select Controllers and observe that our Test Agent is present: </p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-17-AgentInLabCenter.png"></div>
<p>If you can&#8217;t see your Test Agent you have to troubleshoot why before you proceed. </p>
<p>Once this works, revert to <i>Checkpoint 2</i>. To automate the Test Agent configuration from the command line, there is a tool called &#8216;TestAgentConfig.EXE&#8217; that does it for us within your VM:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-17-AgentManualRegistration.png"></div>
<p>In the above case, I was running the Test Configuration utility as WOOHOO.COM\Administrator but want the Test Agent to run as Graham (Administrator account on the Virtual Machine). So I need to reboot (and you will see that in my scripts). </p>
<p>When I restarted the Virtual Machine, I was told that QTAgentService.EXE was still blocked by my firewall: so I need to add an explicit exception for that to the Windows Firewall and you will find that call in the ConfigureTestAgent.BAT file which looks like this:</p>
<pre>
REM Add a Firewall Exception for our Agent Service executable.
netsh firewall add allowedprogram program="C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\QTAgentService.EXE" name="QTAgentService.EXE" mode=ENABLE scope=ALL profile=ALL
</pre>
<p>For now, Unblock the application using the Firewall Alert (if you are asked) manually so that you can continue. When you run the ConfigureTestAgent.BAT batch file using VmRun.Exe, the exception will be added. </p>
<p>The parameters map one-to-one with what is in the UI. Once your Agent User Interface comes up, you should be able to see your Controller and Agent in Lab Center again:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-17-AgentInLabCenter.png"></div>
<p>FINALLY! Revert to <i>Checkpoint 2</i> again. To &#8216;Undo&#8217; (Unregister the Test Agent with the Test Controller) just do this from a Command Prompt in your Virtual Machine:</p>
<pre>
C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\TestAgentConfig.EXE Delete
</pre>
<p>Now we can see that this is going to work using our VmRun.EXE call with our Batch File:</p>
<p>VmWare Server:</p>
<pre class="brush: powershell">
vmrun.exe -T server -h https://localhost:8333/sdk -u Administrator -p whatever -gu WOOHOO\Administrator -gp whatever runProgramInGuest "[VmWareImages] Golden XP Pro Service Pack 3/Golden XP Pro Service Pack 3.vmx" "C:\Windows\System32\CMD.EXE" /C C:\scripts\ConfigureTestAgent.BAT Graham moo localhost:6901 SomeExtraStuffSoTheParameterGetsSentThrough
</pre>
<p>VmWare Workstation:</p>
<pre class="brush: powershell">
vmrun.exe -T ws gu WOOHOO\Administrator -gp whatever runProgramInGuest "[VmWareImages] Golden XP Pro Service Pack 3/Golden XP Pro Service Pack 3.vmx" "C:\Windows\System32\CMD.EXE" /C C:\scripts\ConfigureTestAgent.BAT Graham moo localhost:6901 SomeExtraStuffSoTheParameterGetsSentThrough
</pre>
<p>After that, check once again you can see your Controller and Agent in TFS:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-17-AgentInLabCenter.png"></div>
<p>Awesome! So that&#8217;s all the moving parts tamed. </p>
<p><b>Automation Summary</b><br />
Unpack the Source Code for Part 4. With the source code, you should be able to provision a new virtual machine from VmWare; install the Test Controller and Test Agent; and register them with TFS automatically. </p>
<p>This snippet shows the key changes to the VmWareTfsIntegration.ps1 script for this stage:</p>
<pre class="brush: powershell">

# ...

# Test Controller Configuration Parameters
$TestControllerTfsTeamProjectCollection = "http://WINTSKURF-CLU7G.WOOHOO.COM:8080/Tfs/DefaultCollection";
$TestControllerTfsServiceUser = "WOOHOO.COM\TfsTest";
$TestControllerTfsServicePassword = "whatever";

# Test Agent Configuration Parameters
# I want to log in the user automatically so I can do UI Testing: these are the credentials under which the Test will be run.
$TestProcessUsername = "Graham";
$TestProcessPassword = "moo";
# The Test Agent needs to know what Test Controller to connect to. As we only have one machine, use localhost.
$TestControllerUri = "localhost:6901";

# ... Provision and Install Test Controller + Test Agent

# STAGE 4: Configure Test Controller + Test Agent
ConfigureTestController $VmWareConnectionParameters $VmWareClonedImageLocation "$DomainName\$DomainUsername" $DomainPassword $TestControllerTfsTeamProjectCollection $TestControllerTfsServiceUser $TestControllerTfsServicePassword
ConfigureTestAgent $VmWareConnectionParameters $VmWareClonedImageLocation "$DomainName\$DomainUsername" $DomainPassword $TestProcessUsername $TestProcessPassword $TestControllerUri
</pre>
<p>Before going on I recommend constructing a Physical Environment using that Controller and Agent and targetting it via MTM in a simple test. If you can do this, you know the system works end-to-end and it will make Stage 5 much easier <img src='http://www.havecomputerwillcode.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Only one more step! And that is to automate the creation of a Physical Environment in TFS so we can run our tests against them using MTM. </p>
<p>L8r!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.havecomputerwillcode.com/blog/?feed=rss2&#038;p=683</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Automating the Integration of VmWare with Microsoft Test Manager and Lab Center: Part 3 – Installing the Test Controller and Test Agent (and Patches)</title>
		<link>http://www.havecomputerwillcode.com/blog/?p=660</link>
		<comments>http://www.havecomputerwillcode.com/blog/?p=660#comments</comments>
		<pubDate>Sun, 13 Mar 2011 14:36:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ALM]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Build-Deploy-Test]]></category>
		<category><![CDATA[Lab Center]]></category>
		<category><![CDATA[Microsoft Test Manager]]></category>
		<category><![CDATA[MTM]]></category>
		<category><![CDATA[TFS]]></category>
		<category><![CDATA[TFS 2010]]></category>
		<category><![CDATA[VmWare]]></category>
		<category><![CDATA[VS 2010]]></category>

		<guid isPermaLink="false">http://www.havecomputerwillcode.com/blog/?p=660</guid>
		<description><![CDATA[PLEASE NOTE: This is for Visual Studio 2010. An updated version for Visual Studio 2011 will be available when I get around to it (consider subscribing to my blog for updates or look out for the VS11 tag on the right&#8230;) This series of posts will show you how to provision VmWare machines, install Test [...]]]></description>
			<content:encoded><![CDATA[<p><b>PLEASE NOTE:</b> This is for <b>Visual Studio 2010</b>. An updated version for Visual Studio 2011 will be available when I get around to it <img src='http://www.havecomputerwillcode.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  (consider subscribing to my blog for updates or look out for the VS11 tag on the right&#8230;)</p>
<p>This series of posts will show you how to provision VmWare machines, install Test Controllers and Test Agents, register those with TFS and construct a Physical Environment within Lab Center so that it can be targeted by Microsoft Test Manager. All automatically using PowerShell (and VmRun.EXE):</p>
<li><a href="http://www.havecomputerwillcode.com/blog/?p=593" target="_blank">Part 1 &#8211; Introduction</a>.</li>
<li><a a href="http://www.havecomputerwillcode.com/blog/?p=641" target="_blank">Part 2 &#8211; Provisioning a new VmWare machine using Vix and joining a domain. </a><s>(Source Code)</s> [See Part 5]</li>
<li><b>Part 3 &#8211; Automating the installation of the Test Controller and Test Agent.</b> (<s>Source Code</s>) [See Part 5] </li>
<li><a href="http://www.havecomputerwillcode.com/blog/?p=683" target="_blank">Part 4 &#8211; Automating the configuration and registration of the Test Controller and Test Agent with TFS</a></li>
<li><a href="http://www.havecomputerwillcode.com/blog/?p=702" target="_blank">Part 5 &#8211; Automating the creation of a Physical Enviroment in Lab Center.</a>(Source Code)</li>
<li><a href="http://www.havecomputerwillcode.com/blog/?p=725" target="_blank">Part 6 &#8211; Service Pack 1 Notes</a></li>
<p>
Build-Deploy-Test with VmWare is a superset of this so I will tackle that after this series.</p>
<p>See Part 2 for Requirements (PowerShell, Vix etc.).<br />
</p>
<h3> </h3>
<p>Like Part 2, this does not really belong in this series but has been provided for completeness. What we need to do is to automatically install the Test Controller and the Test Agents and any patches onto our virtual machines so we are ready to register that testing infrastructure with TFS. </p>
<p><b>Manually installing the Test Controller and Test Agent</b><br />
The first thing we need to do is to make the Test Controller installation software available SOMEWHERE on the network accessible from your brand new provisioned Virtual Machine in Stage 2. Vix will be used to install the software in the virtual machine so the user we log on to the Virtual Machine as must have access to that network location. </p>
<p>My personal network at home is called WOOHOO.COM (don&#8217;t ask) and I have a share called VisualStudioGumpf whose directory structure looks like this:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-14-VmWareShareAgentsIso.png"></div>
<p>Because I am not a System Administrator, it is open to EVERYONE as Read and ADMINISTRATORS as Read/Write.</p>
<p>If you lock down the permissions of that share remember that a lot of the work will be done from within the security context of a user in the virtual machine. Whatever user you log into the virtual machine as during this stage must have READ access to that directory. </p>
<p>That directory structure is an unpacked version of the &#8216;X16-49583VS2010Agents1.iso&#8217; Agents ISO from MSDN. My scripts assume that directory structure. I have an additional complication in that my Test Controllers and Test Agents have since been updated with a Knowledge Base patch that I need to run as well (VS10-KB983578-x86.exe or VS10-KB983578-x64.exe) which reside in the Patches directory:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-14-VmWareSharePatchesIso.png"></div>
<p>My scripts are written on the assumption those patches are there: customize the scripts and install whatever is needed to establish your TFS, Test Controller and Test Agent patch level. Either way, in this case, you only need to install the KB Patch once so do it after you have installed the Test Controller and the Test Agent. </p>
<p>The first thing we need to do is to create a Response File for our Test Controller and Test Agents so we can automate their installation. Log onto your newly provisioned VIRTUAL MACHINE as the user you intend to run the installation process as: for now I recommend the Domain Administrator or some other super user to remove security complications [as you can tell I am not a Sysadmin!]. Open up a command prompt and execute the Test Controller installer directly but specify the CreateUnattend File switch for the TestController and TestAgent. This will create a Response File we can later use to automate their installation:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-14-CreateResponseFile.png"></div>
<p>Go through the Wizard as you normally would and select &#8216;SaveSettings&#8217; at the end. When setting up the Response File for the Test Agent, do not select the Performance Tools for now &#8211; do that later if you need to support that.</p>
<p>Now we have a Response File for the Test Controller and Test Agent installation on the network share:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-14-ResponseFiles.png"></div>
<p>KOOL! Now we have all the bits sorted out and we just need to automate the installation of the Test Controllers and Test Agents using those Response Files. We can do this using Vix and running the executables directly from within the context of a user logged into the virtual machine. Before continuing, add the files from the Guest\Scripts directory in the attached Zip to the C:\Scripts directory in your Golden Image: (<b>if you used the ones from Part 2, replace them: I have made a few modifications</b>):</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-14-ScriptLayout.png"></div>
<p>All of the InstallXXX batch files access one parameter &#8211; the UNC of the VisualStudioGumpf directory (ie: \\10.0.0.1\VisualStudioGumpf). From there, they can locate the rest of the things they need and they all pretty much look like this:</p>
<pre>
REM www.havecomputerwillcode.com
REM %1 - The UNC of the VisualStudioGumpf directory. ie: \\10.0.0.1\VisualStudioGumpf

SET SEE_MASK_NOZONECHECKS=1
CMD.EXE /C %1\Agents\TestController\setup.exe /UnattendFile %1\ResponseFiles\TestController.INI
</pre>
<p>To make sure everything works, you can run the Test Controller Installer manually:</p>
<p>VmWare Server:</p>
<pre class="brush: powershell">
vmrun.exe -T server -h https://localhost:8333/sdk -u Administrator -p whatever  -gu WOOHOO\Administrator -gp whatever runProgramInGuest "[VmWareImages] Golden XP Pro Service Pack 3/Golden XP Pro Service Pack 3.vmx" "C:\Windows\System32\CMD.EXE" /C C:\scripts\InstallTestController.BAT \\10.0.0.1\VisualStudioGumpf
</pre>
<p>VmWare Workstation:</p>
<pre class="brush: powershell">
vmrun.exe -T ws -gu WOOHOO\Administrator -gp whatever runProgramInGuest "[VmWareImages] Golden XP Pro Service Pack 3/Golden XP Pro Service Pack 3.vmx" "C:\Windows\System32\CMD.EXE" /C C:\scripts\InstallTestController.BAT \\10.0.0.1\VisualStudioGumpf
</pre>
<p>It seemed to take forever to execute the installation because of all the pre-requisites. To fix this, have a look at the Application Event Log on your Virtual Machine and double click each MsiInstaller reference:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-14-EventLog.png"></div>
<p>To speed up this process, install as many of the pre-requisites as possible on your Golden Image. You will find the pre-requisite installation packages in the WCU sub-directory of the TestController and TestAgent.</p>
<p>Regardless, you can then do the same with the Test Agent:</p>
<p>VmWare Server:</p>
<pre class="brush: powershell">
vmrun.exe -T server -h https://localhost:8333/sdk -u Administrator -p whatever  -gu WOOHOO\Administrator -gp whatever runProgramInGuest "[VmWareImages] Golden XP Pro Service Pack 3/Golden XP Pro Service Pack 3.vmx" "C:\Windows\System32\CMD.EXE" /C C:\scripts\InstallTestAgent.BAT \\10.0.0.1\VisualStudioGumpf
</pre>
<p>VmWare Workstation:</p>
<pre class="brush: powershell">
vmrun.exe -T ws -gu WOOHOO\Administrator -gp whatever runProgramInGuest "[VmWareImages] Golden XP Pro Service Pack 3/Golden XP Pro Service Pack 3.vmx" "C:\Windows\System32\CMD.EXE" /C C:\scripts\InstallTestAgent.BAT \\10.0.0.1\VisualStudioGumpf
</pre>
<p>&#8230; and then finally the patches (if necessary). The .BAT file installs the 32-bit version so change it if you have a 64-bit VM:</p>
<p>VmWare Server:</p>
<pre class="brush: powershell">
vmrun.exe -T server -h https://localhost:8333/sdk -u Administrator -p whatever  -gu WOOHOO\Administrator -gp whatever runProgramInGuest "[VmWareImages] Golden XP Pro Service Pack 3/Golden XP Pro Service Pack 3.vmx" "C:\Windows\System32\CMD.EXE" /C C:\scripts\InstallTestPatches.BAT \\10.0.0.1\VisualStudioGumpf
</pre>
<p>VmWare Workstation:</p>
<pre class="brush: powershell">
vmrun.exe -T ws -gu WOOHOO\Administrator -gp whatever runProgramInGuest "[VmWareImages] Golden XP Pro Service Pack 3/Golden XP Pro Service Pack 3.vmx" "C:\Windows\System32\CMD.EXE" /C C:\scripts\InstallTestPatches.BAT \\10.0.0.1\VisualStudioGumpf
</pre>
<p>You can validate that everything is working hunkey-dorey by looking at Programs on your Virtual Machine:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-14-Programs.png"></div>
<p>KOOL!</p>
<p><b>Automation Summary</b><br />
Unpack the Part 3 Source Code above and you should now have enough information to automate the provisioning of a new virtual machine and the installation of the Test Controllers and Test Agents. The key differences in the script are:</p>
<pre class="brush: powershell">

# ... The VmWare and Domain Parameters from Part 2

# The share location on the domain network which contains an 'Agents', 'ResponseFiles' and 'Patches' directory.
$VisualStudioGumpfUnc = "\\10.0.0.1\VisualStudioGumpf";

# ... The provisioning code from Part 2

InstallTestController $VmWareConnectionParameters $VmWareClonedImageLocation "$DomainName\$DomainUsername" $DomainPassword $VisualStudioGumpfUnc;
InstallTestAgent $VmWareConnectionParameters $VmWareClonedImageLocation "$DomainName\$DomainUsername" $DomainPassword $VisualStudioGumpfUnc;
# If you want to install the KB Patch, run this <img src='http://www.havecomputerwillcode.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  Check that the InstallTestPatches.BAT file is installing the correct Platform for your Virtual Machine (32-bit vs 64-bit)
InstallTestPatches $VmWareConnectionParameters $VmWareClonedImageLocation "$DomainName\$DomainUsername" $DomainPassword $VisualStudioGumpfUnc;
</pre>
<p>Now all the grunt work has been done we can actually start integrating this with TFS and Lab Center&#8230;</p>
<p>L8r!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.havecomputerwillcode.com/blog/?feed=rss2&#038;p=660</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Automating the Integration of VmWare with Microsoft Test Manager and Lab Center: Part 2 – Provisioning a new Virtual Machine</title>
		<link>http://www.havecomputerwillcode.com/blog/?p=641</link>
		<comments>http://www.havecomputerwillcode.com/blog/?p=641#comments</comments>
		<pubDate>Sat, 12 Mar 2011 08:01:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ALM]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Build-Deploy-Test]]></category>
		<category><![CDATA[Lab Center]]></category>
		<category><![CDATA[Microsoft Test Manager]]></category>
		<category><![CDATA[MTM]]></category>
		<category><![CDATA[TFS]]></category>
		<category><![CDATA[TFS 2010]]></category>
		<category><![CDATA[VmWare]]></category>
		<category><![CDATA[VS 2010]]></category>

		<guid isPermaLink="false">http://www.havecomputerwillcode.com/blog/?p=641</guid>
		<description><![CDATA[PLEASE NOTE: This is for Visual Studio 2010. An updated version for Visual Studio 2011 will be available when I get around to it (consider subscribing to my blog for updates or look out for the VS11 tag on the right&#8230;) This series of posts will show you how to provision VmWare machines, install Test [...]]]></description>
			<content:encoded><![CDATA[<p><b>PLEASE NOTE:</b> This is for <b>Visual Studio 2010</b>. An updated version for Visual Studio 2011 will be available when I get around to it <img src='http://www.havecomputerwillcode.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  (consider subscribing to my blog for updates or look out for the VS11 tag on the right&#8230;)</p>
<p>This series of posts will show you how to provision VmWare machines, install Test Controllers and Test Agents, register those with TFS and construct a Physical Environment within Lab Center so that it can be targeted by Microsoft Test Manager. All automatically using PowerShell (and VmRun.EXE):</p>
<li><a href="http://www.havecomputerwillcode.com/blog/?p=593" target="_blank">Part 1 &#8211; Introduction</a>.</li>
<li><b>Part 2 &#8211; Provisioning a new VmWare machine using Vix and joining a domain.</b>(<s>Source Code</s>) [See Part 5]</</li>
<li><a href="http://www.havecomputerwillcode.com/blog/?p=660" target="_blank">Part 3 &#8211; Automating the installation of the Test Controller and Test Agent.</a></li>
<li><a href="http://www.havecomputerwillcode.com/blog/?p=683" target="_blank">Part 4 &#8211; Automating the configuration and registration of the Test Controller and Test Agent with TFS</a>.</li>
<li><a href="http://www.havecomputerwillcode.com/blog/?p=702" target="_blank">Part 5 &#8211; Automating the creation of a Physical Enviroment in Lab Center.</a> (Source Code)</li>
<li><a href="http://www.havecomputerwillcode.com/blog/?p=725" target="_blank">Part 6 &#8211; Service Pack 1 Notes</a></li>
<p>
Build-Deploy-Test with VmWare is a superset of this so I will tackle that after this series.<br />
<br />
<b>Requirements</b><br />
To do this you will need:<br />
</p>
<li>PowerShell v2.0+</li>
<li>VmWare <img src='http://www.havecomputerwillcode.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  (The scripts are written for Workstation / Server using VMRUN.EXE/Vix so you WILL need to customize the scripts if you use PowerCLI)</li>
<li><a href="http://www.vmware.com/support/developer/vix-api/" target="_blank">VIX 1.10+ [Add VmRun.EXE to your PATH]</a></li>
<p>This series has generated a lot of interest so I would like to clarify what I am doing: I am putting together a PowerShell script, piece by piece, that will provision a new, single VmWare machine (replace with virtualization platform of choice), install and configure all of the necessary Test components from the ground up and then register that machine as a physical environment in TFS/Lab Center so it can be targeted using MTM. Despite all the moving parts, this is the bare minimum you need to be able to do to automate the integration of VmWare with TFS/Lab Center/MTM. After that, I will move onto Build-Deploy-Test and then finally customizing the Build Workflows and UI&#8217;s explicitly for VmWare. Given the complexity of this, my assumption is that you will follow this through stage by stage and customize the scripts for your Enterprise. </p>
<p>To John, Brian and the half a dozen others who contacted me about these posts: I will reply shortly. I work as Performance Tester during the day and it has been <i>quite a fortnight&#8230;</i>!</p>
<p>I have decided as part of these scripts to provision a machine and join it to my domain because this is the easiest approach from an Administration point of view. At a later date, I will update this to work with Workgroups too (when I deal with Fencing). One thing I have learned about Lab Center and TFS is that it touches every part of your infrastructure &#8211; DNS, IPSec, DHCP, Hyper-V, SCVMM, TFS and all of its moving parts such as Test Controllers and Test Agents. So each of these posts will be split up into a &#8216;Manual&#8217; and an &#8216;Automated&#8217; section. The Manual section will guide you through what the script is going to do step-by-step with the expectation that you follow it through manually in your Enterprise. There are so many moving parts it is guaranteed you will need to understand what the scripts are doing and you will have to modify them for your Enterprise. </p>
<p>Over to provisioning!<br />
</p>
<h3> </h3>
<p><b>Manually provisioning a new Virtual Machine from VmWare using PowerShell</b><br />
It goes without saying that the first thing we need to do is to get hold of a new virtual machine. This is by far the hardest part because there are so many possibilities depending on what VmWare installation you have and this stage is included only so we have something that works end to end: for this part, you will have to do most of the heavy lifting yourself even though I have provided a script that kind of works with VmWare server and should work with VmWare Workstation (let me know if it does!). Before continuing, I will assume you have a baseline Virtual Machine image already &#8211; a &#8216;Golden Image&#8217; &#8211; that is configured in VmWare. This is just an ordinary Virtual Machine that you want to make a lot of duplicates of:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-13-VmWareImage.png"></div>
<p>To simplify the script and any issues that might come up, consider doing the following with your Golden Image:</p>
<li>Turn off Automatic Updates.</li>
<li>If you are using the Windows 7 or Vista, disable UAC before continuing and turn off all of the other Security Helpers before you start. If you want to use UAC, consider re-enabling it when everything has been installed. In particularly, you might need to turn off the Security Settings that stop you running files from the Network&#8230;</li>
<li>I am using a Windows XP SP3 Image to test these scripts because it does not get in the way</li>
<li>Disable any annoying utilities that pop up during startup.</li>
<li>Install Vm Tools.</li>
<li>It obtains its IP Address using DHCP. </li>
<li>It is a member of a Workgroup (not a Domain). </li>
<li>That it can be started and used just like any other virtual machine. </li>
<li>VmWare Server Only: You have powered *down* your Golden VM and taken a Snapshot. This is due to Cloning limitations in the API.</li>
<li><b>Copy the Guest\Scripts directory from the attached source code into C:\Scripts on your Golden Image. </b></li>
<p>All we are going to do is to make lots of identical copies of that machine (ideally use Sysprep but there&#8217;s too many possibilities to discuss here). Every Enterprise has a way of provisioning Virtual Machines dynamically so this is none-issue and I am only including it here for completeness.</p>
<p>And this is where the fun starts! You see, if you are using VmWare Workstation, you can use the &#8216;VMRUN.EXE Clone&#8217; command to clone a virtual machine. If you are using VmWare Server, you cannot use the VMRUN.EXE Clone command because its not supported. </p>
<p>Annoying. </p>
<p>It is for this reason I am going to fudge this post. Rather than go through all the possibilities, I am going to leave the provisioning step up to you: it is the only part of the process that differs depending on whether you are using VmWare Workstation, VmWare Server, ESX, PowerCLI, Virtual PC or Virtual Box and you will know how to make this cloning happen using whatever virtualization platform you are using. By the end of this post, you just need to have a Virtual Machine that has been joined to a domain.  </p>
<p>My script supports VmWare Workstation and (with a fudge) VmWare Server so I will go through the steps for those. But first a few things:</p>
<p>VmWare Workstation supports full machine cloning and that is included in the script. Unfortunately, I do not have VmWare Workstation to test it so let me know if it works <img src='http://www.havecomputerwillcode.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>VmWare server does not support Cloning via Vix. But it does allow a single Snapshot for each virtual machine so I treat that single snapshot as the &#8216;Clone&#8217; (ie: every time I run the script I will revert to it). This is just so I can run the script repeatedly and there <i>are</i> hackey ways to clone a Virtual Machine in VmWare Server (hunt around) but I won&#8217;t elaborate here: do whatever you need to do to clone a VmServer image if you want to use that as part of your Enterprise but I won&#8217;t inlude the logic in the script (replace the revertToSnapshot call with your Cloning Logic). To set up the snapshot baseline for VmWare Server, power down your Golden Image and take the one and only snapshot you are allowed. </p>
<p>Any operations performed on VmWare from VmRun.Exe require a &#8216;Virtual Machine VMX Location&#8217;. So the first thing to do is to get this identity for the virtual machines. VmRun.Exe (part of the Vix installation) can be used for this:</p>
<p>VmWare Server:</p>
<pre class="brush: powershell">
vmrun -h https://localhost:8333/sdk -T server -u "Administrator" -p "whatever" listRegisteredVM
</pre>
<p>VmWare Workstation:</p>
<pre class="brush: powershell">

vmrun -T ws listRegisteredVM
</pre>
<p>The output of that will be something like this:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-13-VmWareRegistered.png"></div>
<p>Once you know the original image name, you can clone it by doing this:</p>
<p>VmWare Workstation:</p>
<pre class="brush: powershell">
vmrun.exe -T ws  clone "[VmWareImages] Golden XP Pro Service Pack 3/Golden XP Pro Service Pack 3.vmx" "[VmWareImages] Your New VM Machine Name/Golden XP Pro Service Pack 3.vmx" full
</pre>
<p>VmWare Server:</p>
<pre class="brush: powershell">
# We cannot Clone on VmWare Server so we just revert to a baseline so I don't need to provide all the script stuff to do the duplication in other ways
vmrun.exe -T server -h https://localhost:8333/sdk -u Administrator -p whatever revertToSnapshot "[VmWareImages] Golden XP Pro Service Pack 3/Golden XP Pro Service Pack 3.vmx" "PassInAnyNameHere"
</pre>
<p>Once that has been done, we just need to start up the machine:</p>
<p>VmWare Workstation:</p>
<pre class="brush: powershell">
vmrun.exe -T ws start "[VmWareImages] Your New VM Machine Name/Golden XP Pro Service Pack 3.vmx"
</pre>
<p>VmWare Server:</p>
<pre class="brush: powershell">
# Note: With VmWare Server we start the ORIGINAL machine name because the API does not support Cloning.
vmrun.exe -T server -h https://localhost:8333/sdk -u Administrator -p whatever  start "[VmWareImages] Golden XP Pro Service Pack 3/Golden XP Pro Service Pack 3.vmx"
</pre>
<p>There are a few ways to rename the machine and join it to our domain. NETDOM.EXE is part of the resource kit and is one solution. But WMI is an alternative and it requires no resource kit so I will use that. <a href="http://www.tek-tips.com/viewthread.cfm?qid=1240726" target="_blank">This </a> is the post I have based the Rename Machine and Join Domain logic on. </p>
<p>The easiest way to rename your cloned machine and join a domain for this series is to ensure the Configuration scripts are already inside your Golden Virtual Machine image at C:\Scripts like this:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-13-ScriptLayout.png"></div>
<p>We can then rename our machine like this:</p>
<p>VmWare Server:</p>
<pre class="brush: powershell">
vmrun.exe -T server -h https://localhost:8333/sdk -u Administrator -p whatever  -gu Graham -gp moo runProgramInGuest "[VmWareImages] Golden XP Pro Service Pack 3/Golden XP Pro Service Pack 3.vmx" "C:\Windows\System32\CMD.EXE" /C C:\scripts\RenameMachine.BAT Moo222
</pre>
<p>VmWare Workstation:</p>
<pre class="brush: powershell">
vmrun.exe -T ws -gu Graham -gp moo runProgramInGuest "[VmWareImages] Golden XP Pro Service Pack 3/Golden XP Pro Service Pack 3.vmx" "C:\Windows\System32\CMD.EXE" /C C:\scripts\RenameMachine.BAT Moo222
</pre>
<p>&#8230;and then we can join it to our Domain:</p>
<p>VmWare Server:</p>
<pre class="brush: powershell">
vmrun.exe -T server -h https://localhost:8333/sdk -u Administrator -p whatever -gu Graham -gp moo runProgramInGuest "[VmWareImages] Golden XP Pro Service Pack 3/Golden XP Pro Service Pack 3.vmx" "C:\Windows\System32\CMD.EXE" /C C:\scripts\JoinDomain.BAT Administrator whatever WOOHOO.COM
</pre>
<p>VmWare Workstation:</p>
<pre class="brush: powershell">
vmrun.exe -T ws -gu Graham -gp moo runProgramInGuest "[VmWareImages] Golden XP Pro Service Pack 3/Golden XP Pro Service Pack 3.vmx" "C:\Windows\System32\CMD.EXE" /C C:\scripts\JoinDomain.BAT Administrator whatever WOOHOO.COM
</pre>
<p>Kool!</p>
<p>There&#8217;s a lot more you might want to do to set up a machine ready for automated testing and Build-Deploy-Test. After Joining the domain, you can connect to it directly using WMI using PowerShell or VBScript from anywhere and managing it is easy. More information can be found <a href="http://vs2010quickref.codeplex.com/releases/view/52402" target="_blank">here</a> in the &#8216;Virtualization Visual Studio ALM Rangers Base Image Guide.PDF&#8217; (part of the Full Package). Lots of PowerShell snippets such as disabling the screen saver, disabling the firewall and so forth. I will not include that information here but it is something to bare in mind if you want to scale this out across an Enterprise. </p>
<p>By now the Virtual Machine you have just created should be registered with your Domain Controller:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-13-VmWareDomain.png"></div>
<p>You now have a cloned machine that has been joined to your Domain. For the uber-aware, you might be wondering about the impact of just cloning Virtual Machines and how the &#8216;SID Problem&#8217; might manifest itself. If you can: use Sysprep for the virtual machine instantiation step. If not, <a href="http://blogs.technet.com/b/markrussinovich/archive/2009/11/03/3291024.aspx" target="_blank">you might not have anything to worry about anyhow!</a> (unless you use WSUS&#8230;). </p>
<p><b>Automation Summary</b><br />
Assuming all of the above can be done one step at a time manually, you should be able to provision a brand new virtual machine and join it to a domain. The source code contains a file called VmWareTfsIntegration.PS1 and for VmWare Server provisioning it looks like this (replace &#8216;server&#8217; with &#8216;ws&#8217; to run against VmWare Workstation):</p>
<pre class="brush: powershell">

# VmWare Authentication Parameters. See VmRun.EXE for more information.
#
$VmWareHostType = "server";         # VmWare Server 2.0 (replace with "ws" if Workstation)
$VmWareHostName = "localhost";      # Only needed for VmWare Server. Ignored by Workstation.
$VmWareHostPort = "8333";			# Only needed for VmWare Server. Ignored by Workstation.
$VmWareUsername = "Administrator";  # Only needed for VmWare Server. Ignored by Workstation.
$VmWarePassword = "whatever";       # Only needed for VmWare Server. Ignored by Workstation. 

$VmWareGuestUsername = "Graham";    # Administrator user name you would log in as interactively.
$VmWareGuestPassword = "moo";       # Password for Administrator account. 

# Parameters required for joining a domain
#
$DomainUsername = "Administrator";
$DomainPassword = "whatever";
$DomainName = "WOOHOO.COM";

# The new machine name
$MachineName = "Moo222";

# ...... See PS1 for more information .... 

# STAGE 2: Provision a new Virtual Machine and join it to a domain
CloneVirtualMachine $VmWareConnectionParameters $VmWareGoldenImageSourceLocation $VmWareGoldenImageTargetLocation;

StartVirtualMachine $VmWareConnectionParameters $VmWareClonedImageLocation $VmWareGuestUsername $VmWareGuestPassword;

RenameVirtualMachine  $VmWareConnectionParameters $VmWareClonedImageLocation $VmWareGuestUsername $VmWareGuestPassword $MachineName;
StopVirtualMachine $VmWareConnectionParameters $VmWareClonedImageLocation $VmWareGuestUsername $VmWareGuestPassword;

StartVirtualMachine $VmWareConnectionParameters $VmWareClonedImageLocation $VmWareGuestUsername $VmWareGuestPassword;
JoinVirtualMachineToDomain $VmWareConnectionParameters $VmWareClonedImageLocation $VmWareGuestUsername $VmWareGuestPassword $DomainUsername $DomainPassword $DomainName;
StopVirtualMachine $VmWareConnectionParameters $VmWareClonedImageLocation $VmWareGuestUsername $VmWareGuestPassword;
</pre>
<p>The output should look something like this:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-03-13-VmWareExecution.png"></div>
<p>If you are using some other virtualization toolkit, it doesn&#8217;t matter: all you need at the end of this section is a machine joined to a domain. </p>
<p>This provisioning step is all a bit of a faff if you don&#8217;t have VmWare Enterprise software and I almost skipped it in this series (I wish I had <img src='http://www.havecomputerwillcode.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> ). But all that aside: we are now ready to automate the installation of the Test Controller and Test Agent and get started on what this post series is really about. </p>
<p>An excellent introduction on VmRun.Exe can be found <a href="http://www.virtuatopia.com/index.php/Controlling_VMware_Virtual_Machines_from_the_Command_Line_with_vmrun" target="_blank">here</a></p>
<p>L8r!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.havecomputerwillcode.com/blog/?feed=rss2&#038;p=641</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Automating the Integration of VmWare with Microsoft Test Manager and Lab Center: Part 1 &#8211; Introduction</title>
		<link>http://www.havecomputerwillcode.com/blog/?p=593</link>
		<comments>http://www.havecomputerwillcode.com/blog/?p=593#comments</comments>
		<pubDate>Wed, 23 Feb 2011 11:16:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ALM]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Build-Deploy-Test]]></category>
		<category><![CDATA[Lab Center]]></category>
		<category><![CDATA[Microsoft Test Manager]]></category>
		<category><![CDATA[MTM]]></category>
		<category><![CDATA[TFS]]></category>
		<category><![CDATA[TFS 2010]]></category>
		<category><![CDATA[VmWare]]></category>
		<category><![CDATA[VS 2010]]></category>

		<guid isPermaLink="false">http://www.havecomputerwillcode.com/blog/?p=593</guid>
		<description><![CDATA[PLEASE NOTE: This is for Visual Studio 2010. An updated version for Visual Studio 2011 will be available when I get around to it (consider subscribing to my blog for updates or look out for the VS11 tag on the right&#8230;) Introduction There have been a few good posts recently on how to integrate Physical [...]]]></description>
			<content:encoded><![CDATA[<p><b>PLEASE NOTE:</b> This is for <b>Visual Studio 2010</b>. An updated version for Visual Studio 2011 will be available when I get around to it <img src='http://www.havecomputerwillcode.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  (consider subscribing to my blog for updates or look out for the VS11 tag on the right&#8230;)</p>
<p><b>Introduction</b><br />
There have been a few good posts recently on how to integrate Physical Environments into the Build-Deploy-Test cycle in Visual Studio 2010. This one by <a href="http://colinsalmcorner.blogspot.com/2011/02/build-deploy-test-workflow-for-physical.html" target="_blank">Colin Dembovsky</a> (and the Darshan Desai one it references) explains how to target a physical environment out of the box with TFS. </p>
<p>But setting up those physical environments and registering them with Lab Center is still a manual task. What I want to do as part of my Build-Deploy-Test cycle is to provision a brand new virtual machine from VmWare, join it to my domain, install the test controllers and test agents, register those test controllers and agents with TFS and construct a Physical Environment in TFS/Lab Center containing those VmWare machines ready for testing. And I want to be able to do that by calling a web service, running a script or pushing a button. And I want the entire process to be automated. How?</p>
<p>This series of posts will achieve that:</p>
<li><b>Part 1 &#8211; Introduction.</b></li>
<li><a href="http://www.havecomputerwillcode.com/blog/?p=641" target="_blank">Part 2 &#8211; Provisioning a new VmWare machine using Vix and joining a domain. </a></li>
<li><a href="http://www.havecomputerwillcode.com/blog/?p=660" target="_blank">Part 3 &#8211; Automating the installation of the Test Controller and Test Agent.</a></li>
<li><a href="http://www.havecomputerwillcode.com/blog/?p=683" target="_blank">Part 4 &#8211; Automating the configuration and registration of the Test Controller and Test Agent with TFS</a>.</li>
<li><a href="http://www.havecomputerwillcode.com/blog/?p=702" target="_blank">Part 5 &#8211; Automating the creation of a Physical Enviroment in Lab Center.</a> (Source Code)</li>
<li><a href="http://www.havecomputerwillcode.com/blog/?p=725" target="_blank">Part 6 &#8211; Service Pack 1 Notes</a></li>
<p></p>
<h3> </h3>
<p><b>Background</b><br />
I am often asked by customers whether it is possible to use VmWare machines as part of their development effort in VS2010 and Lab Center. And the answer is Yes. </p>
<p>And No. </p>
<p>And Of Course. </p>
<p>And It Depends <img src='http://www.havecomputerwillcode.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>So I&#8217;m glad I cleared that up! Whether they can use VmWare is really the wrong question. What they should be asking is <b>Can we use VmWare as part of our Test Automation?</b> and <b>Can we use VmWare as part of our nightly Build-Deploy-Test cycle?</b>. So here goes&#8230;!</p>
<p><b>Can we use VmWare as part of our Test Automation? </b><br />
Yes. Microsoft Test Manager [MTM] can do this by targeting a &#8216;physical enviroment&#8217; that contains VmWare machines. Before targetting VmWare from MTM you need to:</p>
<li>Provision one or more VmWare Machines manually or using Vix, PowerCLI or whatever. </li>
<li>Optionally install a Test Controller onto one of those machines. </li>
<li>Install a Test Agent onto each of those machines.</li>
<li>Register that Test Controller with TFS.</li>
<li>Construct a Physical Environment in Lab Center containing those VmWare machines. </li>
<p>That is a typical approach taken by clients that have an investment in VmWare. Once the VmWare machines have been configured, you can target those machines in MTM:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-02-15-LabCenterMTM.png"</img></div>
<p>The astute technical term for manually configuring those VmWare machines, test controllers and physical environments is: &#8216;ballache&#8217;. </p>
<p><i>These posts will show you how to automate the creation of VmWare Environments for use in MTM and Lab Center.</i> By the end of this series of posts, you will have a set of scripts that will automatically construct brand new VmWare Environments from the ground up, install the Test Controllers and Test Agents, register them with TFS and construct a Physical Environment to be ready for use with MTM. All automatically. </p>
<p><b>We do a build every night and want to install and test our software on VmWare Environments automatically afterwards. Can we do that?</b><br />
Yes! Absolutely! The problem is that out of the box, the Build-Deploy-Test Workflow is designed to target Virtual Environments managed in Lab Center. Lab Center can only manage virtual environments built on Hyper-V and SCVMM. Lab Center has no idea how to start, stop, provision, clone or manage snapshots on a machine that is not managed by SCVMM and it collectively treats every such machine as a &#8216;Physical Machine&#8217;. So if we want to target VmWare and its features as part of Build-Deploy-Test, we need to write the necessary glue ourselves.</p>
<p><a href="http://blogs.msdn.com/b/lab_management/archive/2011/02/16/running-build-deploy-test-workflow-on-physical-environments.aspx" target="_blank">This post sums it up nicely!</a></p>
<p>Let&#8217;s get started&#8230;!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.havecomputerwillcode.com/blog/?feed=rss2&#038;p=593</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Dynamically changing Sampler properties during a Jmeter test</title>
		<link>http://www.havecomputerwillcode.com/blog/?p=543</link>
		<comments>http://www.havecomputerwillcode.com/blog/?p=543#comments</comments>
		<pubDate>Wed, 19 Jan 2011 11:35:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Performance]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Jmeter]]></category>
		<category><![CDATA[JScript]]></category>

		<guid isPermaLink="false">http://www.havecomputerwillcode.com/blog/?p=543</guid>
		<description><![CDATA[I often want to vary the value of a Sampler property such as &#8216;Retrieve All Embedded Resources from HTML Files&#8217; at runtime. The approach I am about to show will let you change (probably) *ANY* Sampler property at runtime providing you know its name! Create a simple Test Plan with one HTTP Sampler which here [...]]]></description>
			<content:encoded><![CDATA[<p>I often want to vary the value of a Sampler property such as &#8216;Retrieve All Embedded Resources from HTML Files&#8217; at runtime. The approach I am about to show will let you change (probably) *ANY* Sampler property at runtime providing you know its name! </p>
<p>Create a simple Test Plan with one HTTP Sampler which here goes to www.bbc.co.uk:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-January-19-RequestSampler.png"></div>
<p>To change the value of &#8216;Retrieve All Embedded Resources from HTML Files&#8217; at runtime, we need to know its underlying property name. The easiest way to do this is to Enable the property, save the JMX file and then open the JMX file in a text editor. Then Disable the property, save the JMX file and open that one up in a text editor: then spot the difference <img src='http://www.havecomputerwillcode.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  In the case of a HTTP Sampler, it is:</p>
<pre>
&lt;boolProp name="HTTPSampler.image_parser"&gt;true&lt;/boolProp&gt;
</pre>
<p>To change the value of &#8216;HTTPSampler.image_parser&#8217; during a test, the easiest way is to add a &#8216;BSF PreProcessor&#8217; to the HTTP Sampler like so:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-January-19-RequestBsf.png"></div>
<p>Dont forget to set the language! Notice the use of the &#8216;sampler&#8217; object name in the script. It goes without saying that this is the Sampler Context that the PreProcessor applies to. More information on the methods exposed from &#8216;sampler&#8217; &#8211; such as setProperty &#8211; can be found <a href="http://jakarta.apache.org/jmeter/api/org/apache/jmeter/testelement/AbstractTestElement.html" target="_blank">here</a>. You can do a lot more with this than you think <img src='http://www.havecomputerwillcode.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Now when you run the test, you will find all of the Content has been downloaded even though it is disabled in the Test Plan:</p>
<div id="centeredimage" align="center"><img src="http://www.havecomputerwillcode.com/blog/Images/2011-January-19-RequestTree.png"></div>
<p>You could go one step further and use a Jmeter Property that can be changed live during a running test session to represent the Enabled/Disable state of a Sampler property. See my previous post <a href="http://www.havecomputerwillcode.com/blog/?p=518" target="_blank">here</a>.</p>
<p>Kool! </p>
]]></content:encoded>
			<wfw:commentRss>http://www.havecomputerwillcode.com/blog/?feed=rss2&#038;p=543</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

