Sunday, March 06, 2011

Cucumber DSL for Selenium Testing - Take 2

After poking around with Cucumber, Cuke4Duke and Selenium, I liked what I saw and started digging around for more interesting bits. I have moved from selenium 1 to Webdriver(Selenium 2).

One of the minor problems I have had so far is that the browser windows don't get closed after my tests completed.

I saw a number of attempts at solving this including having a tagged @After hook on the last scenario in the last Feature. None of them really jumped out at me until I read a question to the group and that led me to give a JVM shutdown hooks a go (equivalent to Kernel#at_exit in Ruby land). That seems to work quite well and lives well away from the features and steps making for cleaner code. It also means that we will have a clean suite of features that don't get polluted by technical detail.


Do take a look at the full thing on GitHub. Let me know what you think.


2 comments:

Anonymous said...

Just tried out your hook-solution. Didn't work out for me (running cuke4duke with FF under maven2) :-( Hook is fired after I close the browser manually.

So I came up with a tear-down thread, started on each @After szenario, shutting down the browser if no @Before is done within a defined time.

regards
Chris

LHFVille said...

Yeah its a bit strange. I found out painfully that it didn't work on Windows.

Wonder whether the error lies in Maven or in the shutdown hook functionality in Java.

I think I also like your @Before and @After solution. Have you got it in a Gist somewhere?