2009-10-14
Maven, Selenium and a hint of GroovyLeonard Axelsson | fix, groovy, mac, maven, selenium, snowleopard
Getting selenium running on maven using selenium-rc and tests written in groovy is a piece of cake, well at least when someone else has written the tutorial already: Grails, Selenium, Maven and integration testing
The only thing I found lacking for my use case was nice html reports. Those can can be added using the maven-surefire-report-plugin.
Add this to mavens pom.xml:
<project>
...
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.4.2</version>
</plugin>
</plugins>
</reporting>
...
</project>
Everything works now right?
Well yeah, as long as you aren't on a Mac upgraded to Snow Leopard. Basically there is a problem with Firefox and Snow Leopard which makes Selenium crash. After some googling I found this post, mentioning among other things a fix to our problem (step 4).
This solved the problem for me (copy into the terminal):
# Make a backup of the old file mv /Applications/Firefox.app/Contents/MacOS/libsqlite3.dylib \\ /Applications/Firefox.app/Contents/MacOS/libsqlite3.dylib.orig # Copy in the working file cp /usr/lib/libsqlite3.dylib \\ /Applications/Firefox.app/Contents/MacOS/libsqlite3.dylib
Show me the code!
All you really need is maven and the pom. To make it all as simple as possible I've put a complete demo up on github, modify it to suit your needs. I used groovy to write the selenium tests but java should work as well.
|
|
2009-10-14 21:10
TipTrick
Hello, nice post. I have a question, is there a way to do code coverage on groovy code ... ?
2009-10-14 22:11
mike
Yes, you can use Cobertura (http://cobertura.sourceforge.net/) to do coverage on Groovy code. If you're using Grails, you can even use the Code-Coverage plugin (http://grails.org/plugin/code-coverage) to do it
2009-10-14 23:24
Leonard
Thanks. As Mike said you can use cobertura to generate a cove-coverage report for your Groovy based tests. If you're using maven it's as easy as adding the following to your poms build plugins. <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> </plugin>
2009-10-14 23:26
Leonard
Sorry about the bad formatting, we really need to look into how comments are handled on the blog. You can read more about using the Cobertura maven-plugin here: http://mojo.codehaus.org/cobertura-maven-plugin/
2009-10-15 09:56
TipTrick
Thanks, now I have basic code coverage support. But have a problem if I want to see lines which are (not)covered, after click on source file link gives me a message "Unable to locate xxx.groovy. Have you specified the source directory?".
2009-10-16 14:42
Leonard
I went back to check my old code and couldnt find any working examples of using maven with cobertura for groovy-code, I'll have to get back to you on that one.
2009-10-17 12:20
webpatser
I wrote a simple howto for Snow Leopard and selenium using firefox 3.5. You can find it here http://www.god-object.com/2009/10/16/user-interface-testing-on-mac-os-10-6-snow-leopard/
2009-11-03 09:36
Leonard
Thanks for the tip webpatser!

