Running Tests (Only) using Sealights Maven plugin
When executing Tests via Maven you do not need to provide the buildSessionId generated in a previous step via an environment variable or a text file.
Please make sure the Sealights Test Listener is deployed to capture coverage of the application to be tested by this script.
For Java application, you can refer to Using Java Agents - Installing Test Listener as Java Agent
You can use the SeaLights agent to update your maven pom.xml with the needed changes to run your Maven build using the Maven Plugin
Configuring the SeaLights Maven plugin using a JSON file
Create a JSON configuration file with the following parameters in order to provide the necessary configuration fields to the SeaLights Maven plugin:
token or tokenFile - set with a token or a file containing the token obtained from the SeaLights dashboard
createBuildSessionId - Set to false because Build Session ID was created externally
buildSessionId or buildSessionIdFile - (Not to be used IF using labId) Set with a build session id or a file containing the build session id created by the config step
executionType - Provide which executions need to handled by the Maven plugin
testsonly - Execute only the test listener
testStage - Set the name of the test stage as will be displayed on the SeaLights dashboard
There are additional parameters you can provide
labId - (Optional) Unique ID for a set of test labs in case multiple labs are running simultaneously
runFunctionalTests - (Optional) Set to true to enforce partial validation of build. This is commonly used when the tested application is for example an Integration Build or a different technology than Java.
In these cases, the Java packages included parameter will not be validated. (ex. without this you may see an error like this:[INFO] - [Sealights Maven Plugin] - Initializing failed; errors:[received build session data without 'packagesIncluded' ('additionalInfo'='null')]
).filesStorage - Set to the temp folder for the agent to create temporary files in. For example /tmp
logEnabled - Set to true if you want a log to be created
logLevel - Set the log level to create. For example WARN or INFO
proxy - (Optional) Address of proxy to run connection through
sealightsJvmParams - Entry to provide JVM params to the SeaLights agent. It should be of the format {"key1":"val1", "key2":"val2"}
See Java Command Reference - Installing test listener as Java Agent for more parameter values and information
{
"tokenFile": "./sltoken.txt",
"createBuildSessionId": false,
"executionType": "testsonly",
"testStage": "Functional Tests",
"labId": "my_lab_id",
"runFunctionalTests": true,
"proxy": "",
"logEnabled": false,
"logDestination": "console",
"logLevel": "warn",
"sealightsJvmParams": {}
}
For Windows OS, please update the line 4 to use double backslashes like "buildSessionIdFile":"C:\\Sealights\\buildSessionId.txt"
Integrating into the pom.xml files
Before running your maven build, you run the build scanner with -pom flag to integrate the SeaLights Maven Plugin into the pom.xml files. This command will use the JSON configuration file defined above to inject Sealights plugin integration into the pom.xml settings.
The parameters it receives are:
configfile - The path to the JSON configuration you created with the parameters to be provided to the SeaLights Maven Plugin
workspacepath - The base path to the location of the pom.xml files to update
java -jar sl-build-scanner.jar -pom -configfile sealights-tests.json -workspacepath .
Executing your tests with Maven
You can use your regular maven command to execute your tests
Typically the command is 'mvn clean install' or 'maven clean verify' for example.
Sample shell script
echo "Downloading Sealights Agents..."
wget -nv https://agents.sealights.co/sealights-java/sealights-java-latest.zip
unzip -o sealights-java-latest.zip
echo "Sealights agent version used is:" `cat sealights-java-version.txt`
#Replace the Token value below with the proper value from your Accounts settings
export SL_TOKEN="123"
echo $SL_TOKEN>sltoken.txt
echo '{
"executionType": "testsonly",
"tokenFile": "./sltoken.txt",
"createBuildSessionId": false,
"testStage": "Functional Tests",
"runFunctionalTests": true,
"labId": "my_lab_id",
"proxy": null,
"logEnabled": false,
"logDestination": "console",
"logLevel": "warn",
"sealightsJvmParams": {}
}' > slmaventests.json
echo "Adding Sealights to Tests Project POM file..."
java -jar sl-build-scanner.jar -pom -configfile slmaventests.json -workspacepath .
Optional
Tagging
You can add tags to be viewed in the cockpit for the agents started by this maven job by passing them through the sl.tags property in the sealightsJvmParams field
Restoring the pom.xml file to its previous state
In case the pom file is to be restored to its previous state before the Sealights plugin was applied, use the build scanner with the -restore flag on the workspace where the pom.xml file is located: