27 October, 2012

answer: squash stuffed with spiced rice, raisins, craisins, cashews, and honey

the question was: what does a vegetarian eat when it's cold out?

mmm... poppyseed bread

spent my day making spiced brioche dough for a couple of loaves of poppyseed bread. with all that poppyseed filling in my near future, i hope there are no surprise drug tests on the horizon. funny coincidence, the poppyseed/opium/drug test episode of seinfeld was on just last night

14 October, 2012

amping up the watij


I've been working on a grails webapp recently that I need to iterate on pretty quickly. Unfortunately the steps are getting more and more complex that have to be performed in each iteration. This weekend's project was an attempt to get a web-testing automation flow. No, not for deep QA or for extensive regression testing, I just want to be able to fire off some tests so I can iterate. In case you're wondering, this is on a mac.

I've looked around some and, to date, watij had the lowest bar to entry. So long as I had everything on the classpath that came with the watij webspec zip file, it seemed to work just fine. I wrote a shell script watij.sh to handle the dirty work:

export JAVA_OPTS=-d32
export CLASSPATH=$WATIJ_HOME/testlib/engine-gecko.jar:$WATIJ_HOME/

testlib/engine-ie.jar:$WATIJ_HOME/testlib/engine-webkit.jar:$WATIJ_HOME/
testlib/jniwrap-native.jar:$WATIJ_HOME/testlib/junit-4.8.2.jar:$WATIJ_HOME/
testlib/jxbrowser-2.5.jar:$WATIJ_HOME/testlib/log4j-1.2.15.jar:$WATIJ_HOME
/testlib/MozillaGlue.jar:$WATIJ_HOME/testlib/MozillaInterfaces.jar:
$WATIJ_HOME/testlib/mshtml.jar:$WATIJ_HOME/testlib/runtime.jar:
$WATIJ_HOME/testlib/slf4j-api-1.5.8.jar:$WATIJ_HOME/testlib/
slf4j-log4j12-1.5.8.jar:$WATIJ_HOME/testlib/tuxpack-0.2.jar:$WATIJ_HOME/
testlib/watij.jar:$WATIJ_HOME/testlib/webspec.jar:$WATIJ_HOME/testlib/
winpack-3.8.jar:$WATIJ_HOME/testlib/xulrunner-linux.jar:$WATIJ_HOME/
testlib/xulrunner-linux64.jar:$WATIJ_HOME/testlib/xulrunner-mac.jar:$WATIJ_HOME/
testlib/xulrunner-windows.jar:.

USAGE='
usage: watij <watijscript>.groovy [scriptargs ...]

        sets watij libs on classpath (based on WATIJ_HOME) and
        runs groovy-based watij scripts. All scriptargs passed
    on to the groovy call.

'
while [ $# -gt 0 ]
do
    case $1 in
        -h)
        echo >&2 "$USAGE"
        exit 1;;
        *)  break;;    # terminate while loop
    esac
    shift

done
if [[ $1 == *.groovy ]]
then
    groovy $@
else
    echo >&2 "$USAGE"
fi


Yes, that means you have to set an environment variable, WATIJ_HOME. Then, I also wanted to be able to write and execute my scripts from within vim as that is my primary development tool, so I added the following to my .vimrc:

command! -complete=shellcmd -nargs=* Watij call s:RunShellCommand('watij ' . expand('%:p'). ' ' . <q-args>)

function! s:RunShellCommand(cmdline)
  echo a:cmdline
  let expanded_cmdline = a:cmdline
  for part in split(a:cmdline, ' ')
     if part[0] =~ '\v[%#<]'
        let expanded_part = fnameescape(expand(part))
        let expanded_cmdline = substitute(expanded_cmdline, part, expanded_part, '')
     endif
  endfor
  botright new
  setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap
  call setline(1, 'You entered:    ' . a:cmdline)
  call setline(2, 'Expanded Form:  ' .expanded_cmdline)
  call setline(3,substitute(getline(2),'.','=','g'))
  execute '$read !'. expanded_cmdline
  setlocal nomodifiable
  1
endfunction

The RunShellCommand function was straight out of the vim tips wiki. It makes it so the output of a command is displayed in an extra window. The Watij command! statement makes it so I can execute watij against the script in the currently active editor window:


Just type :Watij <followed by args>
In this case, my script will launch bing because I added that as an argument
Now... after closing the groovy window with command-q, I see any printed output from the script in the scratch window in vim:
Now, just close the scratch window with :q

In a perfect world, I would like to create a homebrew formula for installing/configuring this and configuring the .vimrc. But... I need to get back to doing some work, so I just decided to blog about it for now.