Archive for January, 2007

Run Watir Tests from within Visual Studio

I have been having a bit of a play with the Watir Ruby web UI testing framework and after a bit of jiggery pokery I’ve managed to get it all going inside of Visual Studio. Here’s how…

You will need to install:

I had a bit of trouble getting Watir to install on Windows XP using the Windows installer but I think that was due to having installed Ruby using InstantRails. Once I installed it using the Ruby Windows installer it worked OK. On Vista however the installer wasn’t playing nicely at all. To install on Vista required the use of RubyGems which basically involves typing:

    gem install watir

… at the command line. Simple as that. One thing to note is that if you install Watir using the ‘gem’ approach you need to add the line:

    require ‘rubygems’

at the top of your test ruby files before adding:

    require ‘watir’

Thanks to my Ruby (tor)mentor Dave Verwer for that gem. (oh dear…)

Ruby in Steel (worst name ever competition winner 2007) will allow you to debug your Watir tests and edit them with all of the Visual Studio goodness in place.

Once you have all that in order you need a bit of code to hook your Ruby scripts into the usual NUnit/TestDriven way of things. You have two options (writing it yourself being a third). Either go ‘the whole hog’ and try and get this article on Code Project running or use the code below, adapted from Scott Hanselman’s efforts to do the same thing. (I say ‘adapted’. I mean added the ‘directoryPath’ argument as Scott’s version seemed to need the .rb files to be put in the bin, so to speak)

public class WatirAssert 
    public static void TestPassed(string rubyFileName, 
    string directoryPath) 
        string output = String.Empty; 
        using (Process p = new Process()) 
            p.StartInfo.UseShellExecute = false; 
            p.StartInfo.RedirectStandardOutput = true; 
            p.StartInfo.FileName = "ruby.exe"; 
            p.StartInfo.Arguments = rubyFileName; 
            p.StartInfo.WorkingDirectory = directoryPath; 
            output = p.StandardOutput.ReadToEnd(); 
        Regex reg = new Regex(@"(?<tests>\d+)\stests,\s(?<assertions>\d+)\sassertions,\s(?<failures>\d+)\sfailures,\s(?<errors>\d+)\serror\s", RegexOptions.Compiled); 
        Match m = reg.Match(output); 
            int tests = int.Parse(m.Groups["tests"].Value); 
            int assertions = int.Parse(m.Groups["assertions"].Value); 
            int failures = int.Parse(m.Groups["failures"].Value); 
            int errors = int.Parse(m.Groups["errors"].Value); 
            if (tests > 0 && failures > 0) 
                Assert.Fail(String.Format("WatirAssert: Failures {0}", failures)); 
            else if (errors > 0) 
                Assert.Fail(String.Format("WatirAssert: Errors {0}", errors)); 
        catch (Exception e) 
            Assert.Fail("WatirAssert EXCEPTION: " + e.ToString()); 

Where you stick this is entirely up to you but you need to be able to reference it from your unit tests so you could put it in its own assembly or just add the class to your unit test project.

Once you have all that sorted out you can now add a .NET unit test such as the following:

public class UITest 
    public void LoginTests() 
       WatirAssert.TestPassed("login_tests.rb", @"C:MyAppWatirTestDirectoryUI Tests\"); 

In this example “login_tests.rb” is the name of the Ruby script file containing the Watir test (or tests) and the directoryPath argument is the directory containing said Ruby file.

Now, using TestDriven.NET we can right-click on the above code in VS and run the test. We can add a break point to the C# code and right-click to debug through the test. As we have Ruby in Steel installed we can also use Visual Studio to edit the Ruby file and whilst doing so we can add breakpoints in the Ruby and step into the executing Ruby with the debugger.

Oh joy…

Whilst I am on the topic I have to say that I think Ruby is rubbish. It is supposed to be the language of the Gods and it can’t even tell that when I add a semi-colon at the end of EVERY SODDING LINE, I didn’t mean to do it. Couldn’t it just ignore them for me if it is supposed to be so clever…

NVIDIA Forceware for Vista Released, Still doesn’t work with my laptop…

Since installing Vista I have been checking all the vendors’ sites every couple of days waiting for my drivers to arrive. It has to be said that they are certainly taking their time considering the public launch is just a couple of weeks away…

Anyway, I digress… I found yesterday night that NVIDIA has released a final version of their Forceware drivers. I already had the beta which required a bit of noodling under the bonnet to get working.

With the release version I got an even better error message than I had with the beta.

Setup detected that the operating system in use is not Windows Vista. The setup program and its associated drivers are designed to run only on Windows Vista. The installation will be terminated.

No, that’s right… OF COURSE IT ISN’T VISTA. Who do these drivers think they are speaking to me like that?

Turns out the solution was more or less the same as before, with a few tweaks. The latest inf file I found was for 97.27 which doesn’t quite work with the release version. You need to download it and replace the following lines (which are lines 12 and 13):

CatalogFile =
DriverVer = 11/16/2006,

With these lines from the NVIDIA supplied inf:

CatalogFile = NV_DISP.CAT
DriverVer = 12/07/2006,

Otherwise the process is the same as in my previous post.

I still don’t know why they don’t support my card without all of this hoohah… IT IS TOP OF THEIR SHITTING MOBILE RANGE FOR CLIFF’S SAKE.

Oh well, works a treat now…

SQL Server Deployment Goodies…

I just spent most of the afternoon on a pointless keyboard puncher. I only wanted to move a SQL Server Express database from one place to another which is one of those things that should be straightforward but for one reason or another (which I won’t bore you with) it wasn’t and took me a few hours of messing about to get it to work.

So, it was with a mixture of delight and that feeling you get when you find something in the sales for half the price you paid for it last week that I read Scott Guthrie’s post about deploying Sql Server 2005 databases.

Microsoft are on the way to releasing a Database Publishing Wizard (RC1 is available for download now) which scripts both the schema and data of your SQL Server database.

They also provide an aspx page that you can use to install your db when you don’t have full access to the server.

That would have saved me a fair bit of bother this avo…

Free Anti-Virus, Anti-Spam and Redundancy for Small Business Email

Sorry about the mildly sensational title but I haven’t posted for a while and my traffic is going down the pan so I thought I’d spice it up a bit. That isn’t to say I’m not going to tell you how mind…

Just to get the acknowledgements out of the way I didn’t think of this all by myself but had it suggested to me by Steve at Convex IT. I thought it was a good idea so here’s what you do.

Lots of small businesses run MS Exchange or more likely MS Small Business Server at the end of an ADSL web connection. This is fraught with problems not least of which are managing anti-virus and spam and coping with the inevitable loss of connectivity. I looked around a while back for some sort of back-up mail server service but didn’t find much around.

What you need to do is:

Voila… you now have Google filtering your spam, checking your mail for viruses and holding on to your mail if your Internet connection goes tits up.

Your mail might not arrive quite so quickly as it did and this also isn’t going to be the best for large numbers of users but for small companies I think it is a good idea.

There will be those, you know who you are, who will question why there is a need to run a server at all instead of just using Google corporate mail. I think there are probably lots of reasons, having all company e-mail stored locally, shared folder, calendar sharing (I know Google has a calendar but I’m still not sure it is up to Exchange’s features quite yet.)

RSS My Last.Fm

  • An error has occurred; the feed is probably down. Try again later.