我正在为我的硒测试脚本生成范围报告。它不是一个 Maven 项目。这是一个简单的java项目。使用的 extentReports 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);
}}
loginUsingIterator.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();
}}
任何人都可以帮忙吗?一个星期以来我一直在挣扎。