Testing Stax Control Grabber is now available for download

The Testing Stax Control Grabber is now available for download from Codeplex.

Control Grabber.jpg

 

What is this thing ?

This is a generator that tries to fast track the creation of your stax control classes. To use, open internet explorer at the page you want to capture, enter a namespace and drag the cursor onto the page. You will be prompted to save the CS file to disk. The source code for the grabber  will also soon be available as well on the Codeplex site under tools.

A peek behind our curtain

I am pretty proud of our WatiN stack, it is in it’s third major version now and is an absolute joy to work with.

After seeing some other’s code samples online I thought that I should share some of the details so people can improve what they are doing. We recently hit a new one day record with one of our SDE/T’s writing 72 new test cases in a single day.

How it works

Our stack is broken down into four key layers, the test, a logical layer, a physical layer and then WatiN itself. If we are working on a Winforms application, we replace WatiN with an in-house developed stack that uses the Windows UI automation API’s. Our test data is stored in a SQL express database and we have a generated data access layer, which keeps the cost of creating CRUD methods very low. One of our tests looks like this:

[TestMethod]
public void VerifyCustomerCreation()
{
    Logical.Customer.CreateNewCustomer("Default Customer");
    Verification.Customer.VerifyCustomerCreated();
}

And that’s it. The tests are written in the business domain of the application that we are testing, not in a pile of clicks and set values. The next level down the “logical” layer is called by the tests and looks like this:

public static void CreateNewCustomer(string customerName)
{
    Physical.Customer.GoToNewCustomerPage();
    Physical.Customer.EnterNewCustomerInfo(customerName);
    Physical.Customer.SaveNewCustomer();
}

We build our logical layer up by combining smaller atomic actions, this allows us to heavily use the DRY (don’t repeat yourself) approach.

Our physical layer is where the rubber hits the road and it looks like this:

public static void EnterNewCustomerInfo(string customerName)
{
    ControlHandler conroller = new ControlHandler();
    TestData.Customer customerDetails = TestData.Customer.GetCustomerDetails(customerName);</p>

<pre><code>controller.SetValue(NewCustomerPage.txtFirstName, customerDetails.FirstName);

controller.Invoke(NewCustomerPage.btnSave);
</code></pre>

<p>}

The control handler fully abstracts WatiN, or another automation tool so we interact with any control by typically only calling either SetValue, Invoke or GetValue.

To define our controls we have an in-house developed tool where we drag a magnifying glass (Spy++ style) onto a page and it then captures all the controls and gives us a generated static class.

This stack is the result of a lot of investment in our time and represents, in my opinion, state of the art when it comes to web test automation. But then again, I am a bit biased because I wrote it :-) .

McWatin – can now open and close firefox by itself

With the latest commit to the http://code.google.com/p/mcwatin/ repository can now open and close firefox all by itself. :-)

The next feature to add is detection if a browser is open with jssh running and to re-use that browser instead of always launching a new one, or close as appropriate.

On thing that I have noticed is that the lack of a debugger in mono develop on the mac is really slowing me down as I can’t easily follow the code execution.

Making progress on the WatiN mac os x port

So I haven’t worked on my WatiN Mac os x port for a few days, but I got back into it last night. The main hurdle at the moment is that the System.Diagnostics.Process class is not fully baked on Mono 2.4 on the Mac platform, because it doesn’t implement the /proc filesystem that linux does.

The correct thing to do would be to learn how the Mach kernel process structure works and fix mono, but I haven’t programmed in non managed C since 1990 and I would be very dangerous, especially at such a low level in mono.

So the first approach was to use the parts of mono that were working, namley Proces.Start() to call a shell script that I wrote to /tmp, then redirect standard out to a file, then parse that file and act accordingly.

StreamWriter sw = new StreamWriter(&quot;/tmp/watin-listprocess.sh&quot;,false);
sw.WriteLine (@&quot;ps x | grep&quot; + processname + &quot; | grep -v grep &gt; /tmp/watin-processlist.out&quot;);
sw.Flush();
sw.Close();</p>

<p>Process shScriptProcess = new Process();
shScriptProcess.StartInfo = new ProcessStartInfo(&quot;/bin/sh&quot;,&quot;/tmp/watin-listprocesses.sh&quot;);
shScriptProcess.Start();

A hack, yes, in fact a very messy hack. So messy there had to be a better way.

And there is …

Enter Monobjc. Monobjc is a managed wrapper around the Mac os x Cocoa API’s. A quick search pointed to the NSTask and NSPipe classes as a way to start a process with NSTask, and capture standard out with NSPipe, then parse the result.

A much more technically correct solution.

public static void Main(string[] args)
{
// spin up the objective-c runtime
ObjectiveCRuntime.LoadFramework(&amp;quot;Cocoa&amp;quot;);
ObjectiveCRuntime.Initialize();
NSAutoreleasePool pool = new NSAutoreleasePool();</p>

<p>// Create our process
NSTask task = new NSTask();
NSPipe standardOut = new NSPipe();
task.StandardOutput = standardOut;
task.LaunchPath = @&quot;/bin/ps&quot;;</p>

<p>// add some arguments
NSString argumentString = new NSString(&quot;-ax&quot;);
NSArray arguments = NSArray.ArrayWithObject(argumentString);
task.Arguments = arguments;</p>

<p>// We have liftoff
task.Launch();</p>

<p>// Parse the output and display it to the console
NSData output = standardOut.FileHandleForReading.ReadDataToEndOfFile;
NSString outString = new NSString(output,NSStringEncoding.NSUTF8StringEncoding);
Console.WriteLine(outString);</p>

<p>// Dipose our objects, gotta love reference counting
pool.Release();
}

So this needs to be fully baked in and then put into my Watin on mac os x port and then it should work stand alone, without shell script assistance.