2017-08-30 124 views
1

我是C#,Specflow和Nunit的新手。目前,我正在使用Specun和Nunit来自动化一些UI测试。Nunit测试报告不公布附件

目标:我想附上失败测试用例的截图。

以下是截屏

[AfterScenario] 
    public void AfterScenario() 
    { 
     if (ScenarioContext.Current.TestError != null) 
     { 
      var screenShotPath = AppDomain.CurrentDomain.BaseDirectory + "\\TestResults\\ScreenShots"; 
      Directory.CreateDirectory(screenShotPath); 

      if (BrowserSession != null) 
      { 
       BrowserSession.SaveScreenshot(Path.Combine(screenShotPath, ScenarioContext.Current.ScenarioInfo.Title + ".jpg"), System.Drawing.Imaging.ImageFormat.Jpeg); 
       TestContext.AddTestAttachment(Path.Combine(screenShotPath, ScenarioContext.Current.ScenarioInfo.Title + ".jpg")); 
      } 
     } 
    } 

在詹金斯的工作代码,

  • 我的使用命令行nunit3-console.exe执行测试和产生Testresults.xml。

  • 在Post构建动作中,我使用nunit插件发布了Nunit报告。

一切工作正常,除了“附件”包含失败的截图是不会发布的,即使“附件”标签存在于XML中。

下面是生成的XML

</assertion> 
     </assertions> 
     <attachments> 
      <attachment> 
      <filePath>E:\jekinsJob\autotest\TestSolution\bin\Debug\TestResults\ScreenShots\registrationlink.jpg</filePath> 
      </attachment> 
      <attachment> 
      <filePath>E:\jekinsJob\autotest\TestSolution\bin\Debug\TestResults\ScreenShots\guest_registration.jpg</filePath> 
      </attachment> 
     </attachments> 
     </test-case> 

任何一个可以帮助我的问题快照。我只是想在发布Nunit结果时附上截图。

回答