Quantcast

A 99% Successful Attempt to Get Selenium Tests Running in Continuous Integration using Maven and Cargo.

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

A 99% Successful Attempt to Get Selenium Tests Running in Continuous Integration using Maven and Cargo.

buildlackey-2

Hello, all:

A colleague and I have been trying to create a
build procedure that runs Selenium tests against a Grails application.
Our end goal is to ensure that we can test our app's Ajax functionality using our
target browser in a continuous integration environment.


This is a long message, but I imagine it should be of interest to anyone who
has similar goals.  Below  I describe the approach we took, the issues encountered,
and our attempts at a solution.  In a nut-shell:  we almost have this! And we'd be very
grateful to anyone who could help us clear our last hurdle.


CHOICE OF TOOLS: MAVEN WITH GRAILS, CARGO, AND SELENIUM PLUG-INS
---------------------------------------------------------------

It is a no-brainer to get Selenium to work semi-manually
by launching your tests via something like the Selenium IDE  plug-in
for Firefox.   [ http://openqa.org/selenium-ide/ ]
Getting the tests to run purely from the command line
has proven to be a major pain.

For scripting our build process we tend to use Maven, and this led us to
using a combination of the Maven-Grails, Selenium, and Cargo plug-ins:

We rely on the  Maven Cargo plug-in to  

* automatically download the container which  hosts our app,

* deploy our app and
       
* start and stop the container at appropriate points in the build
        (that is, after compilation, and after unit tests and non-browser
        integration tests have completed.)

The Maven Selenium plug-in launches our target browser and drives the client
side interactions that comprise our test suite.


[ http://cargo.codehaus.org/Maven2+plugin ]
[ http://mojo.codehaus.org/selenium-maven-plugin ]



RUNNING THE DEMO
----------------

Set up your environment as follows:


    MAVEN_OPTS="-Xmx256m -Xms128m -XX:MaxPermSize=128m"
    export MAVEN_OPTS


Also, ensure that you have Maven 2.0.9 (or later) installed.


Unpack the attached archive, cd to the top level directory, and type

        mvn integration-test


THE GLITCH
----------

When you follow the procedure detailed above you will observe see a browser instance
being launched, and all the Selenium tests running successfully. But
you will also note that (even though all tests pass)  the build errors out
with message below:

    SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".


We think this is due to a  Grails Maven Plugin issue.
A very similar issue was closed in version 1.1 of the plugin.
(see: http://jira.codehaus.org/browse/GRAILS-4926)


ATTEMPTED SOLUTION: EXPLICITLY INCLUDING JAR WITH MISSING CLASS ON CLASSPATH OF PLUG-IN
---------------------------------------------------------------------------------------

It is possible to augment or modify the classes that are included on the path of the
tool chain (compiler, unit test runner, etc.) used in your build process -- as distinct
from the class path that is in effect when your application is actually run. The technique
for doing so is described here:

  [ http://www.sonatype.com/people/2008/04/how-to-override-a-plugins-dependency-in-maven/ ]
 

We applied this technique by including the lines bracketed by the XML comment below in
our pom.xml.  



 <plugin>
        <groupId>org.grails</groupId>
        <artifactId>grails-maven-plugin</artifactId>
        <version>1.1</version>
        <extensions>true</extensions>
        <executions>
          <execution>
            <goals>
              <goal>init</goal>
              <goal>maven-clean</goal>
              <goal>validate</goal>
              <goal>config-directories</goal>
              <goal>maven-compile</goal>
              <goal>maven-test</goal>
              <goal>maven-war</goal>
              <goal>maven-functional-test</goal>
            </goals>
          </execution>
        </executions>

     

But, even though this got us past the class load failure, we ran into a second
issue.  The missing class that we included via the new dependency does not seem
to have a compatible API with whatever is trying to use it. This is suggested by the
message below:


Embedded error: java.lang.reflect.InvocationTargetException
loader constraint violation: when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;" the class loader (instance of org/codehaus/groovy/grails/cli/support/GrailsRootLoader) of the current class, org/slf4j/LoggerFactory, and the class loader (instance of org/codehaus/classworlds/RealmClassLoader) for resolved class, org/slf4j/impl/StaticLoggerBinder, have different Class objects for the type org/slf4j/ILoggerFactory used in the signature
[INFO] -------------------------------------------------------------------


So, as stated above, we are close.

If we could just figure out which slf4j .jar to include I think we'd have a working solution.  



REPRODUCING THE DEMO FROM SCRATCH
---------------------------------

If you want to replicate the demo yourself, just follow the steps below:



    1. Install and configure Grails 1.1

    2. Generate Grails Maven Project
            mvn archetype:generate -DarchetypeGroupId=org.grails \
            -DarchetypeArtifactId=grails-maven-archetype  -DarchetypeVersion=1.0 \
            -DarchetypeRepository=http://repository.codehaus.org -DgroupId=com.example \
            -DartifactId=demo

    3. Initialize Grails Maven Project
            mvn initialize

    4. Add Grails domain class
            grails create-domain-class demo

    5. Generate scaffolding code for domain class
            grails generate-all demo

    6. Copy the pom.xml from the archived version of the demo into your project.



Thanks for reading this !   Hope it's helpful to others trying to get Selenium working with Grails in their Continuous Integration builds.



    Chris

-----------------
Chris Bedford
Founder & Lead Lackey
Build Lackey Labs
http://buildlackey.com

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: A 99% Successful Attempt to Get Selenium Tests Running in Continuous Integration using Maven and Cargo.

buildlackey-2
 well this looks promising - >  http://binil.wordpress.com/2006/12/08/automated-smoke-tests-with-selenium-cargo-testng-and-maven/

Wish I saw this before we tried to roll our own solution..

  - chris
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: A 99% Successful Attempt to Get Selenium Tests Running in Continuous Integration using Maven and Cargo.

Robert Fletcher
I'm currently working on a plugin to integrate Selenium RC tests into
the functional phase of 'grails test-app'. It still needs some work
but it is currently usable and available from
http://github.com/robfletcher/grails-selenium-rc

It doesn't require maven or TestNG (not that I think the latter is by
any means a bad thing to use) but enables you to write Selenium tests
in a similar way to unit or integration tests. Currently you need to
extend the grails.plugins.selenium.GrailsSeleneseTestCase class,
although hopefully that won't be necessary for ever.

The ultimate intention is to:
1 - be able to write Selenium RC tests in JUnit, TestNG, Spock, EasyB,
etc. as I'd like the plugin to be able to inject a Selenium instance
into any test class that declares a suitable property (may be tricky
as test-app doesn't currently provide the kind of hooks that would be
needed).
2 - connect to a running instance of Selenium Server and work with
Selenium Grid.

If this is of any interest to you I'd love some feedback or
suggestions on how the plugin could work better.

Cheers,
Rob

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: A 99% Successful Attempt to Get Selenium Tests Running in Continuous Integration using Maven and Cargo.

buildlackey-2
In reply to this post by buildlackey-2

We've come up with a work-around solution based on a Maven multi-module project in
which a build against the top level parent module kicks off two sub module builds:

        * one which is responsible just for constructing the Grails war, and installing
          it into the local maven repository.

        * and a second one which

                declares a dependency on the Grails war installed by the first,  

                deploys the depended-on Grails war to Tomcat

                runs Selenium tests against the deployed war running in the Tomcat container.


The attached zip archive
[ http://buildchimp.com/web_content/working.demo.of.grails.maven.cargo.and.selenium.zip ]
contains the solution. To run it, just unzip, then type:

        cd <unzip directory>/combo

        mvn clean integration-test


There are some gotchas I encountered when running the tests (e.g, the Tomcat container
occasionally not shutting down completely, and as a result, subsequent runs failing
due to "Can't bind to port 8080, already in use" messages.  Future entries on our
blog site (http://blog.buildlackey.com) will explain how to deal with these, as
well as attempt to provide more
background on how the tools we employed work together.

In the meantime, we hope the attached demo project will help others who are interested in
running Grails and Selenium in continuous integration.

regards
 - Chris



*******************

Chris Bedford

Founder & Lead Lackey
Build Lackey Labs
http://buildlackey.com

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: A 99% Successful Attempt to Get Selenium Tests Running in Continuous Integration using Maven and Cargo.

dominicclifton
In reply to this post by Robert Fletcher
This is of great interest to me and I've love to see points one and 2 below implemented.  Point 2 is of more interest to me as we plan to use selenium grid in combination with some VM's running on our CI box.

I'll take a look at this when the CI box arrives from Dell in a couple of weeks time.

Dom

-----Original Message-----
From: Robert Fletcher [mailto:[hidden email]]
Sent: 24 October 2009 04:02
To: [hidden email]
Subject: Re: [grails-user] A 99% Successful Attempt to Get Selenium Tests Running in Continuous Integration using Maven and Cargo.

I'm currently working on a plugin to integrate Selenium RC tests into
the functional phase of 'grails test-app'. It still needs some work
but it is currently usable and available from
http://github.com/robfletcher/grails-selenium-rc

It doesn't require maven or TestNG (not that I think the latter is by
any means a bad thing to use) but enables you to write Selenium tests
in a similar way to unit or integration tests. Currently you need to
extend the grails.plugins.selenium.GrailsSeleneseTestCase class,
although hopefully that won't be necessary for ever.

The ultimate intention is to:
1 - be able to write Selenium RC tests in JUnit, TestNG, Spock, EasyB,
etc. as I'd like the plugin to be able to inject a Selenium instance
into any test class that declares a suitable property (may be tricky
as test-app doesn't currently provide the kind of hooks that would be
needed).
2 - connect to a running instance of Selenium Server and work with
Selenium Grid.

If this is of any interest to you I'd love some feedback or
suggestions on how the plugin could work better.

Cheers,
Rob

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email





---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: A 99% Successful Attempt to Get Selenium Tests Running in Continuous Integration using Maven and Cargo.

buildlackey-2
In reply to this post by Robert Fletcher
Hi

thanks to Robert for his promising work on this plug-in.  I've got it working with his help.
I'd recommend it all those trying to get Selenium and Grails to work together from the command line.

The plug-in's documentation is here:  http://grails.org/plugin/selenium-rc

I've written a blog entry that documents a quick start procedure for Windows users who want to see the plug-in in action in a minimal set of steps:  http://buildchimp.com/wordpress/?p=220.




regards
  - Chris

--
Chris Bedford

Founder & Lead Lackey
Build Lackey Labs
http://buildlackey.com
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: A 99% Successful Attempt to Get Selenium Tests Running in Continuous Integration using Maven and Cargo.

Robert Fletcher
Cool, glad to hear you got it all working.

You really don't need to use git now as the plugin has been properly
released. You can just use 'grails install-plugin selenium-rc' from
inside your project.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Loading...