Экстент-отчет, показывающий только один результат теста при параллельном выполнении сценариев cucumber с использованием плагина Cucable - PullRequest
0 голосов
/ 02 февраля 2019

Я должен сгенерировать отчет об объеме из всех выполненных тестовых сценариев.Я запускаю сценарии параллельно.Когда я использую TestNG или Selenium Grid для параллельного выполнения, в этих реализациях отчеты об экстентах генерируются идеально, покрывая каждый выполненный тестовый сценарий.Но когда я запускаю сценарии параллельно с использованием подключаемого модуля Cucable, создается отчет о экстенте, но он будет содержать только 1 отчет о тестовых случаях, если в процессе было 2 тестовых случая.

Я использую Cucumber (Selenium), Junit Suite Runner,Подключаемый модуль Cucable

Я подтвердил, что код отчета Extent является потокобезопасным.Так что не уверен, почему только в случае Cucable Plugin, отчет Extent получает только 1 контрольный пример.Кто-то сказал мне, что в случае testNG, testNG сам предоставляет дополнительный потокобезопасный механизм, который помогает внутренне иметь все выполненные тестовые примеры в отчете.

ExtentTestManager.java

package com.jacksparrow.automation.extent.listeners;

import java.io.IOException;
import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.MediaEntityBuilder;
import com.aventstack.extentreports.Status;
import com.aventstack.extentreports.markuputils.ExtentColor;
import com.aventstack.extentreports.markuputils.Markup;
import com.aventstack.extentreports.markuputils.MarkupHelper;

public class ExtentTestManager {

    public static ThreadLocal<ExtentTest> testReport = new ThreadLocal<ExtentTest>();
    static ExtentReports extent = ExtentManager.getReporter();

    public static synchronized ExtentTest getTest() {
        return testReport.get();
    }

    public static synchronized void setTest(ExtentTest tst) 
    { 
        testReport.set(tst); 
    }

    public static synchronized void logInfo(String message) {

        testReport.get().info(message);
    }

    public static synchronized void logPass(String message) {

        testReport.get().pass(message);
    }

    public static synchronized void scenarioPass() {

        String passLogg = "SCENARIO PASSED";
        Markup m = MarkupHelper.createLabel(passLogg, ExtentColor.GREEN);
        testReport.get().log(Status.PASS, m);


    }

    public static synchronized void logFail(String message) {

        testReport.get().fail(message);
    }

    public static synchronized boolean addScreenShotsOnFailure() {

        ExtentManager.captureScreenshot();
        try {

            testReport.get().fail("<b>" + "<font color=" + "red>" + "Screenshot of failure" + "</font>" + "</b>",
                    MediaEntityBuilder.createScreenCaptureFromPath(ExtentManager.screenshotName).build());
        } catch (IOException e) {

        }

        String failureLogg = "SCENARIO FAILED";
        Markup m = MarkupHelper.createLabel(failureLogg, ExtentColor.RED);
        testReport.get().log(Status.FAIL, m);
        return true;
    }

    public static synchronized boolean addScreenShots() {

        ExtentManager.captureScreenshot();
        try {
            testReport.get().info(("<b>" + "<font color=" + "green>" + "Screenshot" + "</font>" + "</b>"),
                    MediaEntityBuilder.createScreenCaptureFromPath(ExtentManager.screenshotName).build());
        } catch (IOException e) {
            e.printStackTrace();
        }

        return true;
    }

    public static synchronized ExtentTest startTest(String testName) {
        return startTest(testName, "");
    }

    public static synchronized ExtentTest startTest(String testName, String desc) {
        ExtentTest test = extent.createTest(testName, desc);
        testReport.set(test);
        return test;
    }
}

ExtentManager.java

package com.jacksparrow.automation.extent.listeners;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import com.jacksparrow.automation.utilities.DriverManager;
import com.aventstack.extentreports.AnalysisStrategy;
import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.reporter.ExtentHtmlReporter;
import com.aventstack.extentreports.reporter.configuration.ChartLocation;
import com.aventstack.extentreports.reporter.configuration.Theme;

public class ExtentManager {

    static ExtentReports extent;
    static Date d = new Date();
    static String fileName = "Extent_" + d.toString().replace(":", "_").replace(" ", "_") + ".html";

    public synchronized static ExtentReports getReporter() {
        if (extent == null) {

            ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(System.getProperty("user.dir")+"/target/extent-report/"+fileName);

            htmlReporter.loadXMLConfig(".\\src\\test\\resources\\extent-config.xml");
            htmlReporter.config().setTestViewChartLocation(ChartLocation.BOTTOM);
            htmlReporter.config().setChartVisibilityOnOpen(true);
            htmlReporter.config().setTheme(Theme.STANDARD);
            htmlReporter.config().setDocumentTitle(fileName);
            htmlReporter.config().setEncoding("utf-8");
            htmlReporter.config().setReportName(fileName);
            //htmlReporter.setAppendExisting(true);

            extent = new ExtentReports();
            extent.setAnalysisStrategy(AnalysisStrategy.TEST);
            extent.attachReporter(htmlReporter);
            extent.setSystemInfo("Automation Analyst", "Robin Tyagi");
            extent.setSystemInfo("Organization", "Way2Automation");
            extent.setSystemInfo("Build no", "W2A-1234");
        }
        return extent;
    }

    public static String screenshotPath;
    public static String screenshotName;
    static int i=0;
    public static void captureScreenshot() {
        i = i + 1;
        File scrFile = ((TakesScreenshot) DriverManager.getDriver()).getScreenshotAs(OutputType.FILE);

        Date d = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("E dd MMM HH:mm:ss z yyyy");  
        String strDate = formatter.format(d);
        screenshotName = strDate.replace(":", "_").replace(" ", "_") + "_"+i+".jpg";

        try {
            FileUtils.copyFile(scrFile, new File(System.getProperty("user.dir") + "/target/extent-report/" + screenshotName));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void createExtentReportDirectory() {
        File file = new File(System.getProperty("user.dir") + "/target/extent-report/");
        if (!file.exists()) {
            if (file.mkdir()) {
            } else {
            }
        }
    }
}

Пожалуйста, помогите мне понять, что может быть правильным, чтобы сгенерировать отчет об объеме, содержащий сводку всех выполненных тестовых сценариев, когда Cucable Plugin используется для достижения параллельного выполнения в Cucumber (Selenium)

1 Ответ

0 голосов
/ 23 февраля 2019

После перехода на огуречный 4.0 я могу создать единый сводный отчет по экстентам.Спасибо.

...