Skip to content

Commit

Permalink
Merge pull request #64 from zebrunner/develop
Browse files Browse the repository at this point in the history
8.0.0
  • Loading branch information
vdelendik authored Apr 14, 2023
2 parents b967fc0 + 6031453 commit 56d9249
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 73 deletions.
20 changes: 13 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
<parent>
<groupId>com.qaprosoft</groupId>
<artifactId>carina</artifactId>
<version>7.4.31</version>
<version>8.0.11</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>11</java.version>

<cucumber.testng.version>7.5.0</cucumber.testng.version>
<cucumber.java.version>7.5.0</cucumber.java.version>
<cucumber.reporting>5.7.1</cucumber.reporting>
<guava.version>31.1-jre</guava.version>
<cucumber.testng.version>7.9.0</cucumber.testng.version>
<cucumber.java.version>7.9.0</cucumber.java.version>
<cucumber.reporting>5.7.5</cucumber.reporting>
</properties>
<repositories>
<!-- Uncomment only for testing any SNAPSHOT version of carina! -->
Expand All @@ -37,9 +37,11 @@
</repository-->
</repositories>
<dependencies>
<!-- We should set correct version of guava for Selenium. Copied from the carina-webdriver -->
<dependency>
<groupId>com.qaprosoft</groupId>
<artifactId>carina-core</artifactId>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<!-- Cucumber -->
<dependency>
Expand All @@ -60,6 +62,10 @@
<version>${cucumber.reporting}</version>
</dependency>

<dependency>
<groupId>com.qaprosoft</groupId>
<artifactId>carina-core</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,19 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.events.EventFiringWebDriver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.qaprosoft.carina.core.foundation.webdriver.CarinaDriver;
import com.qaprosoft.carina.core.foundation.webdriver.Screenshot;
import com.zebrunner.carina.webdriver.CarinaDriver;
import com.zebrunner.carina.webdriver.Screenshot;
import com.zebrunner.carina.webdriver.ScreenshotType;

import io.cucumber.java.After;
import io.cucumber.java.Before;
import io.cucumber.java.Scenario;


public class CucumberBaseTest extends CucumberRunner {

private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

/**
Expand All @@ -56,20 +55,15 @@ public void takeScreenshotOfFailure(Scenario scenario) {
LOGGER.info("In @After takeScreenshotOfFailure");
if (scenario.isFailed()) {
LOGGER.error("Cucumber Scenario FAILED! Creating screenshot.");
String screenId = "";

ConcurrentHashMap<String, CarinaDriver> drivers = getDrivers();

for (Map.Entry<String, CarinaDriver> entry : drivers.entrySet()) {
String driverName = entry.getKey();
WebDriver drv = entry.getValue().getDriver();

if (drv instanceof EventFiringWebDriver) {
drv = ((EventFiringWebDriver) drv).getWrappedDriver();
}

screenId = Screenshot.capture(drv, driverName + ": " + scenario.getName()); // in case of failure
LOGGER.debug("cucumber screenshot generated: " + screenId);
// in case of failure
Screenshot.capture(entry.getValue().getDriver(),
ScreenshotType.UNSUCCESSFUL_DRIVER_ACTION,
driverName + ": " + scenario.getName())
.ifPresent(fileName -> LOGGER.debug("cucumber screenshot generated: {}", fileName));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
import org.apache.commons.lang3.StringUtils;
import org.testng.ITestResult;

import com.qaprosoft.carina.core.foundation.commons.SpecialKeywords;
import com.zebrunner.agent.testng.core.testname.TestNameResolver;
import com.zebrunner.carina.utils.commons.SpecialKeywords;

import io.cucumber.testng.FeatureWrapper;
import io.cucumber.testng.PickleWrapper;

public class CucumberNameResolver implements TestNameResolver {

private final static String FEATURE_NAME_OPTIONAL = "Optional";
private static final String FEATURE_NAME_OPTIONAL = "Optional";

@Override
@SuppressWarnings({ "unlikely-arg-type" })
Expand Down Expand Up @@ -50,13 +50,10 @@ public static String prepareTestName(String strFormat, PickleWrapper pickleWrapp
}

private static String cleanQuotes(String originalString) {
String res = StringUtils.removeEnd(StringUtils.removeStart(originalString, "\""), "\"");
return res;
return StringUtils.removeEnd(StringUtils.removeStart(originalString, "\""), "\"");
}

private static String cleanBrackets(String originalString) {
String res = StringUtils.removeEnd(StringUtils.removeStart(originalString, "["), "]");
return res;
return StringUtils.removeEnd(StringUtils.removeStart(originalString, "["), "]");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package com.qaprosoft.carina.core.foundation.cucumber;

import java.io.File;
import java.io.FilenameFilter;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -27,7 +26,6 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import com.qaprosoft.carina.core.foundation.utils.R;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -37,37 +35,34 @@
import org.testng.annotations.Test;

import com.qaprosoft.carina.core.foundation.AbstractTest;
import com.qaprosoft.carina.core.foundation.commons.SpecialKeywords;
import com.qaprosoft.carina.core.foundation.report.ReportContext;
import com.qaprosoft.carina.core.foundation.utils.Configuration;
import com.qaprosoft.carina.core.foundation.utils.Configuration.Parameter;
import com.zebrunner.agent.core.registrar.Artifact;
import com.zebrunner.agent.testng.core.testname.TestNameResolverRegistry;
import com.zebrunner.carina.utils.Configuration;
import com.zebrunner.carina.utils.R;
import com.zebrunner.carina.utils.commons.SpecialKeywords;
import com.zebrunner.carina.utils.report.ReportContext;

import io.cucumber.testng.FeatureWrapper;
import io.cucumber.testng.PickleWrapper;
import io.cucumber.testng.TestNGCucumberRunner;
import net.masterthought.cucumber.ReportBuilder;

public abstract class CucumberRunner extends AbstractTest {

private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

private static final String STR_FORMAT_TEST_NAME = "%s (%s)";
private static final String STR_FORMAT_TEST_FOLDER_NAME = "%s_%s";
private static final String EXAMPLE_FILE_NAME_FORMAT = "_ex%04d";
private static final String EXAMPLE_FILE_NAME_REGEX = "(_ex\\d+){0,1}";
private static final String EXAMPLE_TEST_NAME_FORMAT = " EX%04d";
private static final String EXAMPLE_TEST_NAME_REGEX = "( EX\\d+){0,1}";
private static final String CUCUMBER_REPORT_NAME = "Cucumber report";
private static final String ZAFIRA_REPORT_CI = "ZafiraReport";
private static final String CUCUMBER_REPORT_CI = "CucumberReport";
private TestNGCucumberRunner testNGCucumberRunner;

private final static String STR_FORMAT_TEST_NAME = "%s (%s)";
private final static String STR_FORMAT_TEST_FOLDER_NAME = "%s_%s";
private final static String EXAMPLE_FILE_NAME_FORMAT = "_ex%04d";
private final static String EXAMPLE_FILE_NAME_REGEX = "(_ex\\d+){0,1}";
private final static String EXAMPLE_TEST_NAME_FORMAT = " EX%04d";
private final static String EXAMPLE_TEST_NAME_REGEX = "( EX\\d+){0,1}";

private final static String CUCUMBER_REPORT_NAME = "Cucumber report";
private final static String ZAFIRA_REPORT_CI = "ZafiraReport";
private final static String CUCUMBER_REPORT_CI = "CucumberReport";

List<String> testNamesList = Collections.synchronizedList(new ArrayList<String>());

public CucumberRunner() {
protected CucumberRunner() {
this.testNGCucumberRunner = new TestNGCucumberRunner(this.getClass());
TestNameResolverRegistry.set(new CucumberNameResolver());
}
Expand Down Expand Up @@ -134,33 +129,22 @@ public void tearDownClass(ITestContext context) throws Exception {
* Generate Cucumber Report
*/
private void generateCucumberReport() {
String buildNumber = Configuration.get(Parameter.APP_VERSION);

String buildNumber = Configuration.get(Configuration.Parameter.APP_VERSION);
try {
// String RootDir = System.getProperty("user.dir");
File file = ReportContext.getBaseDir();

File reportOutputDirectory = new File(String.format("%s/%s", file, SpecialKeywords.CUCUMBER_REPORT_FOLDER));

File dir = new File("target/");

File[] finder = dir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String filename) {
return filename.endsWith(".json");
}
});

List<String> list = new ArrayList<String>();

File[] finder = dir.listFiles((dir1, filename) -> filename.endsWith(".json"));
List<String> list = new ArrayList<>();
for (File fl : finder) {
LOGGER.info("Report json: " + fl.getName());
LOGGER.info("Report json: {}", fl.getName());
list.add("target/" + fl.getName());
}

// buildNumber should be parsable Integer
buildNumber = buildNumber.replace(".", "").replace(",", "");

if (list.size() > 0) {
if (!list.isEmpty()) {
// String buildNumber = "1";
// String buildProject = "CUCUMBER";
// boolean skippedFails = true;
Expand All @@ -179,8 +163,8 @@ public boolean accept(File dir, String filename) {
ReportBuilder reportBuilder = new ReportBuilder(list, configuration);
reportBuilder.generateReports();

if (!Configuration.isNull(Parameter.REPORT_URL)) {
String reportUrl = Configuration.get(Parameter.REPORT_URL);
if (!Configuration.isNull(Configuration.Parameter.REPORT_URL)) {
String reportUrl = Configuration.get(Configuration.Parameter.REPORT_URL);
if (reportUrl.endsWith(ZAFIRA_REPORT_CI)) {
Artifact.attachReferenceToTestRun(CUCUMBER_REPORT_NAME, reportUrl.replace(ZAFIRA_REPORT_CI, CUCUMBER_REPORT_CI));
} else {
Expand All @@ -189,7 +173,6 @@ public boolean accept(File dir, String filename) {
}
} else {
LOGGER.info("There are no json files for cucumber report.");
return;
}

} catch (Exception e) {
Expand All @@ -215,7 +198,7 @@ public static boolean isCucumberReportFolderExists() {
}
}
} catch (Exception e) {
LOGGER.debug("Error happen during checking that CucumberReport Folder exists or not. Error: " + e.getMessage());
LOGGER.debug("Error happen during checking that CucumberReport Folder exists or not. Error: {}", e.getMessage());
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@

public class FeatureWrapperCustomName {

private static final String OPTIONAL_KEY = "Optional";
private final FeatureWrapper featureWrapper;

private final static String OPTIONAL_KEY = "Optional";

FeatureWrapperCustomName(FeatureWrapper featureWrapper) {
this.featureWrapper = featureWrapper;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
import org.testng.annotations.Test;

public class CucumberRunnerTest {
@Test()
public void hellowCucumber() {

@Test
public void helloCucumber() {
System.out.println("Hello Carina Cucumber!");
}

Expand Down

0 comments on commit 56d9249

Please sign in to comment.