Geeks With Blogs
AzamSharp Some day I will know everything. I hope that day never comes.

Thanks to Justin and Jason for pointing out WatiN. WatiN is inspired by Watir but build for the .NET framework. This means you can write your unit tests using C#, VB or any CLS complaint language. I used WatiN with MbUnit and it worked super great! Let's check out some of the code below:

You need to add reference to MbUnit.Framework and WatiN.Core.

[TestFixture(ApartmentState=ApartmentState.STA)]
    public class TestLoginPage
    {
        [Test]       
        public void TestCanAuthenticatedUserLoginSuccessfully()
        {
            IE ie = new IE("http://localhost:2334/Login.aspx");
            string finalUrl = "http://localhost:2334/HomePage.aspx";
           
            ie.TextField(Find.ById("txtUserName")).TypeText("AzamSharp");
            ie.TextField(Find.ById("txtPassword")).TypeText("mypassword");

            ie.Button("Button1").Click();

            Assert.AreEqual(finalUrl, ie.Url);

            // close the window
            ie.Close();
               
        }
    }

Pretty awesome! The code will open a new window fill out all the fields and press the Submit button.

Thanks Jason and Justin! :)    

Posted on Wednesday, January 2, 2008 5:10 PM | Back to top


Comments on this post: Unit Testing ASP.NET Pages Using WatiN

# re: Unit Testing ASP.NET Pages Using WatiN
Requesting Gravatar...
You can also use the WatiN COM interface I wrote to use WatiN from almost any other language (perl, php, python, etc)
Left by Daaron on Jan 03, 2008 4:31 AM

# re: Unit Testing ASP.NET Pages Using WatiN
Requesting Gravatar...
How can i use the above code in asp.net application
Left by Ahsan on Apr 14, 2008 6:39 PM

# re: Unit Testing ASP.NET Pages Using WatiN
Requesting Gravatar...
My application has almost 50 pages. how can I use it for them.
can we test link between the pages.
Left by Andy on May 27, 2008 8:48 AM

Your comment:
 (will show your gravatar)


Copyright © Mohammad Azam | Powered by: GeeksWithBlogs.net