Nunit test report does not publish Attachments

1k views Asked by At

I am newbie with C#, Specflow and Nunit. Currently, I am using Specflow with Nunit for to automate some UI tests.

Goal : I want to attach screenshots for failed test case.

Following is the code for taking screenshots

[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"));
            }
        }
    }

In Jenkins job,

  • I an using command line nunit3-console.exe to execute the tests and generate Testresults.xml.

  • In Post build action, I have published Nunit reports using nunit plugin.

Everything is working fine except "attachments" containing failed screenshots is not published even though "attachments" tag is present in xml.

Here is the snapshot for generated 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>

Can any one help me with the issues. I just want to attach screen shots link when I publish the Nunit results.

1

There are 1 answers

0
Chris On

The NUnit Test Attachment feature is relatively new. The Jenkins plugin does not currently have any support for handling it.

You could either raise an issue, or make a pull request.