From 7a9f1bcce318499070c330e204cb1ecb7b2454c8 Mon Sep 17 00:00:00 2001 From: Andrei Kamarouski Date: Thu, 6 Apr 2023 15:46:22 +0300 Subject: [PATCH 1/5] bump up carina-core to 8.0.11, cucumber-testng and cucumber-java to 7.9.0, cucumber-reporting to 5.7.5 --- pom.xml | 9 +++-- .../foundation/cucumber/CucumberBaseTest.java | 29 ++++++++------- .../cucumber/CucumberNameResolver.java | 36 ++----------------- .../foundation/cucumber/CucumberRunner.java | 15 ++++---- 4 files changed, 30 insertions(+), 59 deletions(-) diff --git a/pom.xml b/pom.xml index 3832c66..818916c 100644 --- a/pom.xml +++ b/pom.xml @@ -12,15 +12,14 @@ com.qaprosoft carina - 7.4.29 + 8.0.11 UTF-8 11 - - 7.5.0 - 7.5.0 - 5.7.1 + 7.9.0 + 7.9.0 + 5.7.5 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..1e2e40b 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 @@ -20,12 +20,13 @@ import java.util.concurrent.ConcurrentHashMap; import org.openqa.selenium.WebDriver; -import org.openqa.selenium.support.events.EventFiringWebDriver; +import org.openqa.selenium.support.decorators.Decorated; 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; @@ -56,21 +57,23 @@ 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(removeListeners(entry.getValue().getDriver()), + ScreenshotType.UNSUCCESSFUL_DRIVER_ACTION, + driverName + ": " + scenario.getName()) + .ifPresent(fileName -> LOGGER.debug("cucumber screenshot generated: {}", fileName)); } } } + + /** + * Clean driver from Decorator + */ + private static WebDriver removeListeners(WebDriver driver) { + return driver instanceof Decorated ? ((Decorated) driver).getOriginal() : driver; + } } 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..707080a 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 @@ -1,45 +1,15 @@ package com.qaprosoft.carina.core.foundation.cucumber; -import java.util.Arrays; -import java.util.Map; - 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.core.testng.ZebrunnerNameResolver; import io.cucumber.testng.FeatureWrapper; import io.cucumber.testng.PickleWrapper; -public class CucumberNameResolver implements TestNameResolver { - - private final static String FEATURE_NAME_OPTIONAL = "Optional"; - - @Override - @SuppressWarnings({ "unlikely-arg-type" }) - public String resolve(ITestResult result) { - String name = ""; +public class CucumberNameResolver extends ZebrunnerNameResolver { - if (result.getTestContext() == null) { - throw new RuntimeException("Unable to set Test name without testContext!"); - } - @SuppressWarnings("unchecked") - Map testnameMap = (Map) result.getTestContext().getAttribute(SpecialKeywords.TEST_NAME_ARGS_MAP); - - if (testnameMap != null) { - String testHash = String.valueOf(Arrays.hashCode(result.getParameters())); - if (testnameMap.containsKey(testHash)) { - name = testnameMap.get(testHash); - } - } - - if (name.isEmpty()) { - name = result.getTestContext().getCurrentXmlTest().getName(); - } - - return name; - } + private static final String FEATURE_NAME_OPTIONAL = "Optional"; public static String prepareTestName(String strFormat, PickleWrapper pickleWrapper, FeatureWrapper featureWrapper) { String featureName = cleanQuotes(featureWrapper.toString()); 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..dc73868 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 @@ -27,7 +27,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 +36,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; @@ -134,7 +133,7 @@ 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"); @@ -179,8 +178,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 { From 2b7d67c057ecdd148073f15c01a3b0730b68b8d8 Mon Sep 17 00:00:00 2001 From: Andrei Kamarouski Date: Thu, 6 Apr 2023 16:13:31 +0300 Subject: [PATCH 2/5] refactor(pom.xml): change dependencies order --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 818916c..ad508cc 100644 --- a/pom.xml +++ b/pom.xml @@ -36,10 +36,6 @@ - - com.qaprosoft - carina-core - io.cucumber @@ -59,6 +55,10 @@ ${cucumber.reporting} + + com.qaprosoft + carina-core + From f233613f024bdc4590f83bc71421ef76d37fe4cc Mon Sep 17 00:00:00 2001 From: Andrei Kamarouski Date: Thu, 6 Apr 2023 16:16:45 +0300 Subject: [PATCH 3/5] added guava dependency explicitly --- pom.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pom.xml b/pom.xml index ad508cc..fc17d6b 100644 --- a/pom.xml +++ b/pom.xml @@ -17,6 +17,7 @@ UTF-8 11 + 31.1-jre 7.9.0 7.9.0 5.7.5 @@ -36,6 +37,13 @@ + + + com.google.guava + guava + ${guava.version} + + io.cucumber From f318579b6ec0da5394255ebc9b96ff5727f60171 Mon Sep 17 00:00:00 2001 From: Andrei Kamarouski Date: Mon, 10 Apr 2023 13:12:16 +0300 Subject: [PATCH 4/5] bump up carina-core 8.0.11 --- pom.xml | 1 - .../foundation/cucumber/CucumberBaseTest.java | 11 +----- .../cucumber/CucumberNameResolver.java | 36 +++++++++++++++++-- .../foundation/cucumber/CucumberRunner.java | 2 +- 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/pom.xml b/pom.xml index fc17d6b..915eeef 100644 --- a/pom.xml +++ b/pom.xml @@ -43,7 +43,6 @@ guava ${guava.version} - io.cucumber 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 1e2e40b..1314b5f 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,8 +19,6 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.support.decorators.Decorated; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -62,18 +60,11 @@ public void takeScreenshotOfFailure(Scenario scenario) { for (Map.Entry entry : drivers.entrySet()) { String driverName = entry.getKey(); // in case of failure - Screenshot.capture(removeListeners(entry.getValue().getDriver()), + Screenshot.capture(entry.getValue().getDriver(), ScreenshotType.UNSUCCESSFUL_DRIVER_ACTION, driverName + ": " + scenario.getName()) .ifPresent(fileName -> LOGGER.debug("cucumber screenshot generated: {}", fileName)); } } } - - /** - * Clean driver from Decorator - */ - private static WebDriver removeListeners(WebDriver driver) { - return driver instanceof Decorated ? ((Decorated) driver).getOriginal() : driver; - } } 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 707080a..5462335 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 @@ -1,15 +1,45 @@ package com.qaprosoft.carina.core.foundation.cucumber; +import java.util.Arrays; +import java.util.Map; + +import com.zebrunner.carina.utils.commons.SpecialKeywords; import org.apache.commons.lang3.StringUtils; +import org.testng.ITestResult; -import com.zebrunner.carina.core.testng.ZebrunnerNameResolver; +import com.zebrunner.agent.testng.core.testname.TestNameResolver; import io.cucumber.testng.FeatureWrapper; import io.cucumber.testng.PickleWrapper; -public class CucumberNameResolver extends ZebrunnerNameResolver { +public class CucumberNameResolver implements TestNameResolver { + + private final static String FEATURE_NAME_OPTIONAL = "Optional"; + + @Override + @SuppressWarnings({ "unlikely-arg-type" }) + public String resolve(ITestResult result) { + String name = ""; - private static final String FEATURE_NAME_OPTIONAL = "Optional"; + if (result.getTestContext() == null) { + throw new RuntimeException("Unable to set Test name without testContext!"); + } + @SuppressWarnings("unchecked") + Map testnameMap = (Map) result.getTestContext().getAttribute(SpecialKeywords.TEST_NAME_ARGS_MAP); + + if (testnameMap != null) { + String testHash = String.valueOf(Arrays.hashCode(result.getParameters())); + if (testnameMap.containsKey(testHash)) { + name = testnameMap.get(testHash); + } + } + + if (name.isEmpty()) { + name = result.getTestContext().getCurrentXmlTest().getName(); + } + + return name; + } public static String prepareTestName(String strFormat, PickleWrapper pickleWrapper, FeatureWrapper featureWrapper) { String featureName = cleanQuotes(featureWrapper.toString()); 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 dc73868..96b1083 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 @@ -50,7 +50,7 @@ public abstract class CucumberRunner extends AbstractTest { private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - + private TestNGCucumberRunner testNGCucumberRunner; private final static String STR_FORMAT_TEST_NAME = "%s (%s)"; From 9f8550f6a4fb708f5d4deedef54131cd697a72d6 Mon Sep 17 00:00:00 2001 From: Andrei Kamarouski Date: Mon, 10 Apr 2023 16:37:03 +0300 Subject: [PATCH 5/5] refactor: code cleanup --- .../foundation/cucumber/CucumberBaseTest.java | 2 +- .../cucumber/CucumberNameResolver.java | 11 ++--- .../foundation/cucumber/CucumberRunner.java | 48 +++++++------------ .../cucumber/FeatureWrapperCustomName.java | 3 +- .../cucumber/CucumberRunnerTest.java | 5 +- 5 files changed, 25 insertions(+), 44 deletions(-) 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 1314b5f..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 @@ -30,8 +30,8 @@ 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()); /** 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 5462335..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 @@ -3,18 +3,18 @@ import java.util.Arrays; import java.util.Map; -import com.zebrunner.carina.utils.commons.SpecialKeywords; import org.apache.commons.lang3.StringUtils; import org.testng.ITestResult; 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 96b1083..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; @@ -49,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 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,32 +130,21 @@ public void tearDownClass(ITestContext context) throws Exception { */ private void generateCucumberReport() { 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; @@ -188,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) { @@ -214,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!"); }