### Run ChainLP with Docker Compose (H2 example) Source: https://github.com/anshooarora/chaintest/blob/main/Readme.md Clone the repository and start ChainLP using the H2 docker-compose file. H2 provides the most straightforward way to test but is not recommended for production use. ```bash # example git clone https://github.com/anshooarora/chaintest.git cd chaintest/chainlp/docker docker compose -f docker-compose-h2.yml up ``` -------------------------------- ### Start ChainLP with Docker Compose for H2, MySQL, and PostgreSQL Source: https://github.com/anshooarora/chaintest/blob/main/Readme.md Commands to start ChainLP using the provided docker-compose files for each supported database. The PostgreSQL command contains a typo ('posgres') in the source. ```bash # h2 docker compose -f docker-compose-h2.yml up # mysql docker compose -f docker-compose-mysql.yml up # posgres docker compose -f docker-compose-postgres.yml up ``` -------------------------------- ### Add chaintest-junit5 Gradle dependency Source: https://github.com/anshooarora/chaintest/blob/main/plugins/chaintest-junit5/Readme.md Add the plugin dependency to your Gradle build. Do not include chaintest-core separately; it is included automatically. ```groovy implementation 'com.aventstack:chaintest-junit5:$version' ``` -------------------------------- ### Embed screenshot using qualified name during test Source: https://github.com/anshooarora/chaintest/blob/main/plugins/chaintest-junit5/Readme.md Attach a screenshot during test execution using the qualified name obtained from ChainPluginService.getInstance().getQualifiedName(). ```java @Test public void testMethod(final TestInfo info) { final String qualifiedName = ChainPluginService.getInstance() .getQualifiedName(info.getTestMethod().get()); ChainPluginService.getInstance().embed(qualifiedName, bytes, "image/png"); } ``` -------------------------------- ### Maven dependency for chaintest-core Source: https://github.com/anshooarora/chaintest/blob/main/core/chaintest-core-java/Readme.md Add this dependency to your Maven pom.xml to use the ChainTest core client library. Replace ${chaintest.core.version} with the desired version. The library is licensed under Apache-2.0. ```xml com.aventstack chaintest-core ${chaintest.core.version} ``` -------------------------------- ### Add chaintest-junit5 Maven dependency Source: https://github.com/anshooarora/chaintest/blob/main/plugins/chaintest-junit5/Readme.md Add the plugin dependency to your Maven pom.xml. Do not include chaintest-core separately; it is included automatically. ```xml com.aventstack chaintest-junit5 ${chaintest.junit5.version} ``` -------------------------------- ### Embed screenshot in @AfterTestExecutionCallback (version 1.0.5+) Source: https://github.com/anshooarora/chaintest/blob/main/plugins/chaintest-junit5/Readme.md Attach a screenshot after test completion using the AfterTestExecutionCallback hook. Requires version 1.0.5 or greater. ```java // Version 1.0.5 and greater public class ChainTestExecutionCallback implements AfterTestExecutionCallback { @Override public void afterTestExecution(final ExtensionContext context) { ChainPluginService.getInstance().embed(context.getTestMethod().get(), bytes, "image/png"); } } ``` -------------------------------- ### Configure Cucumber runner with ChainTestCucumberListener Source: https://github.com/anshooarora/chaintest/blob/main/plugins/chaintest-cucumber-jvm/Readme.md Adds the ChainTestCucumberListener to the Cucumber runner class via @CucumberOptions. Requires chaintest.properties on the classpath. ```java @RunWith(Cucumber.class) @CucumberOptions(plugin = { "com.aventstack.chaintest.plugins.ChainTestCucumberListener:" }) public class RunCukes { } ``` -------------------------------- ### Embed screenshot using qualified name in @AfterTestExecutionCallback Source: https://github.com/anshooarora/chaintest/blob/main/plugins/chaintest-junit5/Readme.md Attach a screenshot after test completion using the qualified name obtained from ChainPluginService.getInstance().getQualifiedName(). ```java public class ChainTestExecutionCallback implements AfterTestExecutionCallback { @Override public void afterTestExecution(final ExtensionContext context) { final String qualifiedName = ChainPluginService.getInstance() .getQualifiedName(context.getTestMethod().get()); ChainPluginService.getInstance().embed(qualifiedName, bytes, "image/png"); } } ``` -------------------------------- ### Add chaintest-cucumber-jvm Maven dependency Source: https://github.com/anshooarora/chaintest/blob/main/plugins/chaintest-cucumber-jvm/Readme.md Declares the plugin dependency in a Maven pom.xml. The chaintest-core dependency is automatically included, so do not add it separately. ```xml com.aventstack chaintest-cucumber-jvm ${chaintest.cucumberjvm.version} provided ``` -------------------------------- ### Add chaintest-cucumber-jvm Gradle dependency Source: https://github.com/anshooarora/chaintest/blob/main/plugins/chaintest-cucumber-jvm/Readme.md Declares the plugin dependency in a Gradle build script. The chaintest-core dependency is automatically included, so do not add it separately. ```groovy implementation 'com.aventstack:chaintest-cucumber-jvm:$version' ``` -------------------------------- ### Enable attach-to-step property via System.setProperty Source: https://github.com/anshooarora/chaintest/blob/main/plugins/chaintest-cucumber-jvm/Readme.md Sets the chaintest.plugins.cucumber.attach-to-step property programmatically to attach embeds/logs to the last executed Step instead of the Scenario. Available from version 1.0.12. ```java System.setProperty("chaintest.plugins.cucumber.attach-to-step", "true"); ``` -------------------------------- ### Test class with ChainTestListener Source: https://github.com/anshooarora/chaintest/blob/main/plugins/chaintest-testng/Readme.md Annotate your TestNG test class with @Listeners(ChainTestListener.class) to enable ChainTest reporting. The example shows a simple test method. ```java import org.testng.annotations.Listeners; import com.aventstack.chaintest.plugins.ChainTestListener; import org.testng.Assert; import org.testng.annotations.Test; @Listeners(ChainTestListener.class) public class TestClass { @Test public void sum() { Assert.assertTrue(true); } } ``` -------------------------------- ### Enable attach-to-step property via Maven command Source: https://github.com/anshooarora/chaintest/blob/main/plugins/chaintest-cucumber-jvm/Readme.md Sets the chaintest.plugins.cucumber.attach-to-step property as a System Property to attach embeds/logs to the last executed Step instead of the Scenario. Available from version 1.0.12. ```bash mvn clean test -Dchaintest.plugins.cucumber.attach-to-step=true ``` -------------------------------- ### Embed screenshot during test execution (version 1.0.5+) Source: https://github.com/anshooarora/chaintest/blob/main/plugins/chaintest-junit5/Readme.md Attach a screenshot while the test is in-flight using ChainPluginService.getInstance().embed() with the TestInfo method. Requires version 1.0.5 or greater. ```java // Version 1.0.5 and greater @Test public void testMethod(final TestInfo info) { ChainPluginService.getInstance().embed(info.getTestMethod().get(), bytes, "image/png"); } ``` -------------------------------- ### Annotate test class with @ExtendWith(ChainTestExecutionCallback.class) Source: https://github.com/anshooarora/chaintest/blob/main/plugins/chaintest-junit5/Readme.md Annotate your JUnit 5 test class with @ExtendWith(ChainTestExecutionCallback.class) to enable ChainTest integration. Requires chaintest.properties on the classpath. ```java import com.aventstack.chaintest.plugins.ChainTestExecutionCallback; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @ExtendWith(ChainTestExecutionCallback.class) public class TestClass { @Test public void sum() { Assert.assertTrue(true); } } ``` -------------------------------- ### ChainLP configuration in chaintest.properties Source: https://github.com/anshooarora/chaintest/blob/main/Readme.md Required properties to connect the client to ChainLP: set chaintest.project.name and enable the chainlp generator with the server's host:port. The host:port is where the client connects over TCP. ```properties # (only the relevant bits shows below) # chaintest configuration chaintest.project.name=default # generators: ## chainlp chaintest.generator.chainlp.enabled=true chaintest.generator.chainlp.host.url= ``` -------------------------------- ### Configure AWS S3 storage for embeds Source: https://github.com/anshooarora/chaintest/blob/main/Readme.md Enable S3 storage for embeds by setting chaintest.storage.service.enabled=true, choosing aws-s3, and providing the bucket name. The client and ChainLP both use the AWS Credential Chain for authentication. ```properties # storage chaintest.storage.service.enabled=true # [azure-blob, aws-s3] chaintest.storage.service=aws-s3 # s3 bucket or azure container name chaintest.storage.service.container-name= ``` -------------------------------- ### Log and embed in @BeforeMethod Source: https://github.com/anshooarora/chaintest/blob/main/plugins/chaintest-testng/Readme.md Use ChainTestListener.log and ChainTestListener.embed in the @BeforeMethod hook to attach logs and screenshots before the test method runs. ```java @BeforeMethod public void beforeMethod(final ITestResult result) { //log ChainTestListener.log("log example"); // embed ChainTestListener.embed(bytes, "image/png"); } ``` -------------------------------- ### Add chaintest-testng Gradle dependency Source: https://github.com/anshooarora/chaintest/blob/main/plugins/chaintest-testng/Readme.md Add the plugin dependency to your Gradle build. Do not include chaintest-core; it is included automatically. ```groovy implementation 'com.aventstack:chaintest-testng:$version' ``` -------------------------------- ### Java properties configuration for ChainTest Source: https://github.com/anshooarora/chaintest/blob/main/Config.md Configuration properties for ChainTest in Java, covering project name, storage service, generators (chainlp, simple, email), and their settings. Storage service can be azure-blob or aws-s3. Generators include chainlp (disabled by default), simple (enabled by default), and email (enabled by default). ```properties # chaintest configuration chaintest.project.name=default # storage chaintest.storage.service.enabled=false # [azure-blob, aws-s3] chaintest.storage.service=azure-blob # s3 bucket or azure container name chaintest.storage.service.container-name= # generators: ## chainlp chaintest.generator.chainlp.enabled=false chaintest.generator.chainlp.class-name=com.aventstack.chaintest.generator.ChainLPGenerator chaintest.generator.chainlp.host.url=http://localhost/ chaintest.generator.chainlp.client.request-timeout-s=30 chaintest.generator.chainlp.client.expect-continue=false chaintest.generator.chainlp.client.max-retries=3 chaintest.generator.chainlp.persist-embeds=true ## simple chaintest.generator.simple.enabled=true chaintest.generator.simple.document-title=chaintest chaintest.generator.simple.class-name=com.aventstack.chaintest.generator.ChainTestSimpleGenerator chaintest.generator.simple.output-file=target/chaintest/Index.html chaintest.generator.simple.offline=false chaintest.generator.simple.dark-theme=true chaintest.generator.simple.datetime-format=yyyy-MM-dd hh:mm:ss a chaintest.generator.simple.js= chaintest.generator.simple.css= ## email chaintest.generator.email.enabled=true chaintest.generator.email.class-name=com.aventstack.chaintest.generator.ChainTestEmailGenerator chaintest.generator.email.output-file=target/chaintest/Email.html chaintest.generator.email.datetime-format=yyyy-MM-dd hh:mm:ss a ``` -------------------------------- ### Log and embed in @AfterMethod Source: https://github.com/anshooarora/chaintest/blob/main/plugins/chaintest-testng/Readme.md Use ChainTestListener.log and ChainTestListener.embed in the @AfterMethod hook to attach logs and screenshots after the test method completes. ```java @AfterMethod public void afterMethod(final ITestResult result) { //log ChainTestListener.log("log example"); // embed ChainTestListener.embed(bytes, "image/png"); } ``` -------------------------------- ### Add chaintest-testng Maven dependency Source: https://github.com/anshooarora/chaintest/blob/main/plugins/chaintest-testng/Readme.md Add the plugin dependency to your Maven pom.xml. Do not include chaintest-core; it is included automatically. ```xml com.aventstack chaintest-testng ${chaintest.testng.version} ``` -------------------------------- ### Log and embed in test method Source: https://github.com/anshooarora/chaintest/blob/main/plugins/chaintest-testng/Readme.md Use ChainTestListener.log and ChainTestListener.embed inside a test method to attach logs and screenshots while the test is in-flight or completing. ```java @Test public void testMethod(final Method method) { //log ChainTestListener.log("log example"); // embed ChainTestListener.embed(bytes, "image/png"); } ``` -------------------------------- ### Disable ChainLP embed persistence in DB Source: https://github.com/anshooarora/chaintest/blob/main/Readme.md As of chaintest-core:1.0.11 and ChainLP:0.0.9, embeds are stored in DB by default. Set this property to false to disable DB persistence in favor of S3 via chaintest.storage.service.*. ```properties # default: true (embeds will be persisted in db) chaintest.generator.chainlp.persist-embeds=true ```