<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Grails Geek &#187; selenium java-client-drivers</title>
	<atom:link href="http://grailsgeek.com/tag/selenium-java-client-drivers/feed/" rel="self" type="application/rss+xml" />
	<link>http://grailsgeek.com</link>
	<description>Grails tips I wanna share with you ;)</description>
	<lastBuildDate>Sun, 01 Nov 2009 13:29:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Grails, Selenium, Maven and integration testing</title>
		<link>http://grailsgeek.com/2009/06/grails-selenium-maven-and-integration-testing/</link>
		<comments>http://grailsgeek.com/2009/06/grails-selenium-maven-and-integration-testing/#comments</comments>
		<pubDate>Sat, 13 Jun 2009 17:32:00 +0000</pubDate>
		<dc:creator>Alexander Naumenko</dc:creator>
				<category><![CDATA[integration testing]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[grails-maven-plugin]]></category>
		<category><![CDATA[intellij idea]]></category>
		<category><![CDATA[jetgroovy]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[selenium java-client-drivers]]></category>
		<category><![CDATA[selenium rc]]></category>
		<category><![CDATA[surefire plugin]]></category>

		<guid isPermaLink="false">http://grailsgeek.com/2009/06/grails-selenium-maven-and-integration-testing/</guid>
		<description><![CDATA[Today I wanna share with you my experience of configuring Selenium RC (with Java client drivers), Maven, Surefire to develop and run integration tests on Grails applications. We will build Grails demo application in Intellij IDEA (with Maven project model behind) and run simple integration test written in Groovy using Selenium RC.
Creating project structure

Create &#8220;demo&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>Today I wanna share with you my experience of configuring Selenium RC (with Java client drivers), Maven, Surefire to develop and run integration tests on Grails applications. We will build Grails demo application in Intellij IDEA (with Maven project model behind) and run simple integration test written in Groovy using Selenium RC.</p>
<h4>Creating project structure</h4>
<ul>
<li>Create &#8220;demo&#8221; directory in your projects dir an step inside it.</li>
</ul>
<ul>
<li>Create basic Grails application with Maven by running:</li>
</ul>
<pre class="brush:bash">mvn org.apache.maven.plugins:maven-archetype-plugin:2.0-alpha-4:generate -DarchetypeGroupId=org.grails -DarchetypeArtifactId=grails-maven-archetype -DarchetypeVersion=1.0 -DgroupId=com.grailsgeek -DartifactId=maven-grails-demo</pre>
<p>Fix Grails application pom.xml with tips I described in <a href="http://grailsgeek.com/2009/06/grails-and-maven2-in-intellij-idea/" target="_blank">my previous post</a>.</p>
<ul>
<li>Create integration-test module by running:</li>
</ul>
<pre class="brush:bash">mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.grailsgeek -DartifactId=integration-test</pre>
<p>And don&#8217;t forget to remove App and AppTest from sources that were generated by Maven.</p>
<ul>
<li>You should stay in your main project dir &#8220;demo&#8221;. Create multi-module pom.xml in project root dir with following content:</li>
</ul>
<pre class="brush:xml">&lt;project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                      http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;groupId&gt;com.grailsgeek&lt;/groupId&gt;
    &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
    &lt;artifactId&gt;demo&lt;/artifactId&gt;
    &lt;packaging&gt;pom&lt;/packaging&gt;
    &lt;modules&gt;
        &lt;module&gt;demo-app&lt;/module&gt;
        &lt;module&gt;integration-test&lt;/module&gt;
    &lt;/modules&gt;
&lt;/project&gt;</pre>
<ol>
<li>Now run <span style="color: #333399;">mvn install</span><span style="color: #99ff99;"> </span> from project root directory, and see <span style="color: #333399;">&#8220;BUILD SUCCESSFUL&#8221;</span> ;)</li>
</ol>
<h4>Adding necessary dependencies to maven poms</h4>
<p>We are going to modify only &lt;build&gt; sections of each pom. So If you extending your existing application with integration tests you&#8217;ll need to make just few adjustments.</p>
<ul>
<li>Grails application pom (our demo-app). Go to<span style="color: #333399;"> &lt;build&gt; -&gt; &lt;plugins&gt;</span> section and insert jetty plugin:</li>
</ul>
<pre class="brush:xml">            &lt;plugin&gt;
                &lt;groupId&gt;org.mortbay.jetty&lt;/groupId&gt;
                &lt;artifactId&gt;maven-jetty-plugin&lt;/artifactId&gt;
                &lt;version&gt;6.1.10&lt;/version&gt;
                &lt;configuration&gt;
                    &lt;scanIntervalSeconds&gt;10&lt;/scanIntervalSeconds&gt;
                    &lt;stopKey&gt;foo&lt;/stopKey&gt;
                    &lt;stopPort&gt;9999&lt;/stopPort&gt;
                &lt;/configuration&gt;
                &lt;executions&gt;
                    &lt;execution&gt;
                        &lt;id&gt;start-jetty&lt;/id&gt;
                        &lt;phase&gt;pre-integration-test&lt;/phase&gt;
                        &lt;goals&gt;
                            &lt;goal&gt;run-war&lt;/goal&gt;
                        &lt;/goals&gt;
                        &lt;configuration&gt;
                            &lt;scanIntervalSeconds&gt;0&lt;/scanIntervalSeconds&gt;
                            &lt;daemon&gt;true&lt;/daemon&gt;
                        &lt;/configuration&gt;
                    &lt;/execution&gt;
                    &lt;execution&gt;
                        &lt;id&gt;stop-jetty&lt;/id&gt;
                        &lt;phase&gt;post-integration-test&lt;/phase&gt;
                        &lt;goals&gt;
                            &lt;goal&gt;stop&lt;/goal&gt;
                        &lt;/goals&gt;
                    &lt;/execution&gt;
                &lt;/executions&gt;
            &lt;/plugin&gt;</pre>
<p>We&#8217;ll use it to launch our Grails application in the &#8220;integration-test&#8221; phase. And will click with Selenium on it, but a bit later about all that.</p>
<ol>
<li>Integration tests module. I&#8217;ll post here entire pom.xml because it&#8217;s not aware about project under test, only groupId could differ.</li>
</ol>
<pre class="brush:xml">&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  &lt;groupId&gt;com.grailsgeek&lt;/groupId&gt;
  &lt;artifactId&gt;integration-test&lt;/artifactId&gt;
  &lt;packaging&gt;jar&lt;/packaging&gt;
  &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  &lt;name&gt;integration-test&lt;/name&gt;
  &lt;url&gt;http://maven.apache.org&lt;/url&gt;
  &lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.codehaus.groovy&lt;/groupId&gt;
            &lt;artifactId&gt;groovy&lt;/artifactId&gt;
            &lt;version&gt;1.6.3&lt;/version&gt;
        &lt;/dependency&gt;

        &lt;dependency&gt;
            &lt;groupId&gt;org.seleniumhq.selenium.client-drivers&lt;/groupId&gt;
            &lt;artifactId&gt;selenium-java-client-driver&lt;/artifactId&gt;
            &lt;version&gt;1.0-beta-2&lt;/version&gt;
            &lt;scope&gt;test&lt;/scope&gt;
        &lt;/dependency&gt;
    &lt;/dependencies&gt;
    &lt;build&gt;
        &lt;plugins&gt;
            &lt;plugin&gt;
                &lt;groupId&gt;org.codehaus.groovy.maven&lt;/groupId&gt;
                &lt;artifactId&gt;gmaven-plugin&lt;/artifactId&gt;
                &lt;executions&gt;
                    &lt;execution&gt;
                        &lt;id&gt;test-compile&lt;/id&gt;
                        &lt;phase&gt;test-compile&lt;/phase&gt;
                        &lt;goals&gt;
                            &lt;goal&gt;generateTestStubs&lt;/goal&gt;
                            &lt;goal&gt;testCompile&lt;/goal&gt;
                        &lt;/goals&gt;
                        &lt;configuration&gt;
                            &lt;sources&gt;
                                &lt;fileset&gt;
                                    &lt;directory&gt;${pom.basedir}/src/test&lt;/directory&gt;
                                    &lt;includes&gt;
                                        &lt;include&gt;**/*.groovy&lt;/include&gt;
                                    &lt;/includes&gt;
                                &lt;/fileset&gt;
                            &lt;/sources&gt;
                        &lt;/configuration&gt;
                    &lt;/execution&gt;
                &lt;/executions&gt;
            &lt;/plugin&gt;
            &lt;plugin&gt;
                &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
                &lt;artifactId&gt;selenium-maven-plugin&lt;/artifactId&gt;
                &lt;executions&gt;
                    &lt;execution&gt;
                        &lt;phase&gt;pre-integration-test&lt;/phase&gt;
                        &lt;goals&gt;
                            &lt;goal&gt;start-server&lt;/goal&gt;
                        &lt;/goals&gt;
                        &lt;configuration&gt;
                            &lt;background&gt;true&lt;/background&gt;
                        &lt;/configuration&gt;
                    &lt;/execution&gt;
                &lt;/executions&gt;
            &lt;/plugin&gt;
            &lt;plugin&gt;
                &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
                &lt;configuration&gt;
                    &lt;skip&gt;true&lt;/skip&gt;
                &lt;/configuration&gt;
                &lt;executions&gt;
                    &lt;execution&gt;
                        &lt;id&gt;surefire-it&lt;/id&gt;
                        &lt;phase&gt;integration-test&lt;/phase&gt;
                        &lt;goals&gt;
                            &lt;goal&gt;test&lt;/goal&gt;
                        &lt;/goals&gt;
                        &lt;configuration&gt;
                            &lt;skip&gt;false&lt;/skip&gt;
                        &lt;/configuration&gt;
                    &lt;/execution&gt;
                &lt;/executions&gt;
            &lt;/plugin&gt;
            &lt;plugin&gt;
                &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                &lt;configuration&gt;
                    &lt;source&gt;1.5&lt;/source&gt;
                    &lt;target&gt;1.5&lt;/target&gt;
                &lt;/configuration&gt;
            &lt;/plugin&gt;
        &lt;/plugins&gt;
    &lt;/build&gt;

    &lt;repositories&gt;
        &lt;repository&gt;
            &lt;id&gt;seleniumhq&lt;/id&gt;
            &lt;name&gt;seleniumhq&lt;/name&gt;
            &lt;url&gt;http://nexus.openqa.org/content/repositories/releases/&lt;/url&gt;
        &lt;/repository&gt;
    &lt;/repositories&gt;
&lt;/project&gt;</pre>
<p>I propose to run <span style="color: #333399;">&#8220;mvn integration-test&#8221;</span> from project root, and see what will happen now. There are no tests yet, but Maven should resolve all dependencies and pass all execution phases.<span style="color: #333399;"> &#8220;BUILD SUCCESSFUL&#8221;</span> means that we could go on :)</p>
<h4>Preparing simple functionality for our tests</h4>
<p>Import our Maven project into Intellij IDEA as I described in <a href="http://me-on-grails.blogspot.com/2009/06/grails-111-and-maven2-in-intellij-idea.html">my previous post</a>.</p>
<p>Now I&#8217;m creating domain class Message:</p>
<pre class="brush:groovy">public class Message {
    String text
}</pre>
<p>And controller for it:</p>
<pre class="brush:groovy">class MessageController {
    def scaffold = true
}</pre>
<p>That&#8217;s it, our application is ready to be tested.</p>
<h4>Writing first Selenium test</h4>
<p>Switch to integration-test module, and create <span style="color: #333399;">&#8220;integration-test/test/java/com/grailsgeek/MessageTest.groovy&#8221;</span>:</p>
<pre class="brush:groovy">package com.grailsgeek

import com.thoughtworks.selenium.SeleneseTestCase

public class MessageTest extends SeleneseTestCase {

    public void setUp() {
        setUp "http://localhost:8080/demo-app/", "*firefox"
    }

    void testCreateMessage() {
        selenium.with {
            speed = "3000"

            open "message"
            waitPage()
            assertEquals "Message List", title

            click "//a[text()=\"New Message\"]"
            waitPage()
            assertEquals "Create Message", title

            type "text","Message Text ;)"
            click "//input[@value=\"Create\"]"
            waitPage()
            assertEquals "Show Message", title

            assertTrue isTextPresent ("Message Text ;)")
        }
    }

    private def waitPage() {
        selenium.waitForPageToLoad "30000"
    }
}</pre>
<h4>Running tests from Maven</h4>
<p>Run<span style="color: #333399;"> &#8220;mvn integration-test&#8221;</span> from project root directory and enjoy :). But since your project is going to grow fast (I hope so) or you already big enough, you could experience problems with out of memory error (<span style="color: #333399;">PermGen</span> space) due to Groovy dynamism. You could easy solve this by adding <span style="color: #333399;">&#8220;MAVEN_OPTS=-Xmx512m -XX:MaxPermSize=256m&#8221;</span> to your environment variables.</p>
<h4>Running tests from Intellij IDEA</h4>
<ol>
<li>Go to &#8220;Maven&#8221; context (at the right edge).</li>
<li>Run your application <span style="color: #333399;">&#8220;demo -&gt; Modules -&gt; demo-app -&gt; Plugins -&gt; grails -&gt; grails:run-app&#8221;</span> or just run IDEA grails configuration which should be already available.</li>
<li>Run Selenium with <span style="color: #333399;">&#8220;demo -&gt; Modules -&gt; integration-test -&gt; Plugins -&gt; selenium -&gt; selenium:start-server&#8221;</span></li>
<li>Execute your MessageTest.</li>
</ol>
<p>Intellij IDEA allows you to save run configuration for ease of further use (<span style="color: #333399;">selenium:start-server</span> and<span style="color: #333399;"> grails:run-app </span>could be saved as preconfigured). Also you there is no need to restart your application each time you made some changes. Grails will take care of it as usual.</p>
]]></content:encoded>
			<wfw:commentRss>http://grailsgeek.com/2009/06/grails-selenium-maven-and-integration-testing/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
