2016-08-16 181 views
1

嗨我想通過範圍報告創建報告;該代碼沒有提供任何錯誤並且運行成功,但沒有生成html報告。任何人都可以請幫下面是我的代碼 -範圍報告沒有生成html

package ca.automation.com; 

import org.testng.annotations.Test; 
import com.relevantcodes.extentreports.ExtentReports; 
import com.relevantcodes.extentreports.ExtentTest; 
import org.testng.annotations.BeforeTest; 
import org.junit.Assert; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.ie.InternetExplorerDriver; 
import org.testng.annotations.AfterClass; 

public class ExtentReport { 

    WebDriver driver; 
    ExtentReports extent; 
    ExtentTest test; 

    @BeforeTest 
    public void startReport(){ 
     extent = new ExtentReports("C:\\Report.html", true); 
    } 

    @Test 
    public void installapp() { 
     test = extent.startTest("installapp"); 
     System.setProperty("webdriver.ie.driver", "C:\\Anuj\\Downloads\\IEDriverServer_Win32_2.46.0\\IEDriverServer.exe"); 
     driver = new InternetExplorerDriver(); 
     driver.manage().window().maximize(); 
     driver.get("https://www.tripadvisor.com/"); 
     String Title = driver.getTitle(); 
     Assert.assertTrue(Title.contains("Trip")); 
     extent.endTest(test); 
    } 
} 

回答

1

在這裏,只需將工作代碼複製粘貼到項目中即可。

import org.testng.annotations.Test; 

import com.dell.patientregister.mobilewallet.test.PatientRegister_SmokeTest; 
import com.relevantcodes.extentreports.ExtentReports; 
import org.testng.annotations.BeforeTest; 
import org.junit.Assert; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.chrome.ChromeDriver; 
import org.openqa.selenium.ie.InternetExplorerDriver; 

public class ExtentReport { 

    WebDriver driver; 
    ExtentReports extent; 

    @Test 
    public void installapp() { 

ExtentReports extent = ExtentReports.get(ExtentReport.class); 

     extent.init("myreport.html", true); 
     extent.startTest(" Install App"); 

     System.setProperty("webdriver.ie.driver", "C:\\Anuj\\Downloads\\IEDriverServer_Win32_2.46.0\\IEDriverServer.exe"); 
     driver = new InternetExplorerDriver(); 
     driver.manage().window().maximize(); 
     driver.get("https://www.tripadvisor.com/"); 
     String Title = driver.getTitle(); 
     Assert.assertTrue(Title.contains("Trip")); 
     extent.endTest(); 
    } 
} 
+0

謝謝Rajan;但複製粘貼下面的代碼我收到錯誤get方法說「get方法是未定義的範圍報告」我使用的是extentreports-java-2.41.1.jar –

2

需要調用extent對象的flush()和close()以將更改寫入文件。調用close()只測試結束前必須做,因爲它關閉輸出流中@AfterSuite方法@AfterMethod方法和close()


調用flush()

@AfterMethod 
public void afterMethod() { 
    extent.flush(); 
} 

@AfterSuite 
public void afterSuiteMethod() { 
    extent.close(); 
} 

參考: - ExtentReports Examples for Java

4

在測試方法結束時追加extent.flush();以將所有測試日誌寫入報告文件。

1

請試試這個:

import org.testng.annotations.Test; 

import com.dell.patientregister.mobilewallet.test.PatientRegister_SmokeTest; 
import com.relevantcodes.extentreports.ExtentReports; 
import org.testng.annotations.BeforeTest; 
import org.junit.Assert; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.chrome.ChromeDriver; 
import org.openqa.selenium.ie.InternetExplorerDriver; 

public class ExtentReport { 

WebDriver driver; 
ExtentReports extent; 
@Test 
public void installapp() { 

ExtentReports extent = ExtentReports.get(ExtentReport.class); 
extent.init("myreport.html", true); 
test = extent.startTest(" Install App"); 
System.setProperty("webdriver.ie.driver","C:\\Anuj\\Downloads\\IEDriverServer_Win32_2.46.0\\IEDriverServer.exe"); 
    driver = new InternetExplorerDriver(); 
    driver.manage().window().maximize(); 
    driver.get("https://www.tripadvisor.com/"); 
    String Title = driver.getTitle(); 
    Assert.assertTrue(Title.contains("Trip")); 
    test.Log(LogStatus.Pass, "Login Successful"); 
    extent.endTest(test); 
    extent.flush(); 
    extent.close(); 
} 
} 
1

末添加extent.flush()

0

我在生成Extent報告時遇到同樣的問題。以下解決方案適用於我。 請在最後加上這些命令: extent.EndTest(test); extent.Flush();

確保您的NuGet包添加這個版本 - ExtentReports 2.41.0