2012-01-16 173 views
3

我想运行与Maven Selenium测试作为构建的一部分,所以这里是我的配置:如何使用maven运行硒测试?

<plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-war-plugin</artifactId> 
     <version>2.1.1</version> 
    </plugin> 

    <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>2.3.2</version> 
       <executions> 
        <execution> 
         <goals> 
          <goal>testCompile</goal> 
         </goals> 
        </execution> 
       </executions> 
    </plugin> 



    <plugin> 

     <groupId>org.codehaus.cargo</groupId> 
     <artifactId>cargo-maven2-plugin</artifactId> 
     <version>1.1.4</version> 
     <configuration> 

      <wait>false</wait> 
      <container> 
      <containerId>tomcat7x</containerId> 
      <home>${env.CATALINA_HOME}</home> 
      <timeout>300000</timeout> <!-- 5 minutes -->     
      </container> 

      <configuration> 
      <type>standalone</type> 
      <home>target/tomcat7x</home> 
      </configuration> 

      <properties> 
       <cargo.jvmargs>-XX:PermSize=256m -XX:MaxPermSize=512m -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled</cargo.jvmargs> 
      </properties> 

     </configuration> 
      <executions> 
       <execution> 
       <id>start-container</id> 
       <phase>pre-integration-test</phase> 
        <goals> 
         <goal>start</goal> 
         <goal>deploy</goal> 
        </goals> 
       </execution> 
       <execution> 
       <id>stop-container</id> 
       <phase>post-integration-test</phase> 
        <goals> 
         <goal>stop</goal> 
        </goals> 
       </execution> 
      </executions> 
    </plugin> 



    <plugin> 
     <groupId>org.codehaus.mojo</groupId> 
     <artifactId>selenium-maven-plugin</artifactId> 
      <executions> 
       <execution> 
       <id>start</id> 
       <phase>pre-integration-test</phase> 
        <goals> 
         <goal>start-server</goal> 
        </goals> 
       <configuration> 
        <background>true</background> 
        <logOutput>true</logOutput> 
       </configuration> 
      </execution> 

      <execution> 
      <id>stop</id> 
      <phase>post-integration-test</phase> 
        <goals> 
         <goal>stop-server</goal> 
        </goals> 
      </execution> 
     </executions> 
    </plugin> 

    <plugin> 

      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.8</version> 

      <configuration> 
       <junitArtifactName> 
       org.junit:com.springsource.org.junit 
       </junitArtifactName> 
       <excludes> 

        <exclude>**/unit/*Test.java</exclude> 
       </excludes> 
      </configuration> 


      <executions> 
       <execution> 

       <id>integration-tests</id> 
       <phase>integration-test</phase> 
        <goals> 
         <goal>test</goal> 
        </goals> 
       <configuration> 
       <skip>false</skip> 
       <excludes> 
        <exclude>none</exclude> 
       </excludes> 

       <includes> 
        <include>**/integration/*Test.java</include> 
       </includes> 
       </configuration> 
       </execution> 
     </executions> 

     </plugin> 

会发生什么情况如下:创建

  1. 战争文件。
  2. 集成测试类运行(打开浏览器,然后关闭浏览器)。
  3. tomcat服务器启动并部署应用程序。
  4. 问题:部署后,我得到java.lang.OutOfMemoryError:PermGen的空间虽然我在catalina.bat中和货物的配置增加了记忆,但我可以看到,这些战争部署在货物输出文件夹,所以我想知道为什么我得到这个异常?

UPDATE:日志

[WARNING] [talledLocalContainer] Jan 16, 2012 1:36:51 PM org.apache.catalina.startup.SetAllPropertiesRule begin 
[WARNING] [talledLocalContainer] WARNING: [SetAllPropertiesRule]{Server/Service/Connector} Setting property 'emptySessionPath' to 'true' did not find a matching property. 
[WARNING] [talledLocalContainer] Jan 16, 2012 1:36:51 PM org.apache.tomcat.util.digester.SetPropertiesRule begin 
[WARNING] [talledLocalContainer] WARNING: [SetPropertiesRule]{Server/Service/Engine/Host} Setting property 'xmlValidation' to 'false' did not find a matching property. 
[WARNING] [talledLocalContainer] Jan 16, 2012 1:36:51 PM org.apache.tomcat.util.digester.SetPropertiesRule begin 
[WARNING] [talledLocalContainer] WARNING: [SetPropertiesRule]{Server/Service/Engine/Host} Setting property 'xmlNamespaceAware' to 'false' did not find a matching property 
[WARNING] [talledLocalContainer] Jan 16, 2012 1:36:51 PM org.apache.coyote.AbstractProtocol init 
[WARNING] [talledLocalContainer] INFO: Initializing ProtocolHandler ["http-bio-8080"] 
[WARNING] [talledLocalContainer] Jan 16, 2012 1:36:51 PM org.apache.coyote.AbstractProtocol init 
[WARNING] [talledLocalContainer] INFO: Initializing ProtocolHandler ["ajp-bio-8009"] 
[WARNING] [talledLocalContainer] Jan 16, 2012 1:36:51 PM org.apache.catalina.startup.Catalina load 
[WARNING] [talledLocalContainer] INFO: Initialization processed in 600 ms 
[WARNING] [talledLocalContainer] Jan 16, 2012 1:36:51 PM org.apache.catalina.core.StandardService startInternal 
[WARNING] [talledLocalContainer] INFO: Starting service Catalina 
[WARNING] [talledLocalContainer] Jan 16, 2012 1:36:51 PM org.apache.catalina.core.StandardEngine startInternal 
[WARNING] [talledLocalContainer] INFO: Starting Servlet Engine: Apache Tomcat/7.0.22 
[WARNING] [talledLocalContainer] Jan 16, 2012 1:36:51 PM org.apache.catalina.startup.HostConfig deployWAR 
[WARNING] [talledLocalContainer] INFO: Deploying web application archive cargocpc.war 
[WARNING] [talledLocalContainer] Jan 16, 2012 1:36:52 PM org.apache.catalina.startup.HostConfig deployWAR 
[WARNING] [talledLocalContainer] INFO: Deploying web application archive MyAPP.war 
[WARNING] [talledLocalContainer] java.lang.OutOfMemoryError: PermGen space 
[WARNING] [talledLocalContainer] Exception in thread "main" java.lang.OutOfMemoryError: PermGen space 
[WARNING] [talledLocalContainer]  at java.lang.Throwable.getStackTraceElement(Native Method) 
[WARNING] [talledLocalContainer]  at java.lang.Throwable.getOurStackTrace(Throwable.java:591) 
[WARNING] [talledLocalContainer]  at java.lang.Throwable.printStackTrace(Throwable.java:462) 
[WARNING] [talledLocalContainer]  at java.lang.Throwable.printStackTrace(Throwable.java:451) 
[WARNING] [talledLocalContainer]  at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:469) 

回答

1

尝试在你正在运行的Maven构建的环境变量设置MAVEN_OPTS=-XX:MaxPermSize=384m(或一些合适的数字)。

+0

我已经有'MAVEN_OPTS = -Xmx512m -Xms256m -XX:MaxPermSize = 1024m' – 2012-01-16 11:34:56

+0

确切地说,发生?你能发布输出摘录吗? – artbristol 2012-01-16 11:35:25

+0

问题已更新。 – 2012-01-16 11:38:37

4
  • 我现在使用下面的配置文件,它工作得很好,我运行

    mvn install -Pit 
    

档案集成测试:

<profile> 
      <id>it</id> 
      <build> 
      <plugins> 

      <plugin> 

      <groupId>org.codehaus.cargo</groupId> 
      <artifactId>cargo-maven2-plugin</artifactId> 
      <version>1.1.4</version> 
      <configuration> 

       <wait>false</wait> 
       <container> 
       <containerId>tomcat7x</containerId> 
       <home>${env.CATALINA_HOME}</home> 
       <timeout>300000</timeout>     
       </container> 

       <configuration> 
       <type>standalone</type> 
       <home>target/tomcat7x</home> 
       <properties> 
        <cargo.jvmargs>-XX:PermSize=256m -XX:MaxPermSize=512m -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled</cargo.jvmargs> 
       </properties> 
       </configuration> 


      </configuration> 
       <executions> 
        <execution> 
        <id>start-container</id> 
        <phase>pre-integration-test</phase> 
         <goals> 
          <goal>start</goal> 
          <goal>deploy</goal> 
         </goals> 

         <configuration> 
          <deployer> 
           <deployables> 
            <deployable> 
            <groupId>${project.groupId}</groupId> 
            <artifactId>${project.artifactId}</artifactId> 
            <type>war</type> 
            <pingURL>http://localhost:8080/${project.artifactId}</pingURL> 
            <pingTimeout>60000</pingTimeout> 
            <properties> 
             <context>${project.artifactId}</context> 
            </properties> 
            </deployable> 
           </deployables> 
          </deployer> 
         </configuration> 

        </execution> 
        <execution> 
        <id>stop-container</id> 
        <phase>post-integration-test</phase> 
         <goals> 
          <goal>stop</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 


     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>selenium-maven-plugin</artifactId> 
       <executions> 
        <execution> 
        <id>start</id> 
        <phase>pre-integration-test</phase> 
         <goals> 
          <goal>start-server</goal> 
         </goals> 
        <configuration> 
         <background>true</background> 
         <logOutput>true</logOutput> 
        </configuration> 
       </execution> 

       <execution> 
       <id>stop</id> 
       <phase>post-integration-test</phase> 
         <goals> 
          <goal>stop-server</goal> 
         </goals> 
       </execution> 
      </executions> 
    </plugin> 


      <plugin> 
        <artifactId>maven-surefire-plugin</artifactId> 
        <executions> 

         <execution> 
          <id>default-test</id>         
          <configuration> 
           <skipTests>true</skipTests> 
          </configuration> 
         </execution> 

         <execution> 
          <id>surefire-it</id> 
          <phase>integration-test</phase> 
          <goals> 
           <goal>test</goal> 
          </goals> 
          <configuration> 
           <includes> 
            <include>**/integration/*Test.java</include> 
           </includes> 
           <skipTests>false</skipTests> 
          </configuration> 
         </execution> 
        </executions> 
        <configuration> 
         <argLine>-Xms256M -Xmx768M -XX:MaxPermSize=256M</argLine> 
        </configuration> 
       </plugin> 

       </plugins> 
      </build> 

      <activation> 
       <property> 
       <name>it</name> 
       </property> 
      </activation> 

     </profile>