Wednesday, 15 April 2009

How to reduce a Test Automation Deficit

For some time, I've been wondering how on earth you make sure a Legacy application has a full suite of Automated Tests.  In my place of work, we follow Scrum as our Development Methodoligy.  I was always led to believe that you should create Automated Tests for the Stories the Team accepted in the given Sprint.

However, my colleague has sent me the attached Link, which shed's some light on how to reduce your Test Automation deficit.


Thursday, 12 February 2009

WatiN 2.0 - CTP Release 3.0

WatiN just keeps getting better with the latest release.  WatiN 2.0 CTP 3.0, now offers increased support for both Internet Explorer and FireFox.

Changes in this release:

  • Implemented support on Mozilla.Frame to get access to elements inside the document of a Frame
  • Implemented support on Mozilla.Frame to get access to elements inside the document of an IFrame
  • Implemented Eval on Mozilla.Document (= FireFox and Frame) and added to the IFrame interface

Fixed bug(s):

  • Form.Submit didn't wait for a possible postback and page load.

WatiN - Firefox with iFrames

I’ve been trying to get my head back into WatiN (WatiN-2.0.1.754-net-2.0) recently, and came across an issue trying to get hold of the contents of an IFrame.  Using IE, I was able to use an Assert to check the contents of an IPara which resides within an IFrame.  However, running the same code against Firefox, I was unable to get inside ‘Mainwin’, even though FireBug can see it without issue. 

However, having posted a message on the WatiN Users (Sourceforge) Forum, Jeroen van Menen has advised that the next CTP release of WatiN will support iFrames.

[Test]

public void CheckSplashContentTelephone()

{

IBrowser browser = BrowserFactory.Create(BrowserType.FireFox);

browser.GoTo(_loginUri);

browser.Maximize();

Thread.Sleep(3000);

CMS_Common.LogonDlg.LogonUserNamePassword(browser, "admin", "admin", appname);

Common.LogOn.ImportControl(browser, "Click Here to Skip Download");

Assert.AreEqual(Splash.Telephone(browser).Text.Trim(), "My Phone Number");

Toolbar.ClickButton(browser, Toolbar.Button.LOGOUT);

browser.Close();

}

        public static IPara Telephone(IBrowser browser)

        {

            IFrame mainframe = browser.Frame(Find.ById(mainwin));

            return mainframe.Paras[1];

        }

Friday, 16 January 2009

WatiN 2.0 - CTP Release 2.0

Over recent weeks I've been considering the use of Selenium over WatiN.  This is purely & simply because it supports ALL the Major Standards Compliant Browsers out of the box.  Also, another of our Development Teams is already using Selenium!  However, both myself and my colleagues have invested a lot of time into WatiN, and Jeroen van Menen's WatiN Users Post yesterday has convinced me to stick with it.  Here's a list of what comes with WatiN's latest incarnation:

Changes in this release:

  1. - Works with FireFox 3.x and FireFox 2.x (both jssh.xpi plug-ins are included in the Mozilla directory)
  2. - Greatly improved performance and stability when running tests with FireFox

Fixes reported bugs:

  1. Problem with setting ActiveElement in FF 3.x
  2. SF issue 1954487  Setting TextField.Value for TextArea in FireFox fails
  3. SF issue 1913072  BrowserFactory.Settings.WaitForCompleteTimeOut doesn't work 

Wednesday, 10 September 2008

WatiN - Running IISReset

There might be ocassion where there's a need to run an IISReset as part of your Test. Here's how you do it.

{
// Run IIS reset to clear the chache
Process iisResetProcess = System.Diagnostics.Process.Start("cmd.exe", ConfigurationManager.AppSettings["iisResetCommand"].ToString());
iisResetProcess.WaitForExit();
iisResetProcess.Close();
}

In order to allow this to work, please ensure that your App.Config has the following within appSettings.

<add key="iisResetCommand" value="/C iisreset MACHINE NAME"/>

Thanks to David Cromar

Monday, 28 July 2008

WatiN - Simple SQL Server Class

For a while, I searched long & hard for a simple Class that would allow my tests to easilly query a SQL Server database. Unfortunately, I couldn't find anything that suited my requirements, and so, I enlisted the help of my Boss, who helped me create the following. I cannot guarantee it's suitability for others, but it certainly works for me.
namespace Common
{
public class SQLServer

{
private SqlConnection _sqlConn;

public SqlConnection myConnection
{
get
{

if (_sqlConn.State != System.Data.ConnectionState.Open)
{
_sqlConn.Open();
}
return _sqlConn;
}
}

public void CONNECT(string uname, string pword, string dbserver, bool isTrustedConnection, string database, int connTimeout)

{
string connStr = string.Empty;
if (isTrustedConnection)
{
connStr = " server=" + dbserver + "; Trusted_Connection=yes" + "; database=" + database + "; connection timeout=" + connTimeout.ToString();
}
else
{
connStr = " user id=" + uname + "; password=" + pword + "; server=" + dbserver + "; database=" + database + "; connection timeout=" + connTimeout.ToString();
}
_sqlConn = new SqlConnection(connStr);

try
{
_sqlConn.Open();

}
catch (Exception ex)
{
Console.WriteLine("Connection string not valid:" + connStr);
}
}

public void DISCONNECT()
{
myConnection.Close();
}

public string SELECT(string tableName, string columnName, string fieldname, string value)
{
string sqlStr = string.Empty;

sqlStr = " SELECT [" + fieldname + "] FROM [" + tableName + "] WHERE [" + columnName + "]= '" + value+"'";

SqlCommand sqlComm = new SqlCommand(sqlStr, myConnection);

object o = sqlComm.ExecuteScalar();
if (o == null)
return string.Empty;
else
return o.ToString();
}

public System.Data.DataTable SelectMultipleValues(string tableName, string columnName, string[] fieldNames, string[] critieraValues)
{
System.Data.DataTable values = null;
string sqlStr = " SELECT ";
foreach(string fieldName in fieldNames)
{
sqlStr+="[" + fieldName + "], ";
}

if (sqlStr.EndsWith(", "))
{
sqlStr = sqlStr.Substring(0, sqlStr.Length - 2);
}
sqlStr += " FROM [" + tableName + "] WHERE [" + columnName + "] IN(";
foreach (string criteriaValue in critieraValues)
{
sqlStr += "'" + criteriaValue + "',";
}
if (sqlStr.EndsWith(","))
{
sqlStr = sqlStr.Substring(0, sqlStr.Length - 1);
}
sqlStr += ")";

SqlCommand sqlComm = new SqlCommand(sqlStr, myConnection);

SqlDataReader reader = sqlComm.ExecuteReader();
if (reader != null && reader.HasRows)
{
values = GetTable(reader);
reader.Close();
}
return values;
}

public System.Data.DataTable GetTable(System.Data.SqlClient.SqlDataReader _reader)
{

System.Data.DataTable _table = _reader.GetSchemaTable();
System.Data.DataTable _dt = new System.Data.DataTable();
System.Data.DataColumn _dc;
System.Data.DataRow _row;
System.Collections.ArrayList _al = new System.Collections.ArrayList();

for (int i = 0; i < _table.Rows.Count; i++)
{

_dc = new System.Data.DataColumn();

if (!_dt.Columns.Contains(_table.Rows[i]["ColumnName"].ToString()))
{

_dc.ColumnName = _table.Rows[i]["ColumnName"].ToString();
_dc.Unique = Convert.ToBoolean(_table.Rows[i]["IsUnique"]);
_dc.AllowDBNull = Convert.ToBoolean(_table.Rows[i]["AllowDBNull"]);
_dc.ReadOnly = Convert.ToBoolean(_table.Rows[i]["IsReadOnly"]);
_al.Add(_dc.ColumnName);
_dt.Columns.Add(_dc);

}
}

while (_reader.Read())
{

_row = _dt.NewRow();

for (int i = 0; i < _al.Count; i++)
{

_row[((System.String)_al[i])] = _reader[(System.String)_al[i]];

}

_dt.Rows.Add(_row);

}

return _dt;
}
}
}
How do I use the Class?
public static void SelectValues()
{
Common.SQLServer sq = new Common.SQLServer();
sq.CONNECT("sa", "sa", "SQLServerInstance", true, "Database", 10);
string[] fieldNames = { "ColumnValue" };
string[] criteriaValues = { "field1", "field2", "field3", "field4", "field5", "field6", "field7", "field8" };
System.Data.DataTable result = sq.SelectMultipleValues("Option", "Name", fieldNames, criteriaValues);

foreach (System.Data.DataRow row in result.Select())
{
foreach (System.Data.DataColumn column in result.Columns)
{
Console.WriteLine((string)row[column]);
}
}
sq.DISCONNECT();
}


Thursday, 10 July 2008

Agile Testing - why do it any other way?

I recently went to a BCS SIGIST Conference in London and was quite frankly shocked by the number of QA Professionals that weren't working in an Agile environment. In my past, I have worked in a Development Team that ran with the Waterfall approach, but in recent Years (whether I've realised it or not), I've been working in Agile Development.

More recently, my company 'Immediacy' (or Alterian as we're now known) has been using SCRUM, which is a Lightweight Management Framework that makes it really easy to demonstrate the progress of the project to both you and your customer. I certainly couldn't go back to the archaic practices of Waterfall, or 'dumping over the fence' as I've often been known to refer it to.

My boss sent me this useful Google Video recently, which is a really good insight into Testing in an Agile environment. Give it a watch.........it's really interesting.

Agile Testing Video
Scrum Alliance