Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

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

[TestMethod]
public void Failed_Attempted_Login_Invalid_Combination()
{
    using (var browser = new IE(baseUrl + "login.aspx"))
    {
        browser.Page<AVLoginPage>().Login("test@roger.com", "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
add comment

1 Answer 1

up vote 3 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;
        }
        [STAThread]
        static void Main(string[] args)
        {
            using (Browser b = BrowserFactory(true))
            {
                b.GoTo("http://sqa.stackexchange.com/");
                b.WaitForComplete(20*10000);
                b.TextField(Find.ByName("q")).TypeText("WatiN");
                Console.ReadKey();
            }
        }
    }
}
share|improve this answer
    
Thanks - this does the trick. –  Dan Snell Aug 9 '11 at 16:34
add comment

Your Answer

 
discard

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.