Watir Script Integration with javaCruiseControl - Testing Java App.

22 views
Skip to first unread message

watirpuppy

unread,
Dec 11, 2008, 2:17:46 PM12/11/08
to Watir General
Greetings,

I searched the group posts and found one about CruiseControl
Integration, but it's from 11/27/2007 - just over a year old n' I
can't reply to it.. So resurrecting the issue in hopes to get more
contemporary info. and provide more concrete examples on this journey
through the process.

I am implementing Watir for automation testing of a java web app. w/
CruiseControl (java version) in the mix.

Looks like getting CruiseControl to run the Watir scripts should be
straight forward enough - either via Ant or <exec>. If there are
any particular reasons to using one or the other, I'd appreciate any
feedback?

Seems like the next biggest challenge is to get the Watir script
results into the jUnit XML format so that CruiseControl can consume
them. Bret has indicated ci-reporter is the gem to use that'll format
the reports properly. Tracing backwards from ci-reporter, sounds like
it's best to use a Rakefile in the process chain.

I've come to the crossroad on wether to use "rspec" or "test-unit" to
write the actual test cases. This will make a bit of a difference in
how it gets coded. First glance, it looks like test-unit is more
straight forward but am still real interested in hearing if rspec is
better in practice. Again, any input would be appreciated.

It's a good time to start a Watir script library - considering the
latest release and Watir::Browser.default.
Very nice.

Thanks much,
Hope to hear from you.

MichaelT

watirpuppy

unread,
Dec 12, 2008, 2:51:03 PM12/12/08
to Watir General
I came across a post where Charley Baker provided this great example
of exporting testcase results to the xUnit XML format:
<><><>
require 'test/unit'
require 'ci/reporter/rake/test_unit_loader.rb'
require 'watir'

class My_Test < Test::Unit::TestCase

def test_me
browser = Watir::IE.start('http://www.google.com')
assert(browser.link(:text, 'About Google').exists?)
browser.close
end

end

This will dump the xml file to the directory where the test is run in
test/reports/TEST-My-Test.xml
<><><>

That's it?! I was well on my way to making this WAY TOO
COMPLICATED. Thanks Charley!
After reading a bunch of documentation I thought it would roll out
more like:

CruiseControl > Rakefile with the ci-reporter method calls > Watir
scripts > results to XML > consumed by CruiseControl

Whew... sure glad that got worked out.

Have decided to start coding the scripts with the "test-unit" gem/
module. Just seems to expose more about what's actually going on and
probably
better for the learning process right now.

IMHO, 'rspec' seems to obfuscate which assertion is being employed and
where.
But I can see that rspec may offer an easier path to accessing deep
HTML elements (but so will watirs' xpath).
That's another question. rspec v.s. xpath?
It appears the good news is that either way, test results get fed to
the XML file..

Yesterday, I got a good start on scripting some smokeTests and have
multiple testcase methods sending results to the XML file.
In one afternoon I jumped ahead of my dev. team a little bit.

More to follow on the details of the CruiseControl Integration
piece.
I should be able to simply drop one of my result XML files into the
project (location?) and verify it's data gets expressed on the
dashboard.

Good times..
MichaelT


watirpuppy

unread,
Jan 6, 2009, 4:01:25 PM1/6/09
to Watir General
F/U on this part: (n' I don't want this string to
go stale yet)

"I should be able to simply drop one of my result XML files into the
project (location?) and verify it's data gets expressed on the
dashboard."
=======
Not exactly..
CruiseControl outputs a build log with each new build event/iteration
e.g. log19090105184958FF3333.xml
The logs are usually located under the CCinstallDir\logs\projectName\

The Watir test result data has to exist in the most recent build
log.
Just copy the <testsuite> section of the watir results xml file to the
bottom of the CC build log file, inside the </cruisecontrol> section.

All the results will appear in the CruiseControl Dashboard, under the
'Tests' tab of the project build page.

I did this just to verify the watir xml results were compatible with
our implementation of CC.
Right now, I'm guessing that when CC actually runs the scripts it'll
somehow suck in the result data automagically and add it to the CC
build log.

More to follow.
MichaelT

watirpuppy

unread,
Jan 7, 2009, 2:14:02 PM1/7/09
to Watir General
As mentioned above, the watir test result data needs to be "merged"
with/into the CruiseControl build log XML file.
This gets configured in the CC config.xml file with the <merge>
element - imagine that!.. (documented on the CC website).
e.g.
<log>
<merge dir="C:\blah"/>
</log>

Any watir result xml files found in the configured <merge dir="blah"
> location (or other xml "artifacts") will be merged into the CC build
log and will then show up on the CC dashboard. I've notified my dev
team of my intention to hijack the <merge> element in the CC
config.xml file.

And that covers the details of getting the watir result data onto the
CC dashboard.
<><><>

To get CC to run the watir scripts, the <exec> element works fine (at
least as a jumping off point).
Depending on how the build target stuff is configured for the
<schedule> element in the CC config.xml file, the <exec> can be
included with the build target call.
e.g.
<schedule>
<maven2 mvnhome="C:/blah" pomfile="blah/pom.xml"
goal="clean install" />
<exec command="ruby" workingdir="C:\WatirScripts"
args="SmokeTest3.rb"/>
</schedule>

If the watir script does not run, try wrapping it up in it's own
<schedule> element.
e.g.
<schedule>
<maven2 mvnhome="C:/blah" pomfile="blah/pom.xml"
goal="clean install" />
</schedule>
<schedule>
<exec command="ruby" workingdir="C:\WatirScripts"
args="SmokeTest3.rb"/>
</schedule>


Still more to follow..
So far, I've got this working well, but just running one watir script
with the build.
A single failure in the watir script turns the CC dashboard red.

I'm expecting to run into some timing challenges as more scripts are
added AND
still need to make "one watir script to run them all".


MichaelT

watirpuppy

unread,
Jan 9, 2009, 4:12:25 PM1/9/09
to Watir General
One Watir script to run them all..
Borrowed some code I found on this board and then simplified it a bit.
So far, seems to work!

<><><><>
require 'watir'
require 'firewatir'

#Set the Test Suite root dir.
TOPDIR = File.join(File.dirname(__FILE__))

#Setup an array and fill it with all file names found in the folder.
$all_tests = []
Dir.chdir TOPDIR do
$all_tests += Dir["*.rb"]
end

#this file "blah.rb" needs to be removed from the array so it doesn't
loop.
$all_tests.delete("blah.rb") #puts all_tests

####################
# Flip the browser to run here. #
####################
#bbrand = 'firefox'
$bbrand = 'ie'
#bbrand = 'safari'

# Launch/instantiate the instance of the browser
Watir::Browser.default = $bbrand
@@browser = Watir::Browser.new

#Run all scripts found in the directory!!
$all_tests.each {|x| require x}
<><><><>
Reply all
Reply to author
Forward
0 new messages