diff --git a/pom.xml b/pom.xml index de953ce..915eeef 100644 --- a/pom.xml +++ b/pom.xml @@ -12,15 +12,15 @@ com.qaprosoft carina - 7.4.31 + 8.0.11 UTF-8 11 - - 7.5.0 - 7.5.0 - 5.7.1 + 31.1-jre + 7.9.0 + 7.9.0 + 5.7.5 @@ -37,9 +37,11 @@ + - com.qaprosoft - carina-core + com.google.guava + guava + ${guava.version} @@ -60,6 +62,10 @@ ${cucumber.reporting} + + com.qaprosoft + carina-core + diff --git a/src/main/java/com/qaprosoft/carina/core/foundation/cucumber/CucumberBaseTest.java b/src/main/java/com/qaprosoft/carina/core/foundation/cucumber/CucumberBaseTest.java index 2f83966..35a9899 100644 --- a/src/main/java/com/qaprosoft/carina/core/foundation/cucumber/CucumberBaseTest.java +++ b/src/main/java/com/qaprosoft/carina/core/foundation/cucumber/CucumberBaseTest.java @@ -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()); /** @@ -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 drivers = getDrivers(); for (Map.Entry 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)); } } } diff --git a/src/main/java/com/qaprosoft/carina/core/foundation/cucumber/CucumberNameResolver.java b/src/main/java/com/qaprosoft/carina/core/foundation/cucumber/CucumberNameResolver.java index 6ac014f..1239922 100644 --- a/src/main/java/com/qaprosoft/carina/core/foundation/cucumber/CucumberNameResolver.java +++ b/src/main/java/com/qaprosoft/carina/core/foundation/cucumber/CucumberNameResolver.java @@ -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" }) @@ -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, "["), "]"); } - } diff --git a/src/main/java/com/qaprosoft/carina/core/foundation/cucumber/CucumberRunner.java b/src/main/java/com/qaprosoft/carina/core/foundation/cucumber/CucumberRunner.java index a08d72a..b07602e 100644 --- a/src/main/java/com/qaprosoft/carina/core/foundation/cucumber/CucumberRunner.java +++ b/src/main/java/com/qaprosoft/carina/core/foundation/cucumber/CucumberRunner.java @@ -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; @@ -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; @@ -37,12 +35,12 @@ 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; @@ -50,24 +48,21 @@ 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 testNamesList = Collections.synchronizedList(new ArrayList()); - public CucumberRunner() { + protected CucumberRunner() { this.testNGCucumberRunner = new TestNGCucumberRunner(this.getClass()); TestNameResolverRegistry.set(new CucumberNameResolver()); } @@ -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 list = new ArrayList(); - + File[] finder = dir.listFiles((dir1, filename) -> filename.endsWith(".json")); + List 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; @@ -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 { @@ -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) { @@ -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; } diff --git a/src/main/java/com/qaprosoft/carina/core/foundation/cucumber/FeatureWrapperCustomName.java b/src/main/java/com/qaprosoft/carina/core/foundation/cucumber/FeatureWrapperCustomName.java index bf72a34..e86eb8a 100644 --- a/src/main/java/com/qaprosoft/carina/core/foundation/cucumber/FeatureWrapperCustomName.java +++ b/src/main/java/com/qaprosoft/carina/core/foundation/cucumber/FeatureWrapperCustomName.java @@ -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; } diff --git a/src/test/java/com/qaprosoft/carina/core/foundation/cucumber/CucumberRunnerTest.java b/src/test/java/com/qaprosoft/carina/core/foundation/cucumber/CucumberRunnerTest.java index 3d68285..0b6d1ba 100644 --- a/src/test/java/com/qaprosoft/carina/core/foundation/cucumber/CucumberRunnerTest.java +++ b/src/test/java/com/qaprosoft/carina/core/foundation/cucumber/CucumberRunnerTest.java @@ -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!"); }