Skip to content

Commit

Permalink
Merge pull request #77 from reportportal/examples-updates
Browse files Browse the repository at this point in the history
Examples updates
  • Loading branch information
HardNorth authored Feb 12, 2024
2 parents 312f19c + c599189 commit 5f76fc8
Show file tree
Hide file tree
Showing 167 changed files with 1,519 additions and 1,854 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up JDK 11
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
Expand Down
18 changes: 3 additions & 15 deletions example-cucumber/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
<dependency>
<groupId>com.epam.reportportal</groupId>
<artifactId>agent-java-cucumber</artifactId>
<version>5.1.4</version>
<version>5.2.1</version>
</dependency>

<dependency>
<groupId>com.epam.reportportal</groupId>
<artifactId>logger-java-logback</artifactId>
<version>5.1.6</version>
<version>5.2.1</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -59,7 +59,7 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.3.8</version>
<version>1.3.12</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -91,18 +91,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import gherkin.formatter.model.Scenario;
import gherkin.formatter.model.Step;

import javax.annotation.Nonnull;

import static org.apache.commons.lang3.StringUtils.isNotBlank;

/**
Expand All @@ -33,8 +35,9 @@ public class ScenarioReporterTestCaseId extends ScenarioReporter {
public static final String TEST_TRACKING_TICKET_PREFIX = "JIRA";

// Getting our custom tag from already parsed attributes and set it as Test Case ID for the item
@Nonnull
@Override
protected StartTestItemRQ buildStartScenarioRequest(Scenario scenario, String uri) {
protected StartTestItemRQ buildStartScenarioRequest(@Nonnull Scenario scenario, @Nonnull String uri) {
StartTestItemRQ rq = super.buildStartScenarioRequest(scenario, uri);
rq.getAttributes()
.stream()
Expand All @@ -46,8 +49,9 @@ protected StartTestItemRQ buildStartScenarioRequest(Scenario scenario, String ur
}

// Removing Test Case ID from nested steps as redundant
@Nonnull
@Override
protected StartTestItemRQ buildStartStepRequest(Step step, String stepPrefix, Match match) {
protected StartTestItemRQ buildStartStepRequest(@Nonnull Step step, String stepPrefix, @Nonnull Match match) {
StartTestItemRQ rq = super.buildStartStepRequest(step, stepPrefix, match);
rq.setTestCaseId(null);
return rq;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ import org.junit.runner.RunWith
*/

@RunWith(Cucumber.class)
@CucumberOptions(plugin = ["pretty",
"com.epam.reportportal.cucumber.StepReporter"], features = ["src/test/resources/features/attribute"]
, glue = ["src/test/groovy/cucumber"]
)
class RunCucumberGroovy {
@CucumberOptions(plugin = ["pretty", "com.epam.reportportal.cucumber.StepReporter"], features = ["src/test/resources/features/attribute"],
glue = ["src/test/groovy/cucumber"])
class RunStepReporterTest {

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* A JUnit runner for Cucumber which is using customized {@link ScenarioReporterTestCaseId} reporter.
*/
@RunWith(Cucumber.class)
@CucumberOptions(plugin = { "pretty", "com.epam.reportportal.example.cucumber.reporter.ScenarioReporterTestCaseId" }, features = {
"src/test/resources/features/attribute" }, glue = { "com.epam.reportportal.example.cucumber.attribute" })
public class RunCukesTestScenarioReporter {
@CucumberOptions(plugin = { "pretty", "com.epam.reportportal.example.cucumber.reporter.ScenarioReporterTestCaseId" },
features = "src/test/resources/features/attribute")
public class RunScenarioReporterTest {
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(plugin = { "pretty", "com.epam.reportportal.cucumber.StepReporter" },
features = {"src/test/resources/features/attribute"},
glue = {"com.epam.reportportal.example.cucumber.attribute"})
public class RunCukesTestStepReporter {
}
@CucumberOptions(plugin = { "pretty", "com.epam.reportportal.cucumber.StepReporter" }, features = "src/test/resources/features/attribute")
public class RunStepReporterTest {
}
Original file line number Diff line number Diff line change
@@ -1,139 +1,96 @@
package com.epam.reportportal.example.cucumber.logging;

import com.epam.reportportal.example.cucumber.util.AttachmentHelper;
import com.epam.reportportal.example.cucumber.util.LoggingUtils;
import com.epam.reportportal.example.cucumber.util.MagicRandomizer;
import com.epam.reportportal.service.ReportPortal;
import com.epam.reportportal.utils.files.Utils;
import cucumber.api.java.en.Given;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.io.Files;
import com.google.common.io.Resources;

import java.io.File;
import java.io.IOException;
import java.util.Base64;
import java.util.Date;

public class ReportAttachmentsTest {

private static final Logger LOGGER = LoggerFactory.getLogger(ReportAttachmentsTest.class);
public static final String XML_FILE_PATH = "files/file.xml";
public static final String JSON_FILE_PATH = "files/file.json";
public static final String FILE_FOLDER_PATH = "src/test/resources/files";
public static final String XML_FILE_PATH = FILE_FOLDER_PATH + "/file.xml";
public static final String JSON_FILE_PATH = FILE_FOLDER_PATH + "/file.json";

@Given("I attach logCss")
public void logCss() throws IOException {
File file = File.createTempFile("rp-test", ".css");
Resources.asByteSource(Resources.getResource("files/file.css")).copyTo(Files.asByteSink(file));
LoggingUtils.log(file, "I'm logging CSS");
public void logCss() {
LoggingUtils.log(new File(FILE_FOLDER_PATH + "/file.css"), "I'm logging CSS");
}

@Given("I attach logHtml")
public void logHtml() throws IOException {
File file = File.createTempFile("rp-test", ".html");
Resources.asByteSource(Resources.getResource("files/file.html")).copyTo(Files.asByteSink(file));
LoggingUtils.log(file, "I'm logging HTML");
public void logHtml() {
LoggingUtils.log(new File(FILE_FOLDER_PATH + "/file.html"), "I'm logging HTML");
}

@Given("I attach logPdf")
public void logPdf() throws IOException {
File file = File.createTempFile("rp-test", ".pdf");
Resources.asByteSource(Resources.getResource("files/file.pdf")).copyTo(Files.asByteSink(file));
LoggingUtils.log(file, "I'm logging PDF");
public void logPdf() {
LoggingUtils.log(new File(FILE_FOLDER_PATH + "/file.pdf"), "I'm logging PDF");
}

@Given("I attach logZip")
public void logZip() throws IOException {
File file = File.createTempFile("rp-test", ".zip");
Resources.asByteSource(Resources.getResource("files/file.zip")).copyTo(Files.asByteSink(file));
LoggingUtils.log(file, "I'm logging ZIP");
public void logZip() {
LoggingUtils.log(new File(FILE_FOLDER_PATH + "/file.zip"), "I'm logging ZIP");
}

@Given("I attach logHar")
public void logHar() throws IOException {
File file = File.createTempFile("har", ".json");
Resources.asByteSource(Resources.getResource("files/file.har")).copyTo(Files.asByteSink(file));
LoggingUtils.log(file, "I'm logging HAR");
public void logHar() {
LoggingUtils.log(new File(FILE_FOLDER_PATH + "/file.har"), "I'm logging HAR");
}

@Given("I attach logJavascript")
public void logJavascript() throws IOException {
File file = File.createTempFile("rp-test", ".js");
Resources.asByteSource(Resources.getResource("files/file.js")).copyTo(Files.asByteSink(file));
LoggingUtils.log(file, "I'm logging JS");
public void logJavascript() {
LoggingUtils.log(new File(FILE_FOLDER_PATH + "/file.js"), "I'm logging JS");
}

@Given("I attach logPhp")
public void logPhp() throws IOException {
File file = File.createTempFile("rp-test", ".php");
Resources.asByteSource(Resources.getResource("files/file.php")).copyTo(Files.asByteSink(file));
LoggingUtils.log(file, "I'm logging php");
public void logPhp() {
LoggingUtils.log(new File(FILE_FOLDER_PATH + "/file.php"), "I'm logging PHP");
}

@Given("I attach logPlain")
public void logPlain() throws IOException {
File file = File.createTempFile("rp-test", ".txt");
Resources.asByteSource(Resources.getResource("files/file.txt")).copyTo(Files.asByteSink(file));
LoggingUtils.log(file, "I'm logging txt");
public void logPlain() {
LoggingUtils.log(new File(FILE_FOLDER_PATH + "/file.txt"), "I'm logging TXT");
}

@Given("I attach logCsv")
public void logCsv() throws IOException {
File file = File.createTempFile("rp-test", ".csv");
Resources.asByteSource(Resources.getResource("files/file.csv")).copyTo(Files.asByteSink(file));
LoggingUtils.log(file, "I'm logging txt");
public void logCsv() {
LoggingUtils.log(new File(FILE_FOLDER_PATH + "/file.csv"), "I'm logging CSV");
}

@Given("I attach logCmd")
public void logCmd() throws IOException {
File file = File.createTempFile("rp-test", ".cmd");
Resources.asByteSource(Resources.getResource("files/file.cmd")).copyTo(Files.asByteSink(file));
LoggingUtils.log(file, "I'm logging txt");
public void logCmd() {
LoggingUtils.log(new File(FILE_FOLDER_PATH + "/file.cmd"), "I'm logging CMD");
}

@Given("I attach logXmlBase64")
public void logXmlBase64() throws IOException {
/* here we are logging some binary data as BASE64 string */
LOGGER.info(
"RP_MESSAGE#BASE64#{}#{}",
Base64.getEncoder().encodeToString(Resources.asByteSource(Resources.getResource(XML_FILE_PATH)).read()),
"I'm logging content via BASE64"
);
LoggingUtils.log(Utils.getFileAsByteSource(new File(XML_FILE_PATH)).read(), "I'm logging content via BASE64");
}

@Given("I attach logXmlFile")
public void logXmlFile() throws IOException {
File file = File.createTempFile("rp-test", "xml");
Resources.asByteSource(Resources.getResource(XML_FILE_PATH)).copyTo(Files.asByteSink(file));

LOGGER.info("RP_MESSAGE#FILE#{}#{}", file.getAbsolutePath(), "I'm logging content via temp file");
public void logXmlFile() {
File file = AttachmentHelper.getFileFromResources(FILE_FOLDER_PATH, "file", "xml");
LoggingUtils.log(file, "I'm logging content via temp file");
}

@Given("I attach logJsonBase64")
public void logJsonBase64() throws IOException {
@Given("I attach logBase64")
public void logBase64() throws IOException {
/* here we are logging some binary data as BASE64 string */
ReportPortal.emitLog("LAUNCH LOG MESAGE", "error", new Date());

File file = File.createTempFile("rp-test", ".css");
Resources.asByteSource(Resources.getResource("files/file.css")).copyTo(Files.asByteSink(file));
ReportPortal.emitLog("LAUNCH LOG MESAGE WITH ATTACHMENT", "error", new Date(), file);

LOGGER.info(
"RP_MESSAGE#BASE64#{}#{}",
Base64.getEncoder().encodeToString(Resources.asByteSource(Resources.getResource(JSON_FILE_PATH)).read()),
"I'm logging content via BASE64"
);
ReportPortal.emitLog("ITEM LOG MESSAGE", "error", new Date());
ReportPortal.emitLog("ITEM LOG MESSAGE WITH ATTACHMENT", "error", new Date(), new File(FILE_FOLDER_PATH + "/file.css"));
LoggingUtils.log(Utils.getFileAsByteSource(new File(JSON_FILE_PATH)).read(), "I'm logging content via BASE64");
}

@Given("I attach logJsonFile")
public void logJsonFile() throws IOException, InterruptedException {
public void logJsonFile() {
/* here we are logging some binary data as file (useful for selenium) */
File file = File.createTempFile("rp-test", ".json");
Resources.asByteSource(Resources.getResource(JSON_FILE_PATH)).copyTo(Files.asByteSink(file));

for (int i = 0; i < 1; i++) {
LOGGER.info("RP_MESSAGE#FILE#{}#{}", file.getAbsolutePath(), "I'm logging content via temp file");
}
Thread.sleep(5000L);
File file = AttachmentHelper.getFileFromResources(FILE_FOLDER_PATH, "file", "json");
LoggingUtils.log(file, "I'm logging content via temp file");
}

@Given("I attach logImageBase64")
Expand All @@ -144,15 +101,11 @@ public void logImageBase64() throws IOException {
boolean happy = MagicRandomizer.checkYourLucky(30);
String image = getImageResource(happy);

LOGGER.info(
"RP_MESSAGE#BASE64#{}#{}",
Base64.getEncoder().encodeToString(Resources.asByteSource(Resources.getResource(image)).read()),
"Pug is " + (happy ? "HAPPY" : "NOT HAPPY")
);
LoggingUtils.log(Utils.getFileAsByteSource(new File(image)).read(), "Pug is " + (happy ? "HAPPY" : "NOT HAPPY"));
}
}

private String getImageResource(boolean lucky) {
return "pug/" + (lucky ? "lucky.jpg" : "unlucky.jpg");
return "src/test/resources/pug/" + (lucky ? "lucky.jpg" : "unlucky.jpg");
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package com.epam.reportportal.example.cucumber.util;

public enum Attachment {
CMD(".cmd"),
CSS(".css"),
CSV(".csv"),
HAR(".har"),
HTML(".html"),
JPG(".jpg"),
JS(".js"),
JSON(".json"),
PDF(".pdf"),
PHP(".php"),
PNG(".png"),
TAR(".tar"),
TAR_GZ(".tar.gz"),
TXT(".txt"),
XML(".xml"),
ZIP(".zip");
CMD("cmd"),
CSS("css"),
CSV("csv"),
HAR("har"),
HTML("html"),
JPG("jpg"),
JS("js"),
JSON("json"),
PDF("pdf"),
PHP("php"),
PNG("png"),
TAR("tar"),
TAR_GZ("tar.gz"),
TXT("txt"),
XML("xml"),
ZIP("zip");

private String extension;
private final String extension;

public String getExtension() {
return extension;
Expand Down
Loading

0 comments on commit 5f76fc8

Please sign in to comment.