6

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("[email protected]", "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?

1 Answer 1

4

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();
            }
        }
    }
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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