Wednesday, March 8, 2017

WatiN : Automate Web Application Testing

WatiN aims to bring you an easy way to automate Web Application Testing in .Net. Watin offers automation of Internet Explorer and Firefox.

It has Open source library and is known for very easy to read syntax.

You can download the Watin library from https://sourceforge.net/projects/watin/files/WatiN%202.x/.


WatiN interacts with the Internet Explorer using its COM (Component Object Model) interface. The Firefox interaction is done using the JSSh (JavaScript Shell Server) extension for Mozilla Firefox, present in WatiN.Core.dll file.
JSSH is a plug-in that exposes a telnet server that allows automation commands to be pushed to Firefox. When WatiN is downloaded, then it contains archive which have WatiN.Core.dll file.

Following are the features of WatiN:
  • Automate all the HTML elements
  • Find elements by multiple attributes
  • Support Ajax Website Testing
  • Syntax of WatiN is more Object Oriented and intuitive for developers
  • Supports creating screenshot of WebPages
  • Easy to integrate with your favorite Unit Testing Tool
  • Can be used with any .NET language
  • Since it is open source, you can download and add new features yourself
Sample Code:

BrowserIE.cs :

using WatiN.Core;


public sealed class BrowserIE
    {
        static readonly IE _Instance = new IE();
        
        static BrowserIE()
        {
        }

        BrowserIE()
        {
        }

        public static IE Instance
        {
            get { return _Instance; }
        }

        internal static void WaitForComplete()
        {
            throw new NotImplementedException();
        }

        internal static object SelectList(WatiN.Core.Constraints.AttributeConstraint attributeConstraint)
        {
            throw new NotImplementedException();
        }
    }


Watin Code:

using WatiN.Core;

 public partial class form1 : System.Windows.Forms.Form
    {
        public form1 ()
        {
            InitializeComponent();
        }

private void btnSearch_Click(object sender, EventArgs e)
        {

 BrowserIE.Instance.GoTo("WebURL");
 Span Span_ID = Tbl.Span(Find.ById("spanID"));
                        String Text= Span_ID .Text;

       }
}