- Utility to easily integrate ReportPortal with your JAVA-TestNG automation framework
- This is a library which implements basic utilities
for ReportPortal
(com.epam.reportportal)
ReportPortalLogger
: For logging messages to ReportPortal at different levels like DEBUG, INFO WARNScreenShotManager
: Takes care of following- Capturing Screenshot using selenium
- Descaling/Reducing file size of the taken screenshot
- Saving the screenshots in managed test level hierarchies
CommandLineExecutor
andCommandLineResponse
: Take care of running any CLI commands and storing its Standard Output, Error responses
mvn clean install -DskipTests
If facing issues with dependencies not being resolved from https://jitpack.io, then check the
settings.xml
file you're using for building your maven projects. If you've proxies configured in the same, then make surejitpack.io
is part ofnonProxyHosts
configuration. For instance
<proxy>
<id>httpmyproxy</id>
<active>true</active>
<protocol>http</protocol>
<host>someHost</host>
<port>8080</port>
<username>UserName</username>
<password>Password</password>
<nonProxyHosts>*.google.com|*jitpack.io</nonProxyHosts>
</proxy>
<dependency>
<groupId>com.github.znsio</groupId>
<artifactId>ReportPortalIntegration</artifactId>
<version>x.x.x</version>
</dependency>
- Listener Configuration
- Approach-1 Listener in TestNG XML file: Add the following line to configure ReportPortal listener in the xml
file where you have configured your testng suite
- Without overloading properties
<listener class-name="com.epam.reportportal.testng.ReportPortalTestNGListener"/>
- With overloading properties
<listener class-name="com.znsio.reportportal.integration.listener.ReportPortalListener"/>
- Without overloading properties
- Approach-2 Listener in Maven Surefire Plugin: Add the following snippet to configure ReportPortal listener in
the
pom.xml
file where you have configured yourmaven-surefire-plugin
- Without overloading properties
<property> <name>listener</name> <value>com.epam.reportportal.testng.ReportPortalTestNGListener</value> </property>
- With overloading properties
<property> <name>listener</name> <value>com.znsio.reportportal.integration.listener.ReportPortalListener</value> </property>
- Without overloading properties
- Approach-3: Use the following snippet to configure ReportPortal listener when creating TestNG file
programmatically
- Without overloading properties
ReportPortalTestNGListener reportPortalTestNGListener = new ReportPortalTestNGListener(); testNG.addListener(reportPortalTestNGListener);
- With overloading properties
ReportPortalListener reportPortalListener = new ReportPortalListener(); testNG.addListener(reportPortalListener);
- Without overloading properties
- For more details on listener configuration, refer reportportal-agent-java-testNG
- Approach-1 Listener in TestNG XML file: Add the following line to configure ReportPortal listener in the xml
file where you have configured your testng suite
- Properties file: Create a
reportportal.properties
file either insrc/main/resources/
or insrc/test/resources
directory in your automation framework with the following mandatory attributesrp.endpoint = <Your Endpoint> rp.uuid = <Your UDID> rp.launch = <Your Launch Name> rp.project = <Your Project Name>
- Launch attributes related to CI (Pipeline) execution: The
setPipelineAttributes
method ofReportPortalPropertiesOverloader
class takes care of setting the following attributes in case the test execution is happening on CI (Pipeline)All these attributes will be set as launch attributes if the execution is happening on CI, and if they are either set at System property or System environment variable. If your pipeline is using different keys to set the above attributes then the ones we're using above, for each such key, you can define the new key value in theBUILD_ID AGENT_NAME BRANCH_NAME
config.proprties
file of your automation framework like below:BUILD_ID=BUILD_BUILDID BRANCH_NAME=BUILD_SOURCEBRANCHNAME
- For more details on configuration and additional parameters for
reportportal.properties
, refer reportportal-client-java and reportportal-agent-java-testNG
-
ReportPortalPropertiesOverloader
class takes care of dynamically setting Report Portal properties at run time like launch name, description, attributes etc. The method which takes care of this isgetProperties()
which is automatically invoked fromReportPortalListener
class as part of listener initialization -
Configuring the test metadata:
- The following property values are mandatory to be provided for capturing the relevant test execution metadata. You can provide them in the reportportal.properties file, or add a System property RP_CONFIG with the relative path from project root directory (user.dir) where this file exists.
- LAUNCH_NAME=[application_name]
- TARGET_ENVIRONMENT=[dev/qa/preprod/prod]
- PLATFORM=[web/android/ios/desktop/api/etc.]
- BROWSER=[if Platform==web, which browser is used for test execution - chrome/firefox/na]
- APP_PACKAGE_NAME=[if Platform==android/ios, the package name]
- IS_LOCAL_DEVICE=[true/false] - is the test running on local browser/device or cloud
- IS_VISUAL=[true/false] - if Visual testing is enabled or not
- BRANCH_NAME=[the current branch name as obtained by git command, or can be specified as an absolute value, or the environment varaiable/system property name which indicates the branch name]
- RUN_IN_CI=[true/false] - if test is running in CI or not
- BUILD_ID=[the environment variable or system property name which indicates the build id]
- AGENT_NAME=[the environment variable or system property name which indicates the CI agent name]
- For setting any additional property to launch attributes which is not already configured
in
ReportPortalPropertiesOverloader
class, we need to set that attribute key and value at either System Property level or at Environment variable. Any key with prefixRP_
set at System property or Environment variable level will be set as ReportPortal's launch attribute. The method which takes care of this configuration issetRPAttributesFromSystemVariables
defined insideReportPortalPropertiesOverloader
class. For instance, if you're setting environment variable likeexport RP_Version=0.0.1
, then on ReportPortal, you'll see the corresponding launch attribute asVersion:0.0.1
- The following property values are mandatory to be provided for capturing the relevant test execution metadata. You can provide them in the reportportal.properties file, or add a System property RP_CONFIG with the relative path from project root directory (user.dir) where this file exists.
-
ReportPortalLogger
class has all its public methods defined as static, so it doesn't require the consumer to create an object of this class. Following are the methods we can use to report logs to ReportPortalReportPortalLogger.logInfoMessage(String message)
: Logsmessage
at INFO level toReportPortal
as well as consoleReportPortalLogger.logDebugMessage(String message)
: Logsmessage
at DEBUG level toReportPortal
ReportPortalLogger.logWarningMessage(String message)
: Logsmessage
at WARN level toReportPortal
ReportPortalLogger.captureAndAttachScreenshot(WebDriver webDriver)
: This method implicitly callscaptureScreenShot
method ofScreenShotManager
class to capture the screenshot and then callsattachFileInReportPortal
method ofReportPortalLogger
class to log the screenshot to ReportPortalReportPortalLogger.captureAndAttachScreenshot(WebDriver webDriver, Sting message)
: It is overloading thecaptureScreenShot
method with additional capability of logging the message (passed in parameter) to ReportPortal along with the screenshotReportPortalLogger.attachFileInReportPortal(String message, File file)
: Logsmessage
and attachesfile
at INFO level toReportPortal
-
ScreenShotManager
class has all methods as private except one (captureScreenShot) .Following are the methods we can use to capture screenshots. This class creates the following directory under your project directory " TestReport/Screenshots" where the screenshots will be savedScreenShotManager.captureScreenShot(WebDriver webDriver)
: This method will take the calling step as its fileName, and its parent as the testName. It will then callprocessScreenShot()
method to capture, descale and save the screenshot. The method returns a File object where the captured file is stored.
-
CommandLineExecutor
class has all its public methods defined as static, so it doesn't require the consumer to create an object of this class. Following are the methods we can use to run CLI commands using JavaCommandLineExecutor.execCommand(final String[] command)
: Run the command passed in the parameter value and returns the response of typeCommandLineResponse
. The method automatically takes care of identifying the platform (Mac, Windows etc)CommandLineExecutor.execCommand(final String[] command, int timeoutInSeconds)
: It is overloading theexecCommand
method with additional capability of specifying the timeout in seconds. The process will wait for the specified time until we save the response from the command execution
-
CommandLineResponse
class stores the CLI command execution response as part of following methods:setExitCode(int exitCode)
andgetExitCode()
: Getters and Setters forprocess.exitValue()
setStdOut(String stdOut)
andgetStdOut()
: Getters and Setters forprocess.getInputStream()
setErrOut(String errOut)
andgetErrOut()
: Getters and Setters forprocess.getErrorStream()
-
@Step
annotation: Modularise your tests by dividing into multiple Steps to achieve Nested Steps in ReportPortal. Nested steps is a common way to group your test logs into small described pieces. For more details and how to use nested steps, refer ReportPortal-NestedSteps