cargo + Selenium RCでintegration test

CargoでTomcatをダウンロード・起動・デプロイして、Selenium RCでテストする方法。

テストケースの準備

src/test/selenium/AppTestSuite.htmlにSeleniumのTestSuiteを置く。

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project>
 <modelVersion>4.0.0</modelVersion>
 <groupId>グループID</groupId>
 <artifactId>アーティファクトID</artifactId>
 <version>バージョン</version>
 <packaging>war</packaging>
 <build>
  <!-- WARファイルにバージョンをつけないようにするため -->
  <finalName>${artifactId}</finalName>
  <plugins>
   <plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
     <execution>
      <phase>integration-test</phase>
      <goals>
       <goal>run</goal>
      </goals>
      <configuration>
       <tasks>
        <taskdef
         resource="selenium-ant.properties"
         classpathref="maven.plugin.classpath" />
        <selenese
         suite="${basedir}/src/test/selenium/AppTestSuite.html"
         browser="*firefox"
         results="${basedir}/target/selenium_result_ff.html"
         multiWindow="true" startURL="http://localhost:8080" />
       </tasks>
      </configuration>
     </execution>
    </executions>
    <dependencies>
     <dependency>
      <groupId>org.openqa.selenium.server</groupId>
      <artifactId>selenium-server</artifactId>
      <version>0.9.0</version>
     </dependency>
    </dependencies>
   </plugin>
   <plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
    <executions>
     <execution>
      <id>tomcat-start</id>
      <phase>pre-integration-test</phase>
      <goals>
       <goal>start</goal>
       <goal>deploy</goal>
      </goals>
      <configuration>
       <wait>false</wait>
      </configuration>
     </execution>
    </executions>
   </plugin>
  </plugins>
  <pluginManagement>
   <plugins>
    <plugin>
     <groupId>org.codehaus.cargo</groupId>
     <artifactId>cargo-maven2-plugin</artifactId>
     <configuration>
      <container>
       <containerId>tomcat5x</containerId>
       <zipUrlInstaller>
        <url>
         http://www.apache.org/dist/tomcat/tomcat-5/v5.5.20/bin/apache-tomcat-5.5.20.zip
        </url>
       </zipUrlInstaller>
      </container>
     </configuration>
    </plugin>
   </plugins>
  </pluginManagement>
 </build>
 <pluginRepositories>
  <pluginRepository>
   <id>openqa</id>
   <url>http://maven.openqa.org</url>
  </pluginRepository>
  <pluginRepository>
   <id>codehaus snapshot repository</id>
   <url>http://snapshots.repository.codehaus.org/</url>
  </pluginRepository>
 </pluginRepositories>
</project>

実行

コマンドラインで以下を実行。

mvn integration-test

target/selenium_result_ff.html にテスト結果が出力されます。

付録:CargoでTomcatの起動のみする場合

mvn cargo:start

#これ試している間にやっとphaseとgoalの関係が理解できた。