Home
About Me
Categories
C#
(11)
ASP.NET
(34)
JavaScript
(6)
CSS
(1)
XSLT
(1)
Unit Testing
(22)
Architecture
(23)
Ajax
(8)
LINQ to SQL
(2)
ASP.NET MVC
(5)
Life
(18)
Book Reviews
(2)
WPF
(13)
Projects
(2)
Unit Testing ASP.NET Pages Using WatiN
published on 5/27/2008 3:06:43 PM
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! :)
Name:
Name:
Email:
Comment/Feedback: