2017-03-21 27 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(); 何が欠けていますか?

EDIT: 私は((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 "という引数であることを示していますが、そのことは完全には確信できませんでした。 – Dillanm

関連する問題