2017-03-21 11 views
0

테스트 실패시 스크린 샷을 찍으려고합니다.캡쳐 화면

[TearDown] 
    public void TearDown() 
    { 
     var status = TestContext.CurrentContext.Result.Outcome.Status; 
     var stackTrace = "<pre>" + TestContext.CurrentContext.Result.Message + "</pre>"; 
     var errorMessage = TestContext.CurrentContext.Result.Message; 
     if (status == NUnit.Framework.Interfaces.TestStatus.Failed) 
     { 
      test.Log(LogStatus.Fail, status + errorMessage); 
      var ScreenShotPath = GetScreenShot.Capture(_webdriverChrome); 
      test.Log(LogStatus.Fail, "Screen Shot Below: "+test.AddScreenCapture(ScreenShotPath)); 
     } 
     else if (status == NUnit.Framework.Interfaces.TestStatus.Passed) 
     { 
      test.Log(LogStatus.Pass, status + errorMessage); 
     } 
     extent.EndTest(test); 
     _webdriverChrome.Quit();} 

및 캡처 기능은

public static string Capture(IWebDriver Webdrievr) 
    { 
     string pth = System.Reflection.Assembly.GetCallingAssembly().CodeBase; 
     string actualPath = pth.Substring(0, pth.LastIndexOf("bin")); 
     string projectPath = new Uri(actualPath).LocalPath; 

     Screenshot ss = ((ITakesScreenshot)Webdrievr).GetScreenshot(); 
     string screenshot = ss.AsBase64EncodedString; 
     byte[] screenshotAsByteArray = ss.AsByteArray; 
     ss.SaveAsFile(projectPath + "ErrorReportScreenshot\\ErrorScreenshot.jpeg", ScreenshotImageFormat.Jpeg); //use any of the built in image formating 
     string _fullPathToReturn = projectPath + "ErrorReportScreenshot"; 
     return _fullPathToReturn; 
    } 

내가 오류를 얻고있다

Result Message:
OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://localhost:56184/session/1aaf976356898c52e5cd57d17d44df15/element timed out after 60 seconds. ----> System.Net.WebException : The operation has timed out TearDown : OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://localhost:56184/session/1aaf976356898c52e5cd57d17d44df15/screenshot timed out after 60 seconds. ----> System.Net.WebException : The operation has timed out

것은 그것이 내가 capture()를 호출하는거야만큼 스크린 샷을 복용 실패하다 방법은 TearDown()입니다. 새로운 테스트 내에서 실행하여 capture()이라고 부르면 매력처럼 작동합니다. 디버깅 모드에서이 행에 오류가 있음을 알 수 있습니다. Screenshot ss = ((ITakesScreenshot)Webdrievr).GetScreenshot(); 나는 무엇이 누락 되었습니까?

편집 : 나는 ((ITakesScreenshot)Webdrievr)를 감시하고 오류가 발생했습니다 :

error CS0103: The name 'Webdrievr' does not exist in the current context

호출 스택 :

> Assign_Represnt.dll!Assign_Represnt.GetScreenShot.Capture(OpenQA.Selenium.IWebDriver Webdrievr) Line 22 C# 
+0

'ITakesScreenShot'작품의 캐스트를 확인 했습니까? – Veverke

+0

무엇을 의미합니까? 어떻게해야합니까? 내가 말했듯이, 내가 독립 실행 형 테스트로 실행하고 Teardown 하에서 실행하지 않으면 작동합니다. –

+0

'TearDown' 전에 다른 곳에서'_webdriverChrome.Quit();'또는'_webdriverChrome.Close();'를 호출합니까? – Guy

답변

0

가 나는 문제를 발견했다. 어떤 이유로 든 다음이 모두를 초래했습니다.

var options = new ChromeOptions(); 
options.AddArgument("no-sandbox"); 
_webdriverChrome = new ChromeDriver(options); 

방금 ​​옵션없이 크롬 드라이버를 사용 했으므로 이제 작동합니다.

_webdriverChrome = new ChromeDriver(); 
+0

http://stackoverflow.com/a/39041495/3110529이 질문은 no sandbox에 대한 인수가 실제로는 "--no-sandbox"'이며, 그럴 수도 있지만 완전히 확신하지 못했음을 보여줍니다. – Dillanm