0

我正在尝试生成日志和高级测试报告。为此,我在我的 Selenium 框架中使用了ExtentReport.jar 。

但我无法在我的项目层次结构中提到的输出文件夹中生成报告。我不知道 extentreport 本身是否创建文件夹来保存这些报告,但我仍然创建了一个新文件夹并给出了该文件夹名称保存这些报告。

我使用了以下代码:

package org.Callers;

import java.io.IOException;

import javax.mail.MessagingException;

import jxl.read.biff.BiffException;

import org.Called_Pages.ExcelLib;
import org.Called_Pages.GoogleSearch;
import org.Called_Pages.SeleniumPage;
import org.Utilities.SendMail;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;

/**
* @author Noushad
*
*/
public class GooglleSearchTest {


public static WebDriver driver=new FirefoxDriver();



@Test
public void Search() throws BiffException, IOException, MessagingException, com.sun.xml.internal.messaging.saaj.packaging.mime.MessagingException
{
    // TODO Auto-generated method stub

    String extentReportFile = "E:\\Project\\jar\\Selenium Scripts\\Hybrid_Driven\\ExtentReport\\extentReport.html";
    String extentReportImage = System.getProperty("user.dir") + "\\ExtentReport\\extentImageFile.png";


    //Create object of the extentreport and specify the report file path
    ExtentReports extent = new ExtentReports(extentReportFile, true);

    //Create object of the SendMail Class 
    SendMail email = new SendMail();

    //Start the test using the ExtentTest class object
    ExtentTest test = extent.startTest("Started the Test" , "Search the Given Test");




    /*//Create Object of extent report and specify the class name of the current class in the get method  
     report = ExtentReports.get(GooglleSearchTest.class);

    //Call the init method and specify the location where you want to save this report
    //Second parameter is set to TRUE it means it will override the report with the new one
    report.init("E:\\Project\\jar\\Selenium Scripts\\myreport.html", true);


    //Start the Test
    report.startTest("Started the Test");*/


    //Maximize the Window
    driver.manage().window().maximize();
    test.log(LogStatus.INFO,"Maximized the Window");

    //Launch the Google application
    driver.navigate().to("http://www.google.com");
    test.log(LogStatus.INFO,"Launched the Application");

    //Create the instance for the ExcelLib class 
    ExcelLib xl = new ExcelLib("E:\\Project\\jar\\Selenium\\SearchText.xls");


    //Create the instance for the Excellib class which is available in the "UTILITIES PKG"
    //Excellib excel = new Excellib("E:\\Project\\jar\\Selenium\\SearchText.xls");

    //Create Instance for the GoogleSearch Page
    GoogleSearch page = new GoogleSearch(driver);

    /*//Getiing the Cell values by iterating the ExcelSheet
    for(int rowCnt = 0;rowCnt < excel.rowcount(); rowCnt++)
    {
           page.searchtext(Excellib.readcell(Excellib.GetCell("SearchText"), rowCnt));
    }*/

    //Call the GoogleSearch Page's method
    page.searchtext(xl.GetCellValue(0, 1));
    //Log.info("Getting the text from the Excelsheet to search");
    test.log(LogStatus.INFO,"Searched the Test");

    //Create instance for the SeleniumPage
    SeleniumPage sel=new SeleniumPage(driver);

    //Call the SeleniumPage method
    sel.DocClick();
    //Log.info("Clicked on the link");
    test.log(LogStatus.INFO,"Clicked on the link");


    //Take the screenshot at runtime and specify the error image path
    test.log(LogStatus.INFO, "Error Snapshot : " + test.addScreenCapture(extentReportImage));

    //close the application 
    driver.quit();

    test.log(LogStatus.INFO, "Browser Closed");


    //close the Report
    extent.endTest(test);

    //Send the Report via Email
    email.mail();

    }

    }

请帮我解决这个问题或向我推荐一些涵盖日志、报告和屏幕截图的其他报告。

4

1 回答 1

0

你实际上没有写任何东西来记录。要执行对文档的实际写入,只需刷新 -

extent.flush();
于 2016-11-18T06:01:35.237 回答