Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In my WatiN tests I am currently structuring the test like this:

public void Failed_Attempted_Login_Invalid_Combination()
    using (var browser = new IE(baseUrl + "login.aspx"))
        browser.Page<AVLoginPage>().Login("", "123421343414");

        Assert.IsTrue(browser.ContainsText("Email address or password is incorrect. "));


Is there a clean way to be able to specify the browser without having to create separate tests for each browser type?

share|improve this question
up vote 4 down vote accepted

Use Factory method that return an object instance of type Browser.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WatiN.Core;

namespace ConsoleApplication4
    class Program

        public static Browser BrowserFactory(bool IWantToUseIEAndOnlyIE)
            Browser result;
            if (IWantToUseIEAndOnlyIE)
                result = new IE();
            else {
                result = new FireFox();

            return result;
        static void Main(string[] args)
            using (Browser b = BrowserFactory(true))
share|improve this answer
Thanks - this does the trick. – Dan Snell Aug 9 '11 at 16:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.