PLEASE NOTE: This is for Visual Studio 2010. For the VS2012 version, please click here.
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):
Part 1 – Introduction.
Part 2 – Provisioning a new VmWare machine using Vix and joining a domain.
(Source Code) [See Part 5]
Part 3 – Automating the installation of the Test Controller and Test Agent. (Source Code) [See Part 5]
Part 4 – Automating the configuration and registration of the Test Controller and Test Agent with TFS.
Part 5 – Automating the creation of a Physical Enviroment in Lab Center. (Source Code)
Part 6 – Service Pack 1 Notes
Build-Deploy-Test with VmWare is a superset of this so I will tackle that after this series.
See Part 2 for Requirements (PowerShell, Vix etc.).
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.
Manually registering the Test Controller
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 – that’s what it is for!
Checkpoint 1 – Machine with Test Controller and Test Agent installed but not configured
There are a lot of possiblities 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.
If you’ve set up a Test Controller before you will be familiar with this user interface. Launch it from within your Virtual Machine:
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…
Enter the parameters and make sure the configuration works if you do it manually:
If the operation was successful you will be able to see the Test Controller in Lab Center:
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.
The User Interface Application used to configure the Test Controller above is called ‘TestControllerConfigUI.EXE’. If you hunt around on your virtual machine disk you will find one called ‘TestControllerConfig.EXE’ that lives in the same directory. ‘TestControllerConfig.EXE’ is what we use to automate setting those parameters.
Now revert to Checkpoint 1 in the VM. To Undo (unregister) the Test Controller from Lab Center, do this first within your Virtual Machine.
We will now automate the Test Controller registration using the command line tool:
I have no idea what can take so long: but it does.
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:
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.
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):
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
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
Note the addition of ‘SomeOtherText’ 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!
Manually registering the Test Agent
Checkpoint 2 – Test Controller Installed and Registered with Lab Center. Test Agent Installed but not Registered with Test Controller.
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’ll point out the difference later when we automate it:
Notice we are using ‘localhost’ 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
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:
If you can’t see your Test Agent you have to troubleshoot why before you proceed.
Once this works, revert to Checkpoint 2. To automate the Test Agent configuration from the command line, there is a tool called ‘TestAgentConfig.EXE’ that does it for us within your VM:
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).
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:
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
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.
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:
FINALLY! Revert to Checkpoint 2 again. To ‘Undo’ (Unregister the Test Agent with the Test Controller) just do this from a Command Prompt in your Virtual Machine:
C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\TestAgentConfig.EXE Delete
Now we can see that this is going to work using our VmRun.EXE call with our Batch File:
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
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
After that, check once again you can see your Controller and Agent in TFS:
Awesome! So that’s all the moving parts tamed.
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.
This snippet shows the key changes to the VmWareTfsIntegration.ps1 script for this stage:
# 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
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
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.