Sending Reports generated by SpecFlow in Email

189 views
Skip to first unread message

qates...@gmail.com

unread,
Dec 19, 2016, 2:12:16 PM12/19/16
to SpecRun
I've been struggling with this. It seems like the reports are generated after the very last hook is executed. So there is no way to programatically grab the test results and attach it in an email.
Was there a specific way SpecFlow handles this to be able to send an Email? Or is there a tutorial on how to handle the pass and fail results to generate a simple result set to send in an email?

Stephen McCafferty

unread,
Dec 20, 2016, 7:27:15 AM12/20/16
to SpecRun
The best way to send the resulting report via email is probably via the command line, either as a build step or by extending the runtest.cmd batch file. There are several command line tools for Windows that can send email and there are also solutions that use PowerShell. A quick google search according to you requirements should throw up a lot of usable results. I'm not sure if all of the solutions will support attachments though.

Presuming you find a suitable command line tool, it's also important to ensure that the name of your report file is static so you can send it. The report output using the template specified in the <Settings> element of your .srprofile is generated with a time stamp in the file name.  However, you can define additional reports in the <Report> element, and the outputName for the Template can be static in this case. The latest SpecRun release candidate on NuGet (1.6.0-rc002) introduces options that handle what to do if a report with the same name already exists. You can install the preview version from the NuGet Pack Manager in VS if you enable the "Include prerelease" option.

The <Template> element now includes an additional attribute, existingFileHandlingStrategy, which can have the following values:

  • Overwrite (default): Overwrite existing files with the same name (you will want to use this option)
  • IncrementFilename: Follows the Windows paradigm of adding an incremental suffix (e.g. "(1)", "(2)" etc.) to the end of file names. This will retain the existing file with its original name and result in a new file being generated with the appropriate incremental suffix.

1.5.2 does unfortunately does not handle existing report files well, hence the new options.

I'm assuming you are not looking to send the report via email when executing tests from within VS (where a link to the report is including in the Output window).
Reply all
Reply to author
Forward
0 new messages