Archive for the 'development' Category

Writing Brittle (Yet Useful!) Acceptance Tests for ExtJS Applications Using Selenium’s getEval()

Friday, August 15th, 2008

I’m a somewhat enthusiastic fan of Selenium these days. It works consistently well in most situations, and it provides some mechanisms for “going deep” when its more regular API calls prove insufficient.

Recently, I was testing an application we’re writing that has a front-end built using the ExtJS framework. Normally, with a bit of XPath-fu, testing our (neatly!) tangled messmass of Javascript is no big deal, but occasionally, ExtJS produces a div or other element that Selenium just can’t seem to find. I ran into such an element (a div with a handler) that I *really* wanted to have my test click(), but no amount of XPath munging would get the job done. Perhaps Selenium is more strict about what elements are click()able than I thought, but no matter, getEval() to the rescue.

I found a number of interesting blog posts on the subject, with the best being Darren Deridder’s. This got me started on using this.browserbot.getCurrentWindow().Ext in the getEval()… the Ext object provides get() and getCmp(), which are gateways into basically any element in your application.

Of course, the one downside to this is that your effectively shortcutting the entire idea of acceptance testing, as your user-agent is now (but only briefly) doing something that your real end user wouldn’t do. I will only use this sparingly, I promise!

The end result are lines something like this in your testing code (C# here, broken up because our CSS won’t wrap it properly):

DefaultSelenium _selenium = new DefaultSelenium(
    "localhost",
    4444,
    "*iexplore",
    "http://localhost");

_selenium.Start();

String evalString = "this.browserbot.getCurrentWindow()."
evalString += "Ext.getCmp('my_component_id').items.get('some_subcomponent_key').doSomething()"

_selenium.GetEval(evalString);

You don’t even have to use the Ext object here… the scope this.browserbot.getCurrentWindow() is your application. The possibilities are endless, but remember the caveat: you’re doing something a real user-agent won’t, so be careful with this in an acceptance-testing scenario.

(Another thing to make the most of this technique is Firebug’s console.dir() function, which you can use while debugging to quickly examine object dumps.)

No Fluff Just Stuff, April 2008

Tuesday, June 17th, 2008

With forecasts of April snow, our 2Paths contingent of two headed off at the crack of dawn one Friday for Bellevue, WA to attend the No Fluff Just Stuff - Pacific Northwest Software Symposium (NFJS). Having only spent 10 minutes at the border (whew!), we arrived early enough in the Seattle area to fit in some Fluff (aka shopping and dining) before getting into the Stuff.

After a quick introduction by Evangelist Scott Davis, and with hopes of winning an IPhone by the end of the weekend, I headed right into his double-bill of sessions about Groovy. The first one entitled “Groovy, the Blue Pill: Writing Next Generation Java Code in Groovy” was a good gentle introduction to neophytes like myself on Groovy basics. Now that my interest was piqued, I was eager to continue on with Scott’s next session “Groovy, The Red Pill: Metaprogramming, the Groovy Way to Blow a Buttoned-Down Java Developer’s Mind”. Never mind the Blue Pill - the Red Pill is where it’s at!

Scott’s enthusiasm for Groovy was definitely contagious, and my mind started churning, trying to think of ways to start introducing Groovy into current projects or future projects at 2Paths. An allure of Groovy is that it’s a dynamic language and can be run on the JVM. Groovy is implemented in Java, so the two languages offer seamless interoperability. Groovy compiles down to Java bytecode, so Groovy code can call Java code, and vice-versa. This would make integration into our existing infrastructure much simpler.

The Blue Pill was starting to take effect, as Scott showed us the terseness of the language. No need to labouriously write getters and setters, amongst other many nifty language shortcuts. Who needs semicolons or parentheses anymore? Because Groovy really is Java under the hood, programmers unwilling to let go of that extra baggage can continue to use it and nothing will break. We were then shown demos on how much more quickly we could bang out Unit Tests in Groovy.

In the next session, the Red Pill stuff was pretty mind-blowing. Introducing method pointers, closures, the ExpandoMetaClass. Method pointers make our code more readable and understandable by allowing us to alias methods with semantics tailored to our own business logic. Closures are an exciting and powerful inclusion in Groovy that aren’t available in Java, allowing us to pass around executable snippets of code. And last but certainly not least, there’s the ExpandoMetaClass that lets us either do a lot of really cool stuff, or get ourselves into a heap of trouble. With the ExpandoMetaClass we can intercept methods and inject methods into any Class. Scott showed us some fun examples that got us all fired up wanting to try more!

With my introduction to Groovy setting the stage for the weekend, I went on to choose more sessions on Groovy (Design Patterns, Testing, Groovy with Spring), but also attended other sessions such as Spring Configuration, Regular Expressions, and GIS for Web Developers. I found most of the other sessions mostly affirming knowledge I already had, but augmenting it with good snippets here and there that were new to me. Venkat Subramaniam was the other main Groovy Prophet, and I came home with his book “Programming Groovy” in hand, eager to start integrating Groovy at least into our testing infrastructure.

The atmosphere at NFJS was inspiring, as the speakers all had great enthusiasm for the technologies they were touting, and the audience was generally equally as keen. It felt great to be in a large conference hall amongst so many other like-minded programmers, all sharing, and getting fired up about what we do, and our seemingly unlimited potential. I fully recommend NFJS (regardless of me not winning an IPhone), and would love the opportunity to go again!

Eclipse update, fix for home and end keys

Friday, October 19th, 2007

2Paths Eclipse Distro v2
I’ve put together a new disto of the latest Eclipse wtp with some added plugin goodness. I’ve found this version to be much more stable than v1, and it even works on Lorill’s machine without too much trouble. Among the new features is a regex tester plugin, and a filter plugin that allows you to run command line tools such as sed against a selection in the text editor.

Also note that I’ve put together a 2Paths preferences file that remaps the home and end keys in eclipse, and adds in the 2Paths code formatting templates. To import, once you’ve got the new eclipse up and running, select import and choose preferences.

Download Eclipse 2Paths Edition v2 (155.6MB)

Fix for home and end keys
If you’re anything like me, you are used to having your home and end keys go to the start of the line of text and the end of the line, respectively. The way OS X does it drives me insane, and I’ve finally found a solution that even fixes it in firefox: KeyFixer.

KeyFixer is a free utility that remaps those keys, there are 2 versions, the standard one that remaps it in OS X and most apps, and KeyFixer for Firefox which is self explanatory. I recommend installing them both if you want your home and end keys back.

Download KeyFixer (60KB)

Download KeyFixer for Firefox (80KB)

Seriously, No BullFluff

Friday, October 5th, 2007

Last week’s No Fluff Just Stuff symposium was undoubtedly the best Java event I’ve attended thus far, and the icing on the cake was Brian Sletten’s talk on “Beyond Cute-sy Mashups”. It was worth showing up for that alone. It’s not very often that it happens, but I’m stoked.

Below is my newly updated ‘Bleeding Edge Learning Curve Road Map’:

No Fluff Just Stuff

Friday, September 28th, 2007

The day started curiously as I was waiting for the 57, where I came across a quaint wannabe bus driver from Somalia. Naturally, I asked him why he had opted for life over here in Canada. “Here the supermarkets don’t sell bullets side by side with the vegetables”, was his honest reply. I never did get his name, but he did manage to leave an impression.

Anyhow, arriving at the square dusky-coloured Delta hotel, Barbie presented me with my name tag for this year’s No Fluff Just Stuff Western Canada Software Symposium. I inquired if it wasn’t necessary to register, at which she bluntly retaliated, “Are you lying about having paid? Well, you look like a honest guy, but nice of you to ask!”. Charming.

Scott Davis kicked off the show, and before we knew it, he had bewildered us Java techies with some Groovy magic. As his finale, he had Grails spooning off a fully-CRUD enabled web app in a split-second jiffy. Admittedly Grails does hit that sweet spot, which no doubt will have me succumbing to its allure, yet one growing pet peeve I have with it is that it does come with shackles of its own. For one, it imposes its own build tool, namely gant. But since, for better or for worse, most of us use maven as our build tool of choice, i would cast an early warning to the coders behind Grails - choice is key.

Thus, and surprisingly so, the much talked about shiny new toy didn’t earn my first merit, instead the honour went to a talk on Agile testing strategies. Jared, a likable confectionery-throwing speaker, not only talked a good talk, he also walked the walk. Test Driven Development (TDD) is a notion that has been much paraded about on the Agile front, yet until now I have remained skeptical. Until now, I didn’t fully take on board what its potential benefits could be. Enlightened, I now realize that by using TDD this has the knock on effect of it driving the design, hence driving the developer in keeping the code testable, which in turn keeps it simple, modular, and loosely-coupled. Genius.

And with that, I will finish off Day 1 with the quote of the day:
“I can’t fix stupid” ~Jared Richardson’s take on dumb developers.

Eclipse WebTools 2.0 Released, time to update your IDE

Tuesday, July 3rd, 2007

The Eclipse WebTools team has released version 2.0 of the WebTools Platform along with the rest of the Europa release. From the release announcement:

Eclipse developers will be particularly pleased with the debut of major features and/or specification updates to EJB3 JPA, JSP 2.0, JSF 1.2, Axis2 Web Services, Tomcat support, and source editing. This release also introduces Java EE 5 project support.

I’ve put together a new Eclipse bundle for everyone here at 2Paths. The package includes some useful plugins preinstalled (Subclipse, SpringIDE 2.0., JAutoDoc, and JSEclipse), as well as some performance and stability tweaks.

Download - Eclipse Europa 2Paths Edition (OS X, 155MB)

To ensure everyone is working with the same tools, you should configure your eclipse to automatically check for updates. This can be done by clicking on the Eclipse menu -> Preferences then Install/Update -> Automatic Updates.

If anyone has any problems with this release, just let me know and I can give you a hand getting things sorted out.

Sweet Online Reference Tool

Thursday, June 7th, 2007

Got API

Eclipse WTP 1.5.4 and 2.0RC1 for OS X

Monday, May 28th, 2007

I’ve downloaded and hand-configured the latest Eclipse WTP builds for your convenience. I’d included the Subclipse SVN plugin as well. If there are any other plugins you’d like to see by default in the future, let me know.

First of all, if you haven’t installed this update to the Java SWT libraries from Apple, do it now. It should improve stability with Eclipse.

Download: SWT Compatibility Update (188KB)

Eclipse WTP 1.5.4 is the latest update to the WTP 1.5 line. Not anything new, but contains numerous bug fixes etc.

Download: Eclipse WTP 1.5.4 (183.9MB)

Eclipse WTP 2.0 RC1 is based on Eclipse 3.3 RC1 and appears to be fairly stable. Some of the new features are support for Tomcat 6, support for JPA projects (annotations, , mappings etc), built in support for web services, and spell checking. This is pre-release, so use at your own risk (I’ve been using it and it seems ok, although I keep my 1.5.4 around just incase).

Download: Eclipse WTP 2.0RC1 (227MB)

Remember to update your copy of eclipse regularly to receive the latest bugfixes, or better yet, set it to auto update in preferences.