2017-05-31 26 views
1

我想只要我把這個方法在我的測試代碼採取硒C#截圖有一個簡單的代碼下面錯誤服用截圖中硒C#

public void takeScreenshot() 
    { 
     Screenshot screenshot = ((ITakesScreenshot)DriverContext.Driver).GetScreenshot(); 
     screenshot.SaveAsFile(@"C:\images\image.png", ImageFormat.Png); 
    } 

,它拋出的錯誤:

System.InvalidOperationException: unknown error: cannot get automation extension 
from unknown error: page could not be found: chrome- 
extension://aapnijgdinlhnhlmodcfapnahmbfebeb/_generated_background_page.html 
(Session info: chrome=58.0.3029.110) 
(Driver info: chromedriver=2.27.440174 
(e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Windows NT 10.0.10586 x86_64) 

我研究了不少,發現

  1. ,這可能是由於舊的鍍鉻驅動程序版本FO r我安裝了最新的一個,但它仍然給出了錯誤

  2. 該網站可能無法導航到www,我通過導航到www.google.com進行了檢查,但它仍然無效。

我不知道如何解決此問題。任何建議都會有所幫助。

+0

添加加載擴展的代碼。添加您使用過的庫的版本。 –

回答

0

我在我的TearDown中使用了它,它爲我工作 - 也許有什麼與DriverContext.Driver在那一點上解決什麼?

[TearDown] 
    public void TearDown() 
    { 
     if (TestContext.CurrentContext.Result.Outcome != ResultState.Success) 
     { 
      var screenshot = ((ITakesScreenshot)browser).GetScreenshot(); 
      var filename = TestContext.CurrentContext.Test.MethodName + "_screenshot_" + DateTime.Now.Ticks + ".jpg"; 
      var path = "C:\\Temp\\" + filename; 
      screenshot.SaveAsFile(path , ScreenshotImageFormat.Jpeg); 
      TestContext.AddTestAttachment(path); 
     } 
     browser.Quit(); 
    }