从硒的范围报告3.1.5迁移到4.1.6

我正在尝试将基于selenium / java / gradle的项目从范围报告3.1.5迁移到4.1.6,以获取所有新更新。在搜索过程中,我注意到ExtentHTMLReporter从4.1.3开始不推荐使用,我们需要使用ExtentSparkReporter。因此,我进行了此更改,但仍会引发异常“ java.lang.NoSuchFieldError:VERSION_2_3_29”。下面是我的记者班。

我的记者类:

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Itestcontext;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.Beforeclass;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;

import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.MediaEntityBuilder;
import com.aventstack.extentreports.MediaEntityModelProvider;
import com.aventstack.extentreports.Status;
import com.aventstack.extentreports.reporter.ExtentSparkReporter;
import com.aventstack.extentreports.reporter.configuration.Theme;

import gov.nv.dwss.nvkids.selenium.api.base.CustomExtentTest;
import gov.nv.dwss.nvkids.selenium.utils.ReadPropertyFile;

public abstract class Reporter{


        public RemoteWebDriver driver;
        private static ExtentReports extent;
        public  ExtentTest test;
        public String testcaseName,testcaseDec,author ; 
        public String category;
        private Logger log=Logger.getLogger(Reporter.class);

        @BeforeSuite (alwaysRun = true)
        public void startReport(Itestcontext c) throws IOException 
        {
            System.setProperty("org.freemarker.loggerlibrary","none");
            try {
                Properties prop=new Properties();
                prop.load(new FileInputStream("./Resources/log4j.properties"));
                PropertyConfigurator.configure(prop);
                } catch (Exception e) {
                log.error(e);
            }
            log.debug("Configuring Extent Report...");
            ExtentSparkReporter reporter;
            String extentreportpath;
            String reportName=this.getclass().getName().substring(29,33).toUpperCase() +" - Test Report";
            String suiteName = c.getcurrentXmlTest().getSuite().getName()+" - Test Report";
            if (suiteName.contains("Default suite")||suiteName.contains("Failed suite"))
            {
                suiteName =reportName;
            }
            String rptName="h5{font-size: 0px;}h5::after{content:\'"+suiteName+"\';font-size: 1.64rem; line-height: 110%;margin: 0.82rem 0 0.656rem 0;}";
            extentreportpath="./reports/"+suiteName+".html";
            reporter = new ExtentSparkReporter(extentreportpath);
            //reporter.setappendExisting(true);         
            extent   = new ExtentReports(); 
            extent.attachReporter(reporter);
            extent.setSystemInfo("URL",ReadPropertyFile.getInstance().getPropertyValue("URL"));
            //reporter.loadXMLConfig("./Resources/extent-config.xml");
            reporter.config().setTheme(Theme.DARK);
            //reporter.config().setTestViewChartLocation(ChartLocation.BOTTOM);
            reporter.config().setReportName(suiteName);
            reporter.config().setCSS(rptName);
            log.info("Extent Report Configured Successfully");

        }

        @Parameters({"browser"})
        @Beforeclass(alwaysRun = true)
        public ExtentTest report(@Optional("browser") String browser)  
        {
             if(ReadPropertyFile.getInstance().getPropertyValue("Runmode").equalsIgnoreCase("STANDALONE"))
            {
                if(browser.equals("browser")) {
                    browser = ReadPropertyFile.getInstance().getPropertyValue("Browser");
                }
            }
            test = extent.createTest(testcaseName,testcaseDec +" <br /><br />Browser Name: "+browser+" <br /><br />Category: "+category);
            test.assignAuthor(author);
            CustomExtentTest extenttst = CustomExtentTest.getInstance();
            extenttst.setExtentTest(test);
            return test;  
        }



        public abstract long takesnap();

        public void reportStep(String desc,String status,boolean bsnap)
        {
            MediaEntityModelProvider img=null;
            if(bsnap && !status.equalsIgnoreCase("INFO"))
            {
                long snapNumber=100000L;
                snapNumber=takesnap();
                try
                {
                    img=MediaEntityBuilder.createScreenCaptureFromPath("images/"+snapNumber+".jpg").build();
                }
                catch(IOException e)
                {
                    log.error(e);
                }
            }
            if(status.equalsIgnoreCase("pass"))
            {
                test.log(Status.PASS,desc,img);
            }
            else if(status.equalsIgnoreCase("fail"))
            {
                test.log(Status.FAIL,img);
            }
            else if(status.equalsIgnoreCase("INFO"))
            {
                test.log(Status.INFO,img);
            }
        }

        public void reportStep(String desc,String status)
        {

            reportStep(desc,status,true);
        }


        @AfterSuite (alwaysRun=true )
        public void stopReport() 
        {
            log.debug("Stopping and preparing the report...");
            extent.flush();
            log.info("Report prepared successfully");
        }
    }

硒版本-3.141.59 泰腾7.1.0 范围报告-4.1.6 Java版本-1.8 请提供您的建议。

iCMS 回答:从硒的范围报告3.1.5迁移到4.1.6

最后,导致问题的是freemarker版本。升级到freemarker版本2_3_29解决了我的问题。

本文链接:https://www.f2er.com/2203771.html

大家都在问