Running a WatiN test scenario on all browsers

I used WatiN a few times for automating User Acceptance Test scenarios in the past, and have posted some tips and tricks to get the Firefox plugin working (which constantly crash even with the newer jssh-WINNT-3.x.xpi).

This time I want to share a snippet of code that you're free to use to make it easier to test against all the supported browsers without making the same repetition on every tests of calling new IE(), new Firefox() or using the browserfactory.

So this is the goal:

[TestFixtureSetUp]
public void Context()
{
  CrossBrowserTestExecutor.Execute( Scenario ).WithAllBrowsers.Go();
}

public void Scenario(Browser browser)
{
  browser.GoTo( "https://www.google.com" );
  browser.Close()
}

pretty clean and readable right?

So this is the code that enables you to do that:

public class CrossBrowserTestExecutor
{
  public static CrossBrowserTest Execute( Action<Browser> test )
  {
    return new CrossBrowserTest( test );
  }
}

public class CrossBrowserTest
{
  public CrossBrowserTest( Action<Browser> test )
  {
    TheTest = test;
    BrowserAgents = new List<Browser>();
  }

  public Action<Browser> TheTest { get; set; }

  public IList<Browser> BrowserAgents { get; set; }

  public CrossBrowserTest WithAllBrowsers
  {
    get
    {
      BrowserAgents.Add( new IE() );
      BrowserAgents.Add( new FireFox() );
      return this;
    }
  }

  public void Go()
  {
    foreach ( Browser agent in BrowserAgents )
    {
      TheTest( agent );
    }
  }
}

Feel free to use it in any of your project, but please drop a comment if you find it useful. Thanks