WatiN

WatiN stands for Web Application Testing In .NET, and it’s a framework that enables web application testing through Internet Explorer. WatiN is inspired on WatiR, a web application testing framework for Ruby. The way that WatiN works is very “easy”, knowing that there’s a lot of work behind a framework like this. WatiN lets you open Internet Explorer instances, and through interop, interact with the elements in a form. With WatiN, you can get and set values from the elements in a form, and you can fire events of any of the elements in the document too.

using System;
using WatiN.Core;

namespace WatinTest
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            // Open a new Internet Explorer window and
            // goto the google website.
            int count = 1000000;
            if (args.Length < 3)
            {
                Console.WriteLine("Synatx: watintest.exe url username password number_of_times");
                return;
            }
            
            string url = args[0].ToString();
            string username = args[1].ToString();
            string password = args[2].ToString();
            if (args.Length == 4)
                count =  Convert.ToInt32(args[3]) ;

            IE ie = new IE(url);
                
            ie.TextField(Find.ByName("txtUserName")).TypeText(username);
            ie.TextField(Find.ByName("txtPassword")).TypeText(password);
            ie.Image(Find.ByName("btnLogin")).Click();

            Frame frame_contentframe = ie.Frame(Find.ByName("contentframe"));
            frame_contentframe.Image(Find.ByUrl(url+"/images/Button/search.gif")).Click();

            for (int i = 0; i < count; i++)
            {
                Console.WriteLine("Run:{0}", i);
                string checkbox = string.Format("dgReport__ctl{0}_chkSelect", i % 6 + 3);
                frame_contentframe.CheckBox(Find.ById(checkbox))
                    .Checked = true;
                frame_contentframe.Image(Find.BySrc(url+"/Images/Button/edit.gif")).Click();
                frame_contentframe.Image(Find.BySrc(url+"/Images/Button/save.gif")).Click();
                frame_contentframe.Image(Find.BySrc(url+"/Images/Button/close.gif")).Click();
            }


            // Internet Explorer and the console window immediately.
            ie.Close();
        }
    }
}

Reference:
http://www.codeproject.com/KB/aspnet/WatiN.aspx src=_blank”/>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s