Talking testing, agility and automation... and anything else.

Nov 14

Screencast: Protractor Test Automation Framework Example Code

I’ve been playing around with Protractor, a great, new(ish) testing framework from our friends at Google. I’ve shared my example code on GitHub for those that might be interested in such things.

Examples in the code include:

  • Using page objects
  • Running on TravisCI
  • Running tests on Sauce Labs and Browserstack
  • Running multiple browsers at once

I’ve also made a quick screencast that walks you through downloading and running the example code.

Cut to the chase, in the video we:

  • Install Node (okay, I don’t show this but you need do to it!)
  • Download the example code from GitHub
  • run npm install to install the project dependancies
  • Briefly discuss a config file
  • run protractor conf.js to run the tests

Jan 14

Spock: Test Framework With Creamy BDD Center

spock[1]Two things I’m willing to admit:

  1. I think it’s a bad idea to dismiss tools prematurely
  2. I think most BDD tools are crap

Delicious hyperbolic contradiction aside, it would probably be more accurate (and PC) to say I’ve yet to work in a situation where using tools like Cucumber or JBehave would make sense. I.e. these tools just don’t compliment my, or my team’s, workflow.

Enter Spock. Spock is a testing framework for Java/Groovy, that is very similar to JUnit, but also adds BDD-friendly specification, baked right in. With Spock, there’s no need to maintain a separate feature or spec file; no weird broken-English language to learn. Your code is the spec and the end result is clean, readable and maintainable.

Case in point: the following is a Geb test, written in Groovy and using Spock. This is working code from my geb-example project on GitHub.

This test, from my CLSearchTest class, which tests searching on Craigslist (had to use something :) ). With that in mind, the code above is probably very readable to just about anyone. I’ll break down what’s going on a bit…

We start by defining our test: 'searches with few results offer nearby results', which is also our method name. Method names are string literals (can have spaces).

Next we have Spock’s built-in code blocks, labeled given:, when: and then:. These three blocks represent the different phases of a test. Each block can also include an optional description to help with readability. A bit about each block:

  1. given: (optional): Think of this block as a setup. It gives you the optional ability to specify state.
  2. when: (required): This is where the meat of your test code will go. You can have multiple Whens and Thens but they must be used in pairs.
  3. then: (required): This block is for asserts. All code in this section must return true or your test will fail. This gives your reader an easy way to see what the test is actually testing!

This just scratches the surface of Spock’s offerings. You of course get a full boat of annotations (including my favorite, @IgnoreRest) and fixture methods, additional blocks, etc… Plus it runs anywhere JUnit runs.

Don’t get me wrong, the principals of BDD are sound but I want tools that work the way I do, not the other way around. When using Spock along with Geb’s page object pattern and selectors, and Groovy’s fabulous syntax, the resulting code is both elegant and readable. YMMV…

Feb 13

Amazon EC2 Ubuntu HowTos

ec2Having a server in the cloud is a nicety. That Amazon gives you one free for a year to tinker with… that’s being downright friendly!

The following are some notes/howtos for setting up an Ubuntu Amazon EC2 instance. I post them to help me remember them but they might also be useful to others…

Allow SSH Access

If you’d prefer to just ssh into your instance instead of using key/pair…

1. Login using the key/pair you created when setting up your EC2 instance:

2. edit your sshd_config file and uncomment and/or set PasswordAuthentication yes:

3. Reload SSH:

4. Create a new user and set the user’s password:

Install LAMP

1. Update Ubuntu’s package database, install and run Taskel. Select the LAMP server (don’t deselect anything that is also checked) and let it install:

2. Install PHPMyAdmin; select Apache2, enter a root password and say No to config the database later:

3. Verify by going to: http://myIPaddress/phpmyadmin and login as root with the password you entered. Of course you’ll probably want to secure/move this!

Install XRDP on Ubuntu 12.10

Installing X11 on your instance–should you be so inclined–may prove tricky… I tried MANY ways of doing it (OpenBox/FluxBox, VNC, etc…) but each attempt ended in failure. I found victory with XRDP!

1. Found from the instructions here. First install Gnome (will take a while)…

2. Ubuntu 12.10 no longer includes gnome-session-2d, so install fallback and edit .xession to use it:

3. Edit Xwrapper file and set allowed_users=anybody:

4. Create a new Security Group Rule for RDP(i.e. open port 590x (where x is the vncserver id))

5. Install RDP client on your local machine…

Install Chromium brownser on Ubuntu 12.10

FireFox is in need of Unity by default and it appears it doesn’t exist on 12.10. I wanted Chrome on there anyway but it didn’t work either. Chromium does:

Feb 13

Adding Copy Filename and Copy Path to Sublime Text’s Sidebar

Sublime_Text_Logo[1]My text editor of choice is Sublime Text but right out of the box, it does not include copy filename or copy file path in the sidebar (both of which I use constantly). Seems that whenever I install it on a new machine (which I just did) I forget how to install the Package Control package, which offers such goodies. Therefore, I thought I would park the instructions here for your–and more importantly, my–convenience.

It’s pretty easy…

  1. In Sublime Text, type ctrl+` to access the console
  2. Copy the code below, paste it in the console and hit return
  3. Restart Sublime Text

Now, when right/ctrl-clicking a file or files in Sublime Text’s sidebar, you should see a wealth of options including copy path/name.

If for some reason this fails to work, you can download and install manually with the instructions here…

Now that you have Package Control installed, use it by typing shift-ctrl-p. You can then, as you might imagine, control Sublime packages. Eg. install, remove, etc…. My two must-haves are: SideBarEnhancements and All Complete. To install them:

  1. Click shift-ctrl-p
  2. Start typing “install” and select Package Control: Install Package
  3. A package prompt appears; start typing the package name, eg. All Auto Complete

That’s it! Just repeat these steps for each package you’d like to install.

Feb 13

I Heart My Chromebook – A Review

chromebookI’ve always been a fan of smaller laptops (my 13″ Macbook is a personal fav) so when Google released their Chromebooks, they had my attention. I eventually couldn’t resist and picked up the Samsung, arm-based Chromebook XE303 for the extremely reasonable price of $249.

After having a couple weeks on it, I must say I really REALLY like it. It’s been shockingly easy to abandon my Macbook in favor of my smaller, lighter Chromebook. In fact, there’s very few things in my daily (non-work) routine that I can’t do on the Chromebook… Chrome Remote Desktop solves the rest.

What’s good:

  • Price!
  • The keyboard and trackpad are great and responsive
  • Battery life – @4.5 hours video; @6.5 hours surfing/etc…
  • Small and light
  • Boots in seconds; wakes instantaneously
  • ChromeOS is simple, intuitive and impressively powerful
  • Chrome Remote Desktop bridges most gaps
  • Overall design is very “Mac-like”
  • Many great, free apps/extensions
  • Setup. If you use Google/Chrome, once you sign in, all your stuff is already there

The bad:

  • The screen is kinda crappy… though certainly servicable
  • Lack of AirTunes equivalent… Google, please make this happen!
  • Lack of full *nix shell is bothersome
  • Power adapter is clunky; wish it was micro usb

One thing that might put ChromeOS over the top for me (and I’m sure I’m not alone) is to allow access to its underlying Linux distro. Like OS X, ChromeOS is just a window manager on top of unix (in this case Linux). I would love to see them continue the trend and allow access to it’s Linux underbelly. In short, give me a full shell!

Long story only slightly longer, this Chromebook is a keeper and has me thinking devious thoughts about selling the Macbook and in its stead, getting a Mac Mini server to command via CRD! And I guess I’ll need a new signature… something like:

Written on my Chromebook… or maybe not (even if it is true).