Thursday, July 7, 2011

Selenium IDE Sideflow Update 1

Once again, for your development pleasure, ladies and gentlemen, the famous Sideflow plugin for Selenium IDE!  Goto and while loops performed in Selenium, before your very eyes.

Some people were having a bit of trouble getting started, so I've updated the demo test for Sideflow (Selenium IDE flow control extension) to use the latest Selenese commands.


What's changed: no more direct access to 'storedVars'.  No more 'getEval'... uses 'runScript' instead.  Need to do some weird casting to perform counter increments.

The github repo is over here.  Everybody git on board the github train!

PS. You can find the original post here.

Wednesday, July 6, 2011

Spinnaker Set

We pulled off a perfect spinnaker set with a crew of first-time sailors, Canada Day long weekend. The weather couldn't have been more perfect!

Flying the spinnaker is challenging, and doing it with a crew of brand new sailors was interesting.  There's a real art to skippering a boat and helping the crew learn the ropes.  It's definitely taught me a lot about patience and leadership.

Monday, July 4, 2011

A simple introduction to TDD with Expresso in NodeJS

In the last post we made a super simple NodeJS module called hello.js and used it in app.js. We can make it better, and test it with Expresso.

First we can add to the awesomeness of hello.js by adding a farewell function, so it can say both "hello" and "goodbye".

// hello.js
var greeting="Hello World!";
var farewell="Goodbye Cruel World!";
var greet = function(){
    return greeting;
};
var leave = function() {
    return farewell;
};
exports.greet = greet;
exports.leave = leave;

So now our module can say hello, and bid farewell.  It exports the "greet" and "leave" functions, which we can use from app.js like so:

// app.js
var hello=require('./lib/hello.js'); 
console.log(hello.greet());
console.log(hello.leave());

Notice that I moved hello.js into a new directory called "lib", which is why the require statement now says "require('./lib/hello.js')".

Now suppose we want to test this module using expresso.  Since expresso is a command-line utility, we should install it globally:

npm install -g expresso

Now we can write a test.  First we make a "test" directory and then create a file called "hello.test.js".

mkdir test
vi test/hello.test.js

// test/hello.test.js
var assert = require('assert'),
      hello = require('hello.js);

module.exports = {
    'greet()': function() {
        assert.equal('Hello World!', hello.greet());
    }
};

This just requires node's built-in "assert" module for unit testing, plus our hello.js module that we want to test. Then, it defines a test to make sure that when we call "greet()", the response is "Hello World!". Alright! Now we can go back to the parent directory (where app.js lives) and run expresso. We tell it to look in the "lib" directory for hello.js. Expresso already knows to look in the "test" directory for tests, and will run everything it finds there.

$ expresso -I lib

    %100 1 tests

Wonderful.  Only, we didn't test the part where we say goodbye. Expresso has built-in code coverage reporting that we can enable with the "-c" flag:

$ expresso -I lib -c

   Test Coverage

   +------------------------------------------+----------+------+------+--------+
   | filename                                 | coverage | LOC  | SLOC | missed |
   +------------------------------------------+----------+------+------+--------+
   | hello.js                                 |    87.50 |   10 |    8 |      1 |
   +------------------------------------------+----------+------+------+--------+
                                              |    87.50 |   10 |    8 |      1 |
                                              +----------+------+------+--------+

   hello.js:

      1 | 1 | var greeting = "Hello World!";
      2 | 1 | var farewell  = "Goodbye Cruel World!";
      3 | 1 | var greet = function() {
      4 | 1 |    return greeting;
      5 |   | };
      6 | 1 | var leave = function() {
      7 | 0 |    return farewell;
      8 |   | };
      9 | 1 | exports.greet = greet;
     10 | 1 | exports.leave = leave; 

Cool. It tells us we haven't tested the part about leaving with a farewell. All we have to do if we want 100% code coverage is to define a test for "leave":

// test/hello.test.js
var assert = require('assert'),
    hello = require('hello.js');

module.exports = {
   'greet()': function() {
       assert.equal('Hello World!', hello.greet());
   }, 
   'leave()': function() {
       assert.equal('Goodbye Cruel World!', hello.leave());
   }
};


And now when we run expresso again, we should have 100% code coverage.

$ expresso -I lib -c

  Test Coverage

   +------------------------------------------+----------+------+------+--------+
   | filename                                 | coverage | LOC  | SLOC | missed |
   +------------------------------------------+----------+------+------+--------+
   | hello.js                                 |   100.00 |   10 |    8 |      0 |
   +------------------------------------------+----------+------+------+--------+
                                              |   100.00 |   10 |    8 |      0 |
                                              +----------+------+------+--------+

   hello.js:

      1 | 1 | var greeting = "Hello World!";
      2 | 1 | var farewell  = "Goodbye Cruel World!";
      3 | 1 | var greet = function() {
      4 | 1 |    return greeting;
      5 |   | };
      6 | 1 | var leave = function() {
      7 | 1 |    return farewell;
      8 |   | };
      9 | 1 | exports.greet = greet;
     10 | 1 | exports.leave = leave; 

Cool, eh?

Expresso offers several other assert functions that you can find in the documentation here: http://visionmedia.github.com/expresso/.

Sunday, July 3, 2011

A simple intro to NodeJS modules

In preparation for an upcoming workshop at Shad Valley on NodeJS, I tried to come up with some simple examples of the CommonJS module system in NodeJS.  Felix Geisendörfer has a similar "hello world" example in his Node.js Beginner Guide.  I've put the main concepts into a short tutorial. We start with one line of Javascript, and turn it into a working NodeJS module.

Assuming you have node installed, you can run "node" from the command line to get the REPL (ie. node shell).

$ node
> console.log("Hello World!");
Hello World!

Wonderful. How about putting this in a file?
// hello.js
console.log("Hello World!")

Then run:
$ node hello.js
Hello World!

Also wonderful. Then, how about making an application that includes hello.js? Let's call it app.js. Here are the two files:

// app.js
require('./hello.js');

// hello.js
console.log("Hello World!");

Now we can run it like this.
$ node app.js
Hello World!

Again wonderful. We've written a module. Not a very fancy one, but it's a start. Now, as an aside, suppose we want to run app.js like a shell script, without specifying "node" on the command line all the time? Simply add the node command to the app.js script:

#!/usr/bin/env node
// app.js
require('./hello.js');

Oh, and make it executable.
chmod u+x app.js

Now we can run it like so:
$ ./app.js
Hello World!

Now we can begin having fun. The thing about modules is that whatever you declare in the module (hello.js) is local to that module. If you want to use it externally, you have to add it to the special variable "exports":

// hello.js
var greeting = "Hello World!";
var greet = function() {
   console.log(greeting);
}
exports.greet = greet;

#!/usr/bin/env node
// app.js
var mygreet = require('./hello.js').greet;
mygreet();

This accomplishes the same thing, but take note of a couple things. First, "var greeting" is not available outside of the hello.js file. The function "greet" is available though, because we added it to exports. So that's how you get variables, functions and objects to be available from your module. Easy peasy.

Saturday, June 11, 2011

Smile

Reading articles on multi-core scaling while listening to a new track from Jamiroquai - "Smile" - available as a download from http://soundcloud.com/jamiroquai1/jamiroquai-smile. It's pretty good - even if you're not into software design for multi-core, multi-cpu computer architectures. :-)

Wednesday, June 1, 2011

Windows 8 gets on the Web Stack Bandwagon

I'm a Mac / Linux guy, but it's good to see Microsoft putting some serious work into the user experience in the Windows 8 preview.  What's cool about the video on that link is that they've also seen the light when it comes to the developer experience, paving the way for rapid application development by leveraging the web stack of HTML5 and JavaScript.  A long way back I wrote about  "Gödel, Escher, Bach" to explore the link between artistic creativity and great engineering work - how a love of technical complexity drives some developers, compared to a love of elegance and simplicity that drives another kind of developer.  While technical complexity enamors the uber-geek, artists are inspired by technology that gets out of the way and allows them to do what they do best - create stuff.  Even though a web stack wouldn't be my first choice for some kinds of apps, it's just fine for a whole lot of them, and when it comes to rapid application development its way, way up high on the list of best options.

It seems like in the midst of Apple's incredible growth in the mobile, laptop, and tablet space there's been a lot of soul-searching going on at companies like Nokia, Microsoft, RIM, and many others.  A dominant theme that keeps coming up is "simplicity".  For example, see "Why Dropbox beat Syncplicity".  By embracing web technologies for app development  Microsoft is taking a forward-looking step towards simplicity in application development.  Hopefully this means standards-based web technologies and not the embrace-and-extend, proprietary model we have come to expect from Microsoft.

Things all seem to be moving in this direction.  RIM has a platform for building apps on web standards for the Blackberry.  The iPhone has had "web apps" for a long time.  And recently I've run into more people who are excited about Nitobi's PhoneGap, a technology I reviewed a few months ago (PhoneGap and jQuery Mobile First Impressions) which let's you build apps for 6 different smartphone platforms using standard web technologies

I think I just set a record for cross-linking to my own posts!  To make up for it next time I'll post a bunch of external links to cool stuff from the interwebs.

Monday, May 16, 2011

get path in bash

When running a bash shell you might want to find files and directories relative to the path of the script. The use of 'pwd' in this case can lead to problems if the script has been run from another directory. What you need is the absolute path of the script being executed. Here's an example of how to do it. This works on most Linuxes but unfortunately is not supported on Mac OSX.

Productivity and Note-taking

I told a friend of mine that I wasn't really happy with the amount of time that gets taken up by Slack and "communication and sched...