Skip to content

JSystem Maven Plugin

Itai Agmon edited this page Sep 22, 2016 · 5 revisions

JSystem Maven Plugin

The most common way of executing JSystem scenarios is from the runner GUI. But in some case, we would like to execute scenarios directly from the command line without opening any graphic interface. This method can be easier for integrating JSystem with CI systems and would result less resource consumption. Running scenarios from the command line can be done by using the runScenario batch/shell scripts that are included in the JSystem root folder. JSystem 6.0.00 introduces another way for Maven based projects; Executing scenarios using the JSystem Maven plugin. The main benefit of the JSystem Maven plugin is that there is no need for JSystem installation. The execution is done by using the JSystem jars that are already included as dependencies in the project.

Configuring the Plugin

If you were using JSystem archetypes for creating your automation project as described in the Quick Start Guide you already have the plugin configured in your test project pom.xml file. Open the test project and search for the plugin definition.

<plugin>
    <groupId>org.jsystemtest</groupId>
    <artifactId>jsystem-maven-plugin</artifactId>
    <version>6.1.04</version>
    <dependencies>
        <dependency>
            <groupId>org.jsystem</groupId>
            <artifactId>my-tests-proj</artifactId>
            <version>[0.0,]</version>
            <scope>runtime</scope>
        </dependency>
    </dependencies>
</plugin>

Since Maven plugins are using a separate class loader then the project, we need to add the project artifact as a dependence to the plugin. In the project generation process the test project GAV details were already updated.

Notice: In the version section there is a use in the Maven version range specification for specifying the latest project version.

Notice: Always make sure to use the same version in the plugin and in all the JSystem dependencies that exist in your POM files.

Executing the Plugin

The plugin can be executed from the command line. Change directory to the test project’s root folder and call to the run goal of the jsystem-maven-plugin

mvn jsystem:run -Dscenario=scenarios/default -Dsut=default.xml

The goal receives two arguments; The scenario name and the sut file name. Notice that the HTML and other reports are all generated in the log/currentfolder under the project’s root directory.

Running from POM

You can also configure the plugin from the POM and attach it to one of Maven goals lifecycle phases.

<plugin>
    <groupId>org.jsystemtest</groupId>
    <artifactId>jsystem-maven-plugin</artifactId>
    <version>6.1.04</version>
    <executions>
        <execution>
            <phase>integration-test</phase>
            <goals>
                <goal>run</goal>    
            </goals>
            <id>runScenario</id>
            <configuration>
                <sut>default.xml</sut>
                <scenario>scenarios/default</scenario>
            </configuration>    
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>org.jsystem</groupId>
            <artifactId>my-tests-proj</artifactId>
            <version>[0.0,]</version>
            <scope>runtime</scope>
        </dependency>
    </dependencies>
</plugin>

In this example, in the integration-test phase the default scenario is executed using the default.xml sut file.

Executing Multiple Scenarios

From version 6.0.03 the JSystem Maven plugin supports execution of multiple scenarios. To specify more than one scenario, list all the scenarios you wish to execute separated by a comma. You would also need to specify the SUT files in the same fashion.

mvn jsystem:run -Dscenario=scenarios/s1,scenarios/s2 -Dsut=sut1.xml,sut2.xml

Notice: The number of scenario must be equals to the number of sut files

If you were using JSystem Multiple Scenario Execution feature, you may already have an XML file with sequences of scenarios and sut files. You can still use those XML files with the JSystem Maven plugin. Just use the -DxmlFile switch to specify the location of the XML file.

mvn jsystem:run -DxmlFile=myXmlFile.xml

Debugging

From Eclipse

If you are using Eclipse you can easily debug the scenario. From Eclipse menu open ‘Run’->’Debug Configuration’ and a new Maven Configuration with your project as Base Directory and the plugin configuration as goal.

jsystem:run -Dscenario=scenarios/default -Dsut=default.xml

Remote Debugging

It can be very useful sometimes to be able to remote debug the execution while it is running on a remote machine. For example, you may encounter a problem that is reproducable only when running the scenarios from you CI system.

To allow remote debugging you will need to add the appropriate JVM options using the MAVEN_OPTS environment variable.

In Linux machine, export the variable before running the plugin as shown below:

export MAVEN_OPTS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"

This will open port 8787 for remote debugging.

If you want the execution to halt so you will have time to connect to the port from your IDE, change the last option to suspend=y

Clone this wiki locally