rss

Selenium Acceptance/Integration Tests for a Google App Engine application using maven-gae-plugin

Hi,
 this is just a little tip on how to setup selenium acceptance tests for a Google App Engine java application when using maven-gae-plugin.
  • First, be sure you are using an earlier version (> 0.9.6 release ; eg. the latest snapshot version) of maven-gae-plugin.
    Here is an extract of a pom for the plugin repository and selenium deps right here :

  <properties>  
     <selenium.version>2.15.0</selenium.version>  
     <maven-gae-plugin.version>0.9.7-SNAPSHOT</maven-gae-plugin.version>  
   </properties>  


 <pluginrepositories>  
     <pluginrepository>  
       <id>sonatype.snapshots</id>  
       <url>https://oss.sonatype.org/content/repositories/snapshots/</url>  
       <releases><enabled>true</enabled></releases>  
       <snapshots><enabled>true</enabled></snapshots>  
     </pluginrepository>  
 </pluginrepositories>  
     <!-- acceptance tests -->  
     <dependency>  
       <groupid>org.seleniumhq.selenium</groupid>  
       <artifactid>selenium-java</artifactid>  
       <version>${selenium.version}</version>  
       <scope>test</scope>  
     </dependency>  

  • Then, map the gae-start and gae-stop executions to the pre/post integration phases. This is an example of the plugin configuration :
      <plugin>  
         <groupid>net.kindleit</groupid>  
         <artifactid>maven-gae-plugin</artifactid>  
         <version>${maven-gae-plugin.version}</version>  
         <configuration>  
           <unpackversion>${gae.version}</unpackversion>  
           <serverid>appengine.google.com</serverid>  
           <appdir>${webappDirectory}</appdir>  
         </configuration>  
         <executions>  
           <execution>  
             <id>unpack</id>  
             <phase>validate</phase>  
             <goals>  
               <goal>unpack</goal>  
             </goals>  
           </execution>  
           <execution>  
             <id>deploy</id>  
             <goals>  
               <goal>deploy</goal>  
             </goals>  
           </execution>  
           <execution>  
             <id>gae-start</id>  
             <phase>pre-integration-test</phase>  
             <goals>  
               <goal>start</goal>  
             </goals>  
             <configuration>  
               <appdir>${webappDirectory}</appdir>  
               <port>9000</port>  
               <address>0.0.0.0</address>
               <sdkdir>${gae.home}</sdkdir>  
               <wait>false</wait>  
               <disableupdatecheck>true</disableupdatecheck>  
             </configuration>  
           </execution>  
           <execution>  
             <id>gae-stop</id>  
             <phase>post-integration-test</phase>  
             <goals>  
               <goal>stop</goal>  
             </goals>  
           </execution>  
         </executions>  
         <dependencies>  
           <dependency>  
             <groupid>net.kindleit</groupid>  
             <artifactid>gae-runtime</artifactid>  
             <version>${gae-runtime.version}</version>  
             <type>pom</type>  
           </dependency>  
         </dependencies>  

  • The next and last step is to write your acceptance test. Here is just a simple example :
 package net.mademocratie.gae.acceptancetest;  
 import org.junit.After;  
 import org.junit.Before;  
 import org.junit.Test;  
 import org.openqa.selenium.WebDriver;  
 import org.openqa.selenium.firefox.FirefoxDriver;  
 import static com.thoughtworks.selenium.SeleneseTestBase.assertEquals;  
 public class HomePageIT {  
   private WebDriver driver;  
   @Before  
   public void setUp() {  
     driver = new FirefoxDriver();  
   }  
   @Test  
   public void home_page_should_be_displayed() {  
     this.driver.get("http://localhost:9000");  
     assertEquals("Ma Democratie", this.driver.getTitle());  
   }  
   @After  
   public void tearDown() {  
     driver.quit();  
   }  
 }  

You should find a full running sample on the github repository of ma-dem-ae.
NB: (possible) related issue #5
PS: thanks to codeformatter for this post ;)
PS(bis): oO i just heard that CasperJS or cucumber.js could do the job too...

Aucun commentaire:

Enregistrer un commentaire