Archive for March, 2009

Using Lightweight Test Automation Framework

Comments

The Lightweight Test Automation Framework is a browser automation framework like WatiN and Selenium RC that allows you to create automated integration tests.  Its a beta release from MS and can be found on Codeplex at:

http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=22739

I first read about it from Steve Sanderson's blog where he describes how to use it with an ASP.NET MVC project.

I am supporting a legacy web forms application and have a typical web application setup so I'll explain what I did to get up and running in a matter of minutes with LTAF.

  1. Download LTAF; you can use the "... for ASP.NET Samples" link and pull the *.dll out of the Bin folder and the contents of the Test folder, or you could build from source using the "... for ASP.NET Source"
  2. Create a new Class Library project in your solution and name it appropriately - Company.Tests.Integration.Site - for example
    1. For this project's properties alter the output assembly's name to begin with App_Code - this will slightly speed up web test load times and can help solve problems you may experience if your web application references tons of assemblies, i.e. App_CodeCompany.Tests.Integration.Site
  3. Add a reference to Microsoft.Web.Testing.Light.dll to your Company.Tests.Integration.Site project
  4. Copy and add to your web project (Company.Site) the Test folder; you can name the folder anything you want and you don't strictly have to add it to your project but I did for convenience for Start > Debug
    1. Remember to alter your build process to remove the Test folder for production releases
  5. Alter the web.config file for your Company.Site to allow anonymous access to the Test folder:
  6. <location path="Test">
      <system.web>
        <authorization>
          <allow users="*" />
        </authorization>
      </system.web>
    </location>

    1. Again, remember to alter your build process to eliminate this node from your production web.config
  7. Add a reference to your integration test project, Company.Tests.Integration.Site, to your web application, Company.Site
  8. Let's test the login page (here I assume that "Login.aspx" is the name of your login page and its in the root of the application and you've used an <asp:Login /> control)...
    1. Create a new class LoginTests in your Company.Tests.Integration.Site project and eliminate the file's contents - it is very important that all tests exist outside of a namespace
    2. Paste this code into the body of your LoginTests.cs file:
    3. using Microsoft.Web.Testing.Light;
      
      [WebTestClass]
      public class LoginTests
      {
          [WebTestMethod]
          public void SignInAndSignOut()
          {
              var page = new HtmlPage("Login.aspx");
      
              page.Elements.Find("UserName").SetText("someuser");
              page.Elements.Find("Password").SetText("yourPW");
              page.Elements.Find("LoginButton").Click(WaitFor.Postback);
      
              // you'll need to determine what a good landmark for your
              // application is upon successful login
              var logoutLink = page.Elements.Find("LogoutHyperlink");
              Assert.AreEqual("[Logout]", logoutLink.GetInnerText());
      
              logoutLink.Click(WaitFor.Postback);
      
              Assert.IsNotNull(page.Elements.Find("LoginButton"));
          }
      }

  9. Set your Company.Site as the startup project if its not already, and Tests/Default.aspx as the startup page; run from Visual Studio

Magic!  This is my first use of a browser automation framework for integration testing and while it has its pitfalls, it does work and looks very promising.

Notes
  • Looks like all your integration tests must exist in the same assembly
    • Source code for LTAF is available so making this a configuration option is a possibility
  • All tests must exist outside of namespaces
  • Prefixing your integration tests assembly with App_Code can help work around assembly loading problems as the test runner searches for WebTestClass attributes
  • Remember to have your production build process eliminate the Tests folder and associated integration test assembly

Basing the Three Hunters

Comments

I demoed Games Workshop's War of the Ring mass combat system over the last weekend with two fully painted 750 point armies.  When I was constructing the armies I realized that Evil had some pretty awesome units (my Mordor Troll and Cave Troll) while my Good force was just missing that special bite.  So I picked up the Three Hunters box set the week before the demo and assembled and painted them.  They are an actual 3 figure unit in the new system and they're pretty bad ass.

One thing you have to do for some special units is create a custom base.  There are a few ways to go about doing this.  I started trying to layer 2mm black sheet styrene and cutting a circular hole with a 1" flat bit; that didn't work out too well (next time I am going to try a 1" round hollow bit).  With time running out I had to make a base quick and settled on the following method.

Step 1: Sheet Styrene

 

I used 2mm black sheet styrene.  Scored with an exacto knife using a square as a guide, and then broke by applying pressure over a table's edge.

Step 2: Rare Earth Magnets

GW suggests using Blu-Tac to hold models in place but that can become messy over time.  While this is cost effective I prefer a more secure hold so I went with Rare Earth Magnets.  You can get these at Michael's for $5 for a pack of 6 (or off the Internet for significantly cheaper).  I used the 13mm (or quarter inch) magnets though smaller would work better.  You'll want to carefully position the magnets on the base and affix with super glue - remember to account for the slot which splits the base on the bottom - you cannot center the model on the magnets easily.

Step 3: Elmer's Glue, Sand, and Spray Primer

I applied Elmer's Glue (not thinned with water) and dumped sand over the surface.  I also applied a few loose rocks.  When this dried I sprayed the entire base with spray primer.  I avoid using Gesso or paint primer because it weakens the bond of the Elmer's Glue creating a big mess.

Step 4: Paint and Seal

Paint the base with your browns, drybrush, and then seal.  I like Dullcote, its strong and will not gloss or satin your finish.

Step 5: Flock

I flocked my base using GW's Citadel Grass (the light happy summer green) and Silflor Buffalo grass (spring green).  The Buffalo grass is expensive at $25 for a box, but it will last you a long time and it looks very nice.  (Buffalo grass comes pre-clumped.)

Step 6: Galvanized Washers

Zinc washers #6 size.  I glue these onto the bottom of my bases; #6 size is small enough to fit on either side of the slot under the base.  Be mindful of your magnet placement when super gluing these onto your model.

Done!

Certainly does not take long to have a very simple but decent looking base.  I would say that overall these flat bases are easier to complete than the GW War of the Ring molded bases because gluing the sand onto those bases can create problems getting your models in and out.  If you do use the molded bases, make sure you have a test model to try each slot before the sand dries in place and you prime the base.

Three Hunters Three QuartersThree Hunters Front