Using WatiN to test browse Yahoo mail.

Summary:

The objective of this exercise is to compare testing of a web site (Yahoo Mail) with WatiN to the test previously done with AutoIt:

Automating Internet Explorer with Auto It. (Windows Tasks Automation software)

The first major advantage is the availability of the Test Recorder. This Test Recorder is able to get the names or id’s (and other properties) of the IExplorer. The Test Recorder is available from: http://watintestrecord.sourceforge.net/ A big plus is that it can generate source code in VB.NET. (The beta 2 version is not generating C# code at the moment)

TestRecorderSmall

Note: the note in red in the above capture: “Scripting to VB.Net and copying to clipboard.”

I modified the example shown in: http://watin.sourceforge.net/gettingstarted.html in order to have the code in C# to access http://mail.yahoo.com, login, and click on Mail.

I have a video that shows the recording process and the code generated using the Test Recorder:

Notice that the example is done with Visual Studio 2003. Since I used Visual Studio Express 2005 there is a minor difference: when adding the Reference to the Project, I needed to click on the Browse tab.

During this exercise I came across the need to address the log-in button in Yahoo but it was not obvious how to invoke it. Then I ran the recorder, compiled the script to VB.Net Console and then copied the results to the console. The button I needed was: Button btn_save = window.Button(Find.ByName(“save”));

Since I am using the C# version I coded the call to the button as:

ie.Button(Find.ByName(“.save”)).Click();

Notes:

1. A useful tool to find out the names, id’s, etc of IExplorer fields is the ie developer toolbar.

2. Here is the C# code:

//**WatiN example**
// Adapted by Omar Flores
//
using System;
using WatiN.Core;
using System.Threading;

namespace WatiNGettingStarted
{
class WatiNConsoleExample
{
[STAThread]
static void Main(string[] args)
{
// Open a new Internet Explorer window and
// goto the google website.
IE ie = new IE(“http://www.mail.yahoo.com”); //(“http://localhost/”);

// Find the search text field and type Watin in it.
ie.TextField(Find.ByName(“login”)).TypeText(“yourUserID”);
Thread.Sleep(2000);

// Find the search text field and type Watin in it.
ie.TextField(Find.ByName(“passwd”)).TypeText(“yourPassword”);
Thread.Sleep(2000);

// Click the Google search button.
ie.Button(Find.ByName(“.save”)).Click();
Thread.Sleep(1000);

// Click the Google search button.
ie.Button(Find.ById(“global_check_mail_top”)).Click();
Thread.Sleep(1000);

// Uncomment the following line if you want to close
// Internet Explorer and the console window immediately.
//ie.Close();
}
}
}

Advertisements

One Response to “Using WatiN to test browse Yahoo mail.”

  1. Vladimir Says:

    The automated test area looks interesting, Would be nice to implement your own UI, and integrate some different test core dlls (different free providers) , that could be interesting. I looked something like that with other commercial programs. Example 1. There are some comercial ZIP programs that get advantage of alredy done free libs.

    Example 2. There are some ISO image commercial programs that calls underneath ISO free libs like the nero ones.

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


%d bloggers like this: