使用Cucable插件并行执行黄瓜脚本时,范围报告仅显示一个测试用例结果

社会

我必须从所有执行的测试脚本生成范围报告。我正在并行运行脚本。当我使用TestNG或Selenium Grid进行并行执行时,在那些实现中,将生成完全覆盖每个执行的测试脚本的范围报告。但是,当我使用Cucable Plugin并行运行脚本时,会生成范围报告,但如果执行中有2个测试用例,则只有1个测试用例报告。

我正在使用Cucumber(Selenium),Junit Suite Runner,Cucable插件

我验证了范围报告代码是线程安全的。因此不确定,为什么仅在“可插入插件”的情况下,“范围”报告仅获得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 {
            }
        }
    }
}

请帮助我了解什么是正确的想法,以便在使用Cucuable Plugin在Cucumber(Selenium)中实现并行执行时,生成具有所有已执行测试脚本摘要的范围报告。

社会

迁移到Cucumber 4.0后,我可以生成单个合并范围报告。谢谢。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使用Grid并行执行黄瓜测试用例?

当我在 pycharm 中使用 pytest 执行 python 脚本时,它没有在测试结果选项卡中显示测试用例编号

当我给出更多然后一个测试用例时,这显示错误的输出

Robot Framework API - 使用一个类获取测试套件/子套件结果和测试用例结果

测试一个函数,使用多个测试用例但只使用一个断言?

如果第一个测试用例失败,如何停止Robot Framework测试执行?

一个测试用例似乎干扰了另一个测试用例

一次用不同的夹具多次执行一个测试用例

并行执行硒/黄瓜测试,但所有测试都在同一个Chrome实例上运行

避免执行外部插件的测试用例

硒自动化:什么应该是失败的测试用例在可接受的范围运行一个测试套件时,除了有效的失败?

在另一个项目中运行测试用例的 Groovy 脚本

如何从黄瓜的挂钩中跳过测试用例的执行

在一个套件中执行多个测试用例时,如何一次又一次打开不安装的android app?

使用 90 个测试用例进行测试时失败

JMeter:如何将示例请求分组为一个测试用例,以使报告看起来整洁

在 Robot 框架中将变量从一个测试用例传递到另一个测试用例(不使用全局变量)

页面加载时仅执行一个JS脚本

如何输入所有测试用例,然后在执行结束时输出所有测试用例的结果

在这种情况下,当我尝试运行一个测试用例脚本时,为什么会打开多个浏览器实例?

笑话:因为它不是一个函数,所以无法监视该属性;未定义给定,而是在执行测试用例时出错

在一个测试用例上更新位错误

反应一个功能的测试用例

maven surefire报告插件未运行测试用例

如何使用 XUnit 编写一个简单的测试用例?

在一个测试用例中使用纯JS检索图像方向失败

Docker Image使用另一个映像运行测试用例

当我接受测试用例的数量= 1时,我的程序终止。否则,它会给出正确的答案,但会跳过最后一个测试用例

即使在测试用例的while循环中再次声明前一个测试用例的字符串时,它如何打印字符?