Skip to content
Max Saperstone edited this page Feb 7, 2019 · 8 revisions

Using Selenified In a Maven Project

Selenified is designed to work seamlessly in your maven project, whether it is a new one, or existing one. Ensure you are using the standard maven project setup.

Dependencies

First thing to do is to add Selenified as a dependency. Update your pom.xml file to include (or add the dependency block to your current dependencies).

<dependencies>
    <dependency>
        <groupId>com.coveros</groupId>
        <artifactId>selenified</artifactId>
        <version>3.0.4</version>
        <scope>test</scope>
    </dependency>
</dependencies>

Test Execution

If following the setup indicated, it is suggested to use the failsafe plugin in order to execute the tests. Update your pom.xml file to include

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>3.0.0-M3</version>
    <executions>
        <execution>
            <goals>
                <goal>integration-test</goal>
                <goal>verify</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Then from the command line run

mvn verify

Additional Run Parameters

If everything is setup properly, no runtime parameters are required, but many can be provided to change and optimized run performance. This can and should be done by configuring the maven failsafe plugin. Several options exist to change how your tests are run.

Configuration Description
threadCount how many tests do you want to run in parallel
verbosity how much logging is desired
listener if you want to loop through multiple browsers for the same test, use the custom Selenified Transformer
groups what tests do you want to include or exclude in the test run based on the provided groups tagging
files what tests do you want to include or exclude in the test run based on the test file names

More options can he found here. It's best to set most of these configuration values up as parameters, so that they can be easily overridden from the command-line.

<properties>
    <!-- Test run information -->
    <failsafe.threads>5</failsafe.threads>
    <failsafe.verbosity>0</failsafe.verbosity>
    <failsafe.groups.include>integration</failsafe.groups.include>
    <failsafe.groups.exclude>browser</failsafe.groups.exclude>
    <failsafe.files.include>**/*IT.java</failsafe.files.include>
    <failsafe.files.exclude></failsafe.files.exclude>
</properties>

Then these variable names can be passed into the failsafe plugin.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>3.0.0-M3</version>
    <configuration>
        <parallel>methods</parallel>
        <threadCount>${failsafe.threads}</threadCount>
        <properties>
            <property>
                <name>surefire.testng.verbose</name>
                <value>${failsafe.verbosity}</value>
            </property>
            <property>
                <name>listener</name>
                <value>com.coveros.selenified.utilities.Transformer</value>
            </property>
        </properties>
        <groups>${failsafe.groups.include}</groups>
        <excludedGroups>${failsafe.groups.exclude}</excludedGroups>
        <includes>
            <include>${failsafe.files.include}</include>
        </includes>
        <excludes>
            <exclude>${failsafe.files.exclude}</exclude>
        </excludes>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>integration-test</goal>
                <goal>verify</goal>
            </goals>
        </execution>
    </executions>
</plugin>

To override these parameters from the command-line, you'll want to pass in the variable name proceeded by a -D and set the desired value. For example, to change threading from the default 5 to 2, the below command would be used:

mvn verify -Dfailsafe.threads=2

Full Example

<?xml version="1.0" encoding="UTF-8"?>
<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.coveros</groupId>
    <artifactId>selenified-maven-example</artifactId>
    <version>1.0-SNAPSHOT</version>

    <prerequisites>
        <maven>3.0.4</maven>
    </prerequisites>

    <properties>
        <!-- General Project Settings -->
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <!-- Test Run Information -->
        <failsafe.threads>5</failsafe.threads>
        <failsafe.verbosity>0</failsafe.verbosity>
        <failsafe.groups.include></failsafe.groups.include>
        <failsafe.groups.exclude></failsafe.groups.exclude>
        <failsafe.files.include></failsafe.files.include>
        <failsafe.files.exclude></failsafe.files.exclude>
    </properties>

    <name>Selenified Maven Example</name>

    <dependencies>
        <dependency>
            <groupId>com.coveros</groupId>
            <artifactId>selenified</artifactId>
            <version>3.0.4</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>3.0.0-M3</version>
                <configuration>
                    <parallel>methods</parallel>
                    <threadCount>${failsafe.threads}</threadCount>
                    <properties>
                        <property>
                            <name>surefire.testng.verbose</name>
                            <value>${failsafe.verbosity}</value>
                        </property>
                        <property>
                            <name>listener</name>
                            <value>com.coveros.selenified.utilities.Transformer</value>
                        </property>
                    </properties>
                    <groups>${failsafe.groups.include}</groups>
                    <excludedGroups>${failsafe.groups.exclude}</excludedGroups>
                    <includes>
                        <include>${failsafe.files.include}</include>
                    </includes>
                    <excludes>
                        <exclude>${failsafe.files.exclude}</exclude>
                    </excludes>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Sample Project

A sample maven project can be found here

You can’t perform that action at this time.