Tuesday, April 08, 2008

Annealing a sword

OK, here is a good reason why I am not a swordsmith:


In case you're wondering what he's doing, it's annealing, the process of softening the metal so it can be re-worked (in this case ground).

Monday, April 07, 2008

Drinking the Watir

I've been using Watir recently to help automate integration tests for some of our client projects. Moving from a Windows XP to a Windows Vista environment proved more troublesome than I had realised it would be, however I now have my test environment all working and last Friday night realised some value from the automated tests as they (very) quickly ran through a complicated series of steps to prove an important piece of client functionality after a server upgrade, thus allowing me to get home earlier than expected.

For the benefit of my fellow Elcomites I'm going to document the steps required to setup Watir on a brand new Vista machine.

Pre-Requisites

Firstly, as I pointed out previously, you can't have Office Groove 2007 installed. Also, you need to be able to run as Administrator on your local machine.

Install Ruby

You will want Ruby 1.8.5, and fortunately there is a one-click installer for Windows, which you just need to download and run. By default this installs under C:\Ruby\ and includes RubyGems (which makes installing other Ruby stuff dead easy).

Having done this, let's test whether we have a fully working Ruby installation by running irb (the interactive ruby shell). Open a command window and type the following:

C:\Users\angus>irb

In Vista this prompts you with the message "An unidentified program wants to access your computer", identifying the program as ruby.exe with the option to Cancel or Allow. Obviously we want to Allow this (note: you won't get this message if your UAC settings are different to mine). It will then open a new command window with the following text shown:

irb(main):001:0>

Just getting this far tells us that Ruby is installed. Close both the command windows you have open.

Install Watir

Installing Watir is as simple as starting another command window and then typing in the following command:

C:\Users\angus>gem install watir

We then want to do the same for the windows-pr library that provides access to various Win32 APIs and is needed in Vista to run Watir.

C:\Users\angus>gem install windows-pr

We can then open irb again and see if we can test Watir from the command-line!

irb(main):001:0> require 'watir'
=> true

This tells Ruby that we are using the Watir namespace (like Imports in VB.NET or using in C#.NET)

irb(main):002:0> include Watir
=> Object

This actually mixes in the Watir library with our code (essentially making it available to us).

irb(main):003:0> ie = Watir::IE.new
=> #<Watir::IE:0x4a50e70 @url_list=["about:blank"], @ole_object=nil, @rexmlDomobject=nil, @logger=#<Watir::DefaultLogger:0x4a50d94, @progname=nil, @logdev=#<Logger::LogDevice:0x4a50d30, @mutex=#<Logger::LogDevice::LogDeviceMutex:0x4a50d08, @mon_entering_queue=[], @mon_count=0, @mon_owner=nil, @mon_waiting_queue=[]>, @dev=#<IO:0x32d7320>, @shift_size=nil, @shift_age=nil, @filename=nil>, @formatter=nil, @default_formatter=#<Logger::Formatter:0x4a50d58 @datetime_format="%d-%b-%Y %H:%M:%S">, @level=2>, @activeObjectHighLightColor="yellow", @down_load_time=0.413, @speed=:slow, @typingspeed=0.08, @page_container=#<Watir::IE:0x4a50e70 ...>, @ie=#<WIN32OLE:0x4a50e0c>, @error_checkers=[], @defaultSleepTime=0.1>

Whoa! Did you see that Internet Explorer window open up? This is the litmus test for Watir, this line opens a new IE window and assigns a reference to it to the ie variable.

irb(main):004:0> ie.goto('http://ww.google.com.au')
=> 2.206

We can now start playing with the open window, firstly by browsing to the Google (Australia) website ...

irb(main):005:0> ie.text_field(:name, 'q').set('Elcom Technology')
=> true

... entering a search term ...

irb(main):006:0> ie.button(:name, 'btnG').click
=> 1.045

... and then actioning the search. There is a lot more that Watir allows you to do, but this is a good start!

Install Aptana Studio

Editing Ruby scripts in Notepad is a chore, and whilst Visual Studio will eventually support Ruby the current Sapphire in Steel IDE doesn't excite me (the free version is still just an alpha release). Enter Aptana Studio, which has absorbed the old RadRails IDE project and which has a stable, and free, Community edition. Amongst other features this gives us Ruby colour coding and an integrated test runner - great for Watir!

Aptana Studio is built atop the open-source Eclipse IDE for Java. This means that other Eclipse plugins are also available. It also means your machine will end up running Sun's Java. It comes with a Windows installer to make things easy and is a free download.

Once you have run the installer you will want to edit the properties of the studio exe so that it runs as administrator.

Aptana

You can now run Aptana Studio and choose to install the Ruby on Rails plugin from the start page:

Aptana Start

Create your first test script ... here is that sample we ran before, but this time the way you might typically create a test file:

##########################################################

# Integration Test Sample

##########################################################

# This demonstrates the skeleton of an integration test.

##########################################################

 

require 'rubygems'

require 'test/unit'

require 'watir'

require 'watir/testcase'

 

class IntegrationTest < Watir::TestCase

    # Runs before each test case, e.g. used to specify login details.

  def setup

    super

  end

 

  # Runs after each test case, e.g. could be used for logging, etc

  def teardown

    super

  end 

 

  # always the first test as it sets up the browser object

  def test_first

    # Create a new browser instance (running this opens IE)

    @@ie = Watir::IE.new

    @@ie.speed = :fast # comment this line if you want to more easily see what is happening

    @@ie.maximize

  end

 

  # reproduce our irb test

  def test_google_elcom

    @@ie.goto('http://www.google.com.au')

    @@ie.text_field(:name, 'q').set('Elcom Technology')

    @@ie.button(:name, 'btnG').click

  end

 

  # always the last test, closes the browser object 

  def test_end

    @@ie.close

  end

end

 

By right-clicking in that file and choosing Run As > Test::Unit Test (see below) you can run the tests within the Aptana test runner.

RunAs

That gives you a nice test result tree that shows exactly where things fall over (when they do).

You are done! Now I am pretty sure that people are going to find problems I haven't documented. If you do, then please feel free to add a comment with your difficulty and I'll update this main post with the solution.

8 little known things about Falkayn

Anthony tagged me with this old meme. Here are the 'rules':

  1. Each player starts with eight random facts/habits about themselves.
  2. People who are tagged need to write a post on their own blog (about their eight things) and post these rules.
  3. At the end of your blog, you need to choose eight people to get tagged and list their names.
  4. Don’t forget to leave them a comment telling them they’re tagged, and to read your blog.

So here are 8 little known things about me:

  1. World traveller
    My Dad's work always took him around the world. That led to my family living in New Zealand, the USA, Canada, the UK and back home in Australia. By the time I was 10 years old I had travelled around the world roughly 5 times (and I've done it another 4 times since then).

  2. Sailor
    In 1986 I did the Sydney to Hobart yacht race. As one of the few Category One ocean races in the world it was a challenge, especially as I was just a teenager. I sailed with my Dad on his boat Dreamtime, and he made sure I trained properly. So it was a half mile swim every morning before school that year, a training sail midweek and then weekend ocean races, with me completing the mandatory two overnight races in the lead up to Boxing Day.

    It was a tumultuous 4 days with gale force winds, rough seas, a crew that was only half experienced and cold, wet conditions. As my Dad had intended it was a watershed moment for me - I ran the mainsheet and at one stage we were in a death roll whilst skimming down the Tasmanian coastline, and I had to ignore panicked commands from my fellow crew (men in their 40s!) and just listen to what my skipper (Dad) was telling me to do.

    I survived that race (and the return sail), but it was quite a few more years before I could be convinced to start ocean racing again. However, I helped my Dad move his new boat, One Step Ahead, from Pittwater to Sydney Harbour a few weekends ago, and you know what? It felt pretty good being out on the water again, and it's not many guys who can say they've "sailed with my father, man and boy, these twenty years".

  3. Bent middle fingers
    The last joint on each of my middle fingers is bent outwards slightly. It's something to do with the angle of the joint because they seem to straighten up when they bend. Weird, huh?

  4. Hate sandals
    Sorry but closed shoes are what I prefer - even on hot days. Having said that, living closer to the beach has caused me to actually buy a pair of thongs.

  5. Love to cook
    It seems to be something about the physicality of cooking, along with the appreciation for good results, that makes me love cooking. I'm not a fast cook, but there is nothing more relaxing after a hard day's work than taking an hour or two to turn out a nice meal. Of course you sometimes have to knock up something edible out of minimal ingredients with 20 minutes notice - that's definitely less fun.

  6. Chlorine blind 
    One family holiday in Spain when I was very young my Dad tried to help me learn to swim with my eyes open underwater. It was a pretty successful day, with me triumphantly announcing I could now swim underwater. However I woke up the next morning unable to open my eyes due to an allergic reaction to the (massive) amounts of chlorine the hotel had dumped in their pool. I've been a firm believer in swimming goggles ever since!

  7. Skiing a white Christmas 
    I spent the bulk of my childhood living in the UK, and one of the (few) nice side-effects of that was my family being able to take holidays in Europe very affordably. The best ever holidays turned out to be ones we had around Christmas when my Dad took us to Lech, Austria for skiing trips (it wasn't quite so exclusive then). We would go for two weeks at a time, and spend the first week re-acquainting ourselves with the sport and the second week revelling in the fantastic snowfields of the region.
    100259289_458867cb28 
    My fondest memory is of getting woken up just before midnight on Christmas Eve to gather at the local church, sing Carols and watch the midnight torch run, local ski instructors snaking down the mountain in lines, carrying burning torches to light up the dark. There's something spectacularly appropriate about all that fatty Christmas food that suits cold, snowy places - somehow 35 degree Centigrade sweaty Christmas days in Oz better suit cold seafood and salads.

  8. Swordsmithing
    Back in my university days I hung out with a bunch of friends who were all into roleplaying games, and hence swords, armour and pretty much all sorts of historical military goodies. We were also into martial arts, especially Japanese ones (I did Judo). One of the guys had a book on Japanese swordsmithing, which we pored over. I had topped my year at school when it came to Design & Technology, and I fondly remembered standing over the forge bashing out some metal.

    I remember dreaming what I would like to do in the future and imagining the perfect blend of natural environment, zen-simple lifestyle and heady success. For me that seemed to be an Austrian chalet on a mountain in New Zealand, with a fully kitted out forge in the back and international customers waiting for one of my original katanas ... since then I've had a friend actually take up blacksmithing, specialising in historical reproductions of weapons (spears, swords, etc). As is often the case the reality turned out to be far more prosaic and boring than you imagine.

So there's 8 (reasonably) useless facts about me. In the spirit of this whole meme I'm going to tag eight other bloggers to follow on:

Monday, March 31, 2008

Great new laptop, but woes with Vista

dell-xps-m1330Life seems full of swings and roundabouts, or if you like, ups and downs. So I have been getting used to my shiny new Dell XPS M1330 laptop and enjoying the unbridled pleasure of being able to work when mobile. But at the same time I have been discovering how little Vista loves developers, or at least the software tools I'm using to develop in.

The problems I've had have been numerous, but I'll restrict myself to describing the ones I've got an answer for.

  • VS2008: Must run as admin
  • Indexing Service is now legacy code and not installed (by default)
  • IIS6 metabase and configuration compatibility (see here for more info)
  • Watir needs windows-pr (gem install windows-pr)
  • Watir conflicts with Office 2007 Groove
  • IIS7 suffers from the same 'usability facelift' woes as does Office 2007
  • Explorer keeps crashing ... actually I don't have an answer for this one

In addition I set the ruby.exe and rubyw.exe files to run as admin and did the same for Aptana Studio and java.exe. That was on the way to finding out that the Groove DLLs had some sort of conflict with Watir/Ruby. I also set nearly everything to run in Windows XP SP2 compatibility mode and disabled UAC along the way.

As usual, once you have everything up and running you forget about your setup woes, however the near constant Explorer crashes are getting on my nerves. It's especially frustrating when you have 2 or 3 Explorer windows open to various important directories (some on other machines) and then have Explorer crash because you opened Control Panel ...

explorer-crash 

UPDATED: Added link for IIS metabase issue.

Tuesday, March 18, 2008

They're just making it up ...

In Sydney for Sun's TechDays James Gosling (his blog), creator of Emacs and Java (you might have heard of it), has a chat with the SMH:
“People you think are oracles of wisdom - they're just making it up.”
Preach it bro' ...

Monday, March 10, 2008

It's the software that matters!

James Shore, creator of NUnitASP and author of The Art of Agile Development has recently announced that he's no longer supporting NUnitASP development, citing his increasing lack of interest in it and pointing interested parties to Selenium or Watir (or perhaps WatiN, although that has received some criticism from Scott Bellware, others are not so sure).

It's a shame we're not getting more choices in this area of testing, but James is right to focus on his own current projects. He has left it open for someone else to take over the project, although the way ASP.NET MVC will expose HTTPRequest as an interface might make it superfluous.

Back to the point of this post. James has a great blog with some very thoughtful articles. I found this great quote in It's the Software, Stupid! It summarises for me the problem with simply implementing Scrum and thinking that makes you Agile.
“your team is expected to self-organize and define its own practices”
“It's time we brought back the early emphasis on great engineering practices. If you're using Scrum or another agile method that doesn't include engineering practices, realize that your method is incomplete. Scrum, for example, intentionally creates an environment in which your team is expected to self-organize and define its own practices. If you aren't doing that--if you aren't talking about engineering practices, what's working, what's not, and how to improve--you're going to run into trouble someday. Probably someday soon.”

Thursday, March 06, 2008

Are VB's XML Literals an XSLT killer?

The VB Team have released the first in a series of XML Cookbook recipes. This one covers how you can use VB's new XML literal support in Visual Studio 2008 to replace the W3C's rather cumbersome XSLT (eXtensible Stylesheet Language Transformations) language with much simpler VB code.
“To sum things up, we’ve seen how Visual Basic, XML Literals and LINQ can be used in place of the <xsl:copy-of>, <xsl:for-each>, <xsl:template>, <xsl:if>, <xsl:value-of>, and <xsl:attribute> elements as well as using XML Axis Properties in place of XPath to create a powerful, yet simple tool for XML transformations.”
As someone who once developed a web site completely using Java servlets spitting out XML data using XSLT files to transform that into web pages, I've got to say that anything that gets us away from XSLT is a good thing. The way you can use LINQ to query the XML data is inspired, and this has the potential to make VB the language of choice for developers needing to glue together SOA.