Skip to main content

Setting up maven project to do first interactive test


The pom file

A basic pom file that sets up all dependencies for your interactive selenium-groovy testing contains following:
<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">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.jankester.selenium</groupId>
  <artifactId>selenium-groovy-public</artifactId>
  <version>2012.03-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>selenium-groovy</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.selenium.version>2.20.0</project.selenium.version>    
    <log.root>./target</log.root>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.8.2</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.codehaus.groovy.maven.runtime</groupId>
      <artifactId>gmaven-runtime-1.6</artifactId>
      <version>1.0</version>
    </dependency>
    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.16</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-simple</artifactId>
      <version>1.4.2</version>
    </dependency>    
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-java</artifactId>
      <version>${project.selenium.version}</version>
    </dependency>
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-firefox-driver</artifactId>
      <version>${project.selenium.version}</version>
    </dependency>
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-chrome-driver</artifactId>
      <version>${project.selenium.version}</version>
    </dependency>
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-ie-driver</artifactId>
      <version>${project.selenium.version}</version>
    </dependency>
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-htmlunit-driver</artifactId>
      <version>${project.selenium.version}</version>
    </dependency>
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-server</artifactId>
      <version>${project.selenium.version}</version>
    </dependency>    
<!--     <dependency>
          <groupId>org.seleniumhq.webdriver</groupId>
          <artifactId>webdriver-common</artifactId>
          <version>${project.selenium.version}</version>
        </dependency>       -->
    <dependency>
          <groupId>com.opera</groupId>
          <artifactId>operadriver</artifactId>
          <version>0.8.1</version>
        </dependency>    
<dependency>
  <groupId>pl.pragmatists</groupId>
  <artifactId>JUnitParams</artifactId>
  <version>0.4.0</version>
  <scope>test</scope>
</dependency>        
  </dependencies>

  <build>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>
    </resources>
    <testResources>
      <testResource>
        <directory>src/test/resources</directory>
        <filtering>true</filtering>
      </testResource>
    </testResources>

    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <compilerVersion>1.6</compilerVersion>
          <source>1.6</source>
          <target>1.6</target>
          <encoding>ISO-8859-1</encoding>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.codehaus.gmaven</groupId>
        <artifactId>gmaven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>generateStubs</goal>
              <goal>compile</goal>
              <goal>generateTestStubs</goal>
              <goal>testCompile</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.7.2</version>
        <configuration>
          <skip>true</skip>
        </configuration>
        <executions>
          <execution>
            <id>unit-tests</id>
            <phase>test</phase>
            <goals>
              <goal>test</goal>
            </goals>
            <configuration>
              <skip>false</skip>
              <includes>
                <include>${testcase.include.pattern}</include>
              </includes>
              <excludes>
                <exclude>**/*InProgressTest.java</exclude>
              </excludes>
            </configuration>
          </execution>
        </executions>
      </plugin>      
    </plugins>
    <pluginManagement>
      <plugins>
        <!--This plugin's configuration is used to store Eclipse m2e settings 
          only. It has no influence on the Maven build itself. -->
        <plugin>
          <groupId>org.eclipse.m2e</groupId>
          <artifactId>lifecycle-mapping</artifactId>
          <version>1.0.0</version>
          <configuration>
            <lifecycleMappingMetadata>
              <pluginExecutions>
                <pluginExecution>
                  <pluginExecutionFilter>
                    <groupId>
                      org.codehaus.gmaven
                    </groupId>
                    <artifactId>
                      gmaven-plugin
                    </artifactId>
                    <versionRange>
                      [1.3,)
                    </versionRange>
                    <goals>
                      <goal>generateTestStubs</goal>
                      <goal>generateStubs</goal>
                      <goal>testCompile</goal>
                      <goal>compile</goal>
                    </goals>
                  </pluginExecutionFilter>
                  <action>
                    <ignore></ignore>
                  </action>
                </pluginExecution>
              </pluginExecutions>
            </lifecycleMappingMetadata>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>

  <profiles>
  
    <profile>
      <id>development</id>
      <properties>
        <start.url>https://groups.google.com/forum/?fromgroups#!forum/selenium-users</start.url>
        <login.username>XXX</login.username>
        <login.password>YYY</login.password>      
        <log.root>./target</log.root>        
      </properties>
    </profile>  

    <profile>
      <id>integration</id>
      <properties>
      </properties>
    </profile>  

    <profile>
      <id>firefox</id>
      <properties>
        <browser.type>*firefox</browser.type>
        <add.firebug.to.firefox>true</add.firebug.to.firefox>
      </properties>
    </profile>

    <profile>
      <id>iexplorer</id>
      <properties>
        <browser.type>*iexplore</browser.type>
      </properties>
    </profile>

    <profile>
      <id>googlechrome</id>
      <properties>
        <browser.type>*googlechrome</browser.type>
        <webdriver.chrome.driver>${user.home}\map_creator-files\chromedriver.exe</webdriver.chrome.driver>
      </properties>
    </profile>

    <profile>
      <id>opera</id>
      <properties>
        <browser.type>*opera</browser.type>
      </properties>
    </profile>


  
    <profile>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <id>run-console</id>
      <properties>
        <testcase.include.pattern>XXX</testcase.include.pattern>
      </properties>      
      <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.1.1</version>
            <executions>
              <execution>
                <phase>test</phase>
                <goals>
                  <goal>java</goal>
                </goals>
                <configuration>
                  <classpathScope>test</classpathScope>
                  <mainClass>com.jankester.selenium.test.RunSeleniumConsole</mainClass>
                  <arguments />
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
    
    <profile>
      <id>run-script-cat1</id>
      <properties>
        <testcase.include.pattern>**/Cat1Test*</testcase.include.pattern>
      </properties>            
    </profile>    
  </profiles>

  <repositories>
  </repositories>

  <pluginRepositories>
  </pluginRepositories>

</project>

I don't want to explain maven, I don't want to go through this pom file in detail. But it will help you with:
  • solving all dependencies of selenium 2.20
  • setup a profile for each browser
  • setup a profile for a test environment
  • setup a profile for a specific test target, or run-console.
All dependencies should be part of maven public repositories, so the repository setting can remain empty. When we have implemented some code, we can execute our selenium groovy console with:
mvn clean test -P firefox,development,run-console  

Comments

Popular posts from this blog

SSL handshake failed: Secure connection truncated

Got this problem on Ubuntu 9.10 and 10.10. svn co --username=xx https:/yy zz “SSL handshake failed: Secure connection truncated” According to this link bug-ubuntu The solution is: sudo apt-get install libneon27 cd /usr/lib/ sudo rm libneon-gnutls.so.27 sudo ln -s /usr/lib/libneon.so.27 libneon-gnutls.so.27

Junit4 running parallel junit classes

To run junit testcases parallel, you can create your own class to run junit with: Add this tag to your class declaration. @RunWith(Parallelized.class) Implementation of this class looks like: package mypackage; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import org.junit.runners.Parameterized; import org.junit.runners.model.RunnerScheduler; public class Parallelized extends Parameterized {         private static class ThreadPoolScheduler implements RunnerScheduler     {         private ExecutorService executor;                 public ThreadPoolScheduler()         {             String threads = System.getProperty("junit.parallel.threads", "16");    ...

Create a groovy console and bind to selenium

Required groovy files In the previous posting we defined the pom file that we need for our build environment. Now we will setup some groovy files to get selenium and groovy running interactively. ConsoleWaiter.groovy The idea of Groovy Console I found on some other sides. Honour goes for instance too: http://josefbetancourt.wordpress.com/tag/eclipse-2/ I copied some code of this, and put it under src/test/groovy/com/jankester/selenium/test/utils: package com.jankester.selenium.test.utils /** * File: ConsoleWaiter.groovy */ import groovy.lang.Binding; import groovy.ui.Console; /** * Provides a wrapper for the console. * * Based on source by John Green * Adapted from: http://www.oehive.org/files/ConsoleWaiter.groovy * Released under the Eclipse Public License * http://www.eclipse.org/legal/epl-v10.html * * I added methods to allow use from Java. * * The run() method launches the console and causes this thread * to sleep until the console's window is closed....