我在硒(Java)范围报告中得到一个空的饼图.它看起来全黑



我正在为我的硒测试脚本生成范围报告。这不是一个Maven项目。这是一个简单的Java项目。使用的LentaReports JAR的版本为2.41.2。我能够生成HTML报告,但问题是通过/失败结果在我的范围报告中没有反映。我在报告中获得了全黑饼图。请参考屏幕截图。请参阅我的范围报告的图片。


以下是我的代码块:generateExtentReports.java(此类包含生成范围报告的方法(:

package SeleniumReports;
import java.io.File;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import org.testng.Assert;
import org.testng.ITestResult;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;
public class GenerateExtentReports {
ExtentReports extent;
ExtentTest test;
ITestResult res;
@BeforeTest
public void reportSetup(){
    System.out.println("BeforTest_reportSetup");
    Calendar mycalendar = Calendar.getInstance();
    SimpleDateFormat formatter=new SimpleDateFormat("dd/mm/yyyy_hhmmss");
    String timestamp=formatter.format(mycalendar.getTime());
    extent=new ExtentReports(System.getProperty("user.dir")+"/TestOutput/My First Report"+timestamp+".html",true);
    extent.addSystemInfo("Host Name", "Rashmi").addSystemInfo("Environment", "QA").addSystemInfo("User Name", "Rashmi Sharma");
    extent.addSystemInfo("Host Name", "Rashmi").addSystemInfo("Environment", "QA").addSystemInfo("User Name", "Rashmi Sharma");
    extent.loadConfig(new File(System.getProperty("user.dir")+"\extent-config.xml"));
    test=extent.startTest("loginUsingExcelData");
    System.out.println(extent.startTest("loginUsingExcelData").getRunStatus().toString());
}
@AfterMethod
public void getResults(ITestResult res) {
    System.out.println("AfterMethod_getResults");
    // TODO Auto-generated method stub
    if(res.getStatus()==ITestResult.SUCCESS){
        //test.log(LogStatus.PASS, res.getThrowable());
}
    else if(res.getStatus()==ITestResult.FAILURE){
        test.log(LogStatus.FAIL, res.getThrowable());
    }
    else if(res.getStatus()==ITestResult.SKIP){
        test.log(LogStatus.SKIP, res.getThrowable());
    }
    else if(res.getStatus()==ITestResult.STARTED){
        test.log(LogStatus.INFO, "Test started");
    }
    System.out.println("TestLogs conditions end here");
    extent.flush();
    extent.endTest(test);
    }}

loginusingerator.java(此类包含我的测试脚本(:

package SeleniumReports;
import static org.testng.Assert.assertTrue;
import java.io.File;
//import com.relevantcodes.extentreports.LogStatus;
import java.io.FileInputStream;

import java.io.IOException;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Iterator;
import java.util.concurrent.TimeUnit;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;
import SeleniumReports.MyMethods;
public class  loginUsingIterator extends GenerateExtentReports {
WebDriver dr;
FileInputStream fin;
XSSFWorkbook wb;
XSSFSheet sh;
XSSFCell cell;
XSSFRow row;
ExtentReports extent;
ExtentTest test;
@BeforeClass
public void initialisation(){
    //extent.startTest("initialisation");
    System.out.println("BeforeClass_initialisation");
    System.setProperty("webdriver.chrome.driver","C:\Chrome selenium driver\chromedriver.exe");   
    dr=new ChromeDriver();
    dr.manage().deleteAllCookies();
    dr.get("http://automationpractice.com/index.php");
    //test.log(LogStatus.INFO, "Navigating to URL");
    dr.manage().window().maximize();
    //dr.findElement(By.xpath("//a[@class='login']")).click();
    dr.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
@Test
public void loginUsingExcelData() throws Exception{

    //GenerateExtentReports extRep=new GenerateExtentReports();
    //extRep.reportSetup();
    fin=new FileInputStream("C:\Users\A638081\SEL_Workspace\ExtentReports\TestData.xlsx");
    wb=new XSSFWorkbook(fin);
    sh=wb.getSheetAt(0);
    Iterator rows=sh.rowIterator();
    while(rows.hasNext()){
    dr.findElement(By.xpath("//a[@class='login']")).click();
    row=(XSSFRow) rows.next();
    if(row.getRowNum()==0){
        continue;
    }
    Iterator cells=row.cellIterator();
    while(cells.hasNext()){
    cell=(XSSFCell) cells.next();
    //cell.setCellType(cell.CELL_TYPE_STRING);
    System.out.println(cell.getStringCellValue());
    dr.findElement(By.xpath("//input[@id='email']")).clear();
    dr.findElement(By.xpath("//input[@id='email']")).sendKeys(cell.getStringCellValue());
    dr.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    cell=(XSSFCell) cells.next();
    System.out.println(cell.getStringCellValue());
    dr.findElement(By.xpath("//input[@id='passwd']")).clear();
    dr.findElement(By.xpath("//input[@id='passwd']")).sendKeys(cell.getStringCellValue());
    dr.findElement(By.xpath("//button[@id='SubmitLogin']")).click();
    MyMethods AddToCart=new MyMethods(dr);
    AddToCart.addingToCart();
    dr.findElement(By.xpath("//a[@class='logout']")).click();
    //test.log(LogStatus.INFO, "Payment processed");
    //extent.endTest(test);
    System.out.println("first cycle completed");
    }
    }
    }
@AfterTest
public void quit() throws IOException{
    System.out.println("Entered tear down loop");
    //System.out.println(test.getTest().getName().toString());
    //System.out.println(extent.get.getRunStatus().toString());
    fin.close();
    dr.close();
    dr.quit();
    }}

有人可以帮忙吗?我从一周开始就在挣扎。

您缺少ExtentHtmlreporter。更改代码中的以下行:

 extent=new ExtentReports(System.getProperty("user.dir")+"/TestOutput/My First Report"+timestamp+".html",true); 

to

ExtentHtmlReporter extentHtmlReporter = ExtentHtmlReporter(System.getProperty("user.dir")+"/TestOutput/My First Report"+timestamp+".html"); 
Extent.attachReporter(extentHtmlReporter):

相关内容

最新更新