2017-11-29 17 views
1

ExtentReport HTML 파일에 스크린 샷을 추가하려고합니다. 그러나 무엇인가의 이유로 이미지가 존재하지 않으며 콘솔이보고있는 것처럼 보이지만 올바른 장소 (href가 맞음).ExtentReports - 스크린 샷이 보고서에 없습니다. - 깨진 이미지

Screenshot screenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000)).takeScreenshot(driver); 
String destination = getScreenshotPath(); 
ImageIO.write(screenshot.getImage(), "IMG", new File(destination)); 
test.fail("Details: " + test.addScreenCaptureFromPath(destination)); 

의 스크린 샷이 대상에 저장됩니다 :

이 최신 시험 코드입니다.

상세 사항 : 내가 디버깅 모드를 시도하거나 보고서를 보면, 그것은으로 인쇄되어 [email protected] 과 그 아래 깨진 이미지가있다 :

enter image description here

답변

1

제안 된대로 - 절대 경로가 해결책 일 수는 있지만 나는 그런 식으로 가고 싶지 않습니다.

보고서를 생성 할 때와 동일한 디렉토리에 이미지를 저장하고 이미지 이름을 .addScreenCaptureFromPath (screenshotName.PNG)로 저장하는 것이 해결책이라는 것을 알아 냈습니다. 완벽하게 작동합니다.

2
은 브로 검사 :

난 절대 경로

참고 사용 브라우저에서 현 이미지는 이미지의 절대 경로를 확인하는

테이크의 스크린 샷 :

ExtentTest.Fail("message", MediaEntityBuilder.CreateScreenCaptureFromPath(TakeScreenShot.TakesScreenshot(driver, "Fatal")).Build()); 
: 특정 단계에서 :

public static String TakesScreenshot(IWebDriver driver, string FileName) 
    { 

     string pathProject = AppDomain.CurrentDomain.BaseDirectory; 
     string pathScreen = pathProject.Replace("\\bin\\Debug", ""); 
     string path = pathScreen + "project/Test-output/Images/"; 

     StringBuilder TimeAndDate = new StringBuilder(DateTime.Now.ToString()); 
     TimeAndDate.Replace("/", "_"); 
     TimeAndDate.Replace(":", "_"); 
     TimeAndDate.Replace(" ", "_"); 

     string imageName = FileName + TimeAndDate.ToString(); 

     ((ITakesScreenshot)driver).GetScreenshot().SaveAsFile(path + "_" + imageName + "." + System.Drawing.Imaging.ImageFormat.Jpeg); 

     return path + "_" + imageName + "." + "jpeg"; 
    } 

미리보기 방법의 경로로 보고서에 이미지를 첨부 방법 "TakesScreenshot" 스크린 샷을 가지고와

버전 ExtentReport : 3, C#을 NUnit과 3

사용하여 Java :

 <dependency> 
     <groupId>com.relevantcodes</groupId> 
     <artifactId>extentreports</artifactId> 
     <version>2.41.2</version> 
     </dependency> 

인가 :

ExtentTestManager.getTest().log(LogStatus.ERROR, ExtentTestManager.getTest().addScreenCapture("//ABOLUTE/PATH/IMAGE.PNG")); 

관련.