테스트 실패시 스크린 샷을 찍으려고합니다.캡쳐 화면
[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#
'ITakesScreenShot'작품의 캐스트를 확인 했습니까? – Veverke
무엇을 의미합니까? 어떻게해야합니까? 내가 말했듯이, 내가 독립 실행 형 테스트로 실행하고 Teardown 하에서 실행하지 않으면 작동합니다. –
'TearDown' 전에 다른 곳에서'_webdriverChrome.Quit();'또는'_webdriverChrome.Close();'를 호출합니까? – Guy