Will SpecFlow produce LivingDoc HTML reports for JSON data-driven or Excel-based tests?

I have installed the SpecFlow ExternalData plugin, but the LivingDoc doesn’t show any parameter details. Is it possible to include them?

How can I get the externalized data (from Excel/JSON) to appear in the HTML report? I know it’s possible with Examples using Scenario Outline, but my data is externalized."

Solution: Pass External Data and Generate LivingDoc with Parameters

Step 1: Set Up Spec Flow Project A. Create a New NUnit Project

1.Create a new NUnit project in Visual Studio 2.Install the required NuGet packages: a. Open NuGet Package Manager Console and run . Install-Package Spec Flow . Install-Package SpecFlow.NUni

B. Install SpecFlow ExternalData Plugin 1.Install the SpecFlow.ExternalData plugin using: [ Install-Package SpecFlow.ExternalData ]

Step 2: Create a Simple Spec Flow Feature File

1.Create your feature file (Login. Feature) with external data reference: [ Feature: Login Feature Scenario Outline: User tries to login with credentials Given the user opens the login page When the user enters “” and “” Then the user should be logged in @source:LoginData.json Examples: | username | password | | | | The @source:LoginData.json tag tells Spec Flow to fetch the data from the external JSON file. ]

Step 3: Create an External Data File (JSON) Create a JSON file named LoginData.json with the following content: [ { “username”: “user1”, “password”: “pass1” }, { “username”: “user2”, “password”: “pass2” } ]

Step 4: Implement Step Definitions (LoginSteps.cs) Create a step definition class (LoginSteps.cs) for your Spec Flow feature: [ using TechTalk.SpecFlow; namespace SpecFlowExample.Steps { [Binding] public class LoginSteps { [Given(@“the user opens the login page”)] public void GivenTheUserOpensTheLoginPage() { Console.WriteLine(“Login page opened”); } [When(@“the user enters “”(.)“” and “”(.)”“”)] public void WhenTheUserEntersAnd(string username, string password) { Console.WriteLine($“Username: {username}, Password: {password}”); } [Then(@“the user should be logged in”)] public void ThenTheUserShouldBeLoggedIn() { Console.WriteLine(“User logged in”); } } } ]

Step 5: Generate Living Doc Report A. Install the Living Doc Plugin Run this command to install the Spec Flow Living Doc plugin: [ Install-Package SpecFlow.Plus.LivingDocPlugin ] B. Generate Living Doc Report After running the tests and generating the .dll, .json, and .html files, generate the Living Doc using the following command: [ living Doc test-assembly “path\to\your\test-assembly.dll” -t “path\to\TestExecution.json” -o “Reports\LivingDoc.html” ]

Troubleshooting

  1. Using the Package Manager in Visual Studio If you face configuration issues or errors in the terminal, try these steps:

Step 1: Check .NET SDK Version

Ensure that the correct version of .NET SDK is installed on your system.

Step 2: Use NuGet Package Manager in Visual Studio 1.Open Visual Studio. 2.Right-click your project in Solution Explorer and select Manage NuGet Packages. 3.Search for and install the following packages: a.SpecFlow b.SpecFlow.NUnit c.SpecFlow.Plus.LivingDocPlugin d.SpecFlow.ExternalData

Step 3: Update NuGet Package Source

  1. In NuGet Package Manager, click on the gear icon ( ) to open Package Sources. Ensure nuget.org is listed with the URL https://api.nuget.org/v3/index.json.
  2. Using the Package Manager Console Go to Tools > NuGet Package Manager > Package Manager Console. Try installing the packages again through the console.
  3. Generate Living Doc Make sure to run your tests using: dotnet test This will generate the .dll file (e.g., jovinspecflow.dll), the TestExecution.json, and the Living Doc HTML file.
  4. Install Living Doc CLI (if needed) If you encounter errors generating the Living Doc, install the Living Doc CLI: dotnet tool install --global SpecFlow.Plus.LivingDoc.CLI Paths to Use in Living Doc Command DLL file: “C:\Users\anshulr\source\repos\jovinspecflow\jovinspecflow\bin\Debug\net8.0\jovinspec flow.dll” JSON file: “C:\Users\anshulr\source\repos\jovinspecflow\jovinspecflow\bin\Debug\net8.0\TestExec ution.json” HTML output: “C:\Users\anshulr\source\repos\jovinspecflow\jovinspecflow\bin\Debug\net8.0\LivingDo c.html” By following these steps, you should be able to pass external data from a JSON or Excel file to your SpecFlow scenarios and see that data reflected in your LivingDoc HTML report.

Important Notes: LivingDoc CLI–> If you’re having issues running the livingdoc command, make sure you have the LivingDoc CLI installed.

1.Install the livingdoc cli tool: [ dotnet tool install --global SpecFlow.Plus.LivingDoc.CLI ] Common Error: Package Source Mapping Issue. [ [Package Source Mapping is enabled, but no source found under the specified package ID: specflow.plus.livingdoc.cli] ] This means package source mapping is limiting where the LivingDoc CLI is being downloaded from. You can fix it by ensuring that your NuGet configuration includes the correct package sources.

Step 1: List Current Package Sources a. Run the following command-> [dotnet nuget list source] b. Make sure nuget.org is listed as-> [nuget.org [Enabled] https://api.nuget.org/v3/index.json ]

Step 2: Update NuGet.Config 1.File Ensure your NuGet.Config is properly configured to include LivingDoc packages. Add this to your NuGet.Config file: [

<?xml version="1.0" encoding="utf-8"?> ] After fixing the NuGet configuration, your LivingDoc CLI command should work fine

[quote=“anshulr, post:2, topic:31428, full:true”] Solution: Pass External Data and Generate LivingDoc with Parameters

Step 1: Set Up Spec Flow Project A. Create a New NUnit Project

1.Create a new NUnit project in Visual Studio 2.Install the required NuGet packages: a. Open NuGet Package Manager Console and run . Install-Package Spec Flow . Install-Package SpecFlow.NUni

B. Install SpecFlow ExternalData Plugin 1.Install the SpecFlow.ExternalData plugin using: [ Install-Package SpecFlow.ExternalData ]

Step 2: Create a Simple Spec Flow Feature File

1.Create your feature file (Login. Feature) with external data reference: [ Feature: Login Feature Scenario Outline: User tries to login with credentials Given the user opens the login page When the user enters “” and “” Then the user should be logged in @source:LoginData.json Examples: | username | password | | | | The @source:LoginData.json tag tells Spec Flow to fetch the data from the external JSON file. ]

Step 3: Create an External Data File (JSON) Create a JSON file named LoginData.json with the following content: [ { “username”: “user1”, “password”: “pass1” }, { “username”: “user2”, “password”: “pass2” } ]

Step 4: Implement Step Definitions (LoginSteps.cs) Create a step definition class (LoginSteps.cs) for your Spec Flow feature: [ using TechTalk.SpecFlow; namespace SpecFlowExample.Steps { [Binding] public class LoginSteps { [Given(@“the user opens the login page”)] public void GivenTheUserOpensTheLoginPage() { Console.WriteLine(“Login page opened”); } [When(@“the user enters “”(.)“” and “”(.)”“”)] public void WhenTheUserEntersAnd(string username, string password) { Console.WriteLine($“Username: {username}, Password: {password}”); } [Then(@“the user should be logged in”)] public void ThenTheUserShouldBeLoggedIn() { Console.WriteLine(“User logged in”); } } } ]

Step 5: Generate Living Doc Report A. Install the Living Doc Plugin Run this command to install the Spec Flow Living Doc plugin: [ Install-Package SpecFlow.Plus.LivingDocPlugin ] B. Generate Living Doc Report After running the tests and generating the .dll, .json, and .html files, generate the Living Doc using the following command: [ living Doc test-assembly “path\to\your\test-assembly.dll” -t “path\to\TestExecution.json” -o “Reports\LivingDoc.html” ]

Troubleshooting

  1. Using the Package Manager in Visual Studio If you face configuration issues or errors in the terminal, try these steps:

Step 1: Check .NET SDK Version

Ensure that the correct version of .NET SDK is installed on your system.

Step 2: Use NuGet Package Manager in Visual Studio 1.Open Visual Studio. 2.Right-click your project in Solution Explorer and select Manage NuGet Packages. 3.Search for and install the following packages: a.SpecFlow b.SpecFlow.NUnit c.SpecFlow.Plus.LivingDocPlugin d.SpecFlow.ExternalData

Step 3: Update NuGet Package Source

  1. In NuGet Package Manager, click on the gear icon ( ) to open Package Sources. Ensure nuget.org is listed with the URL https://api.nuget.org/v3/index.json.
  2. Using the Package Manager Console Go to Tools > NuGet Package Manager > Package Manager Console. Try installing the packages again through the console.
  3. Generate Living Doc Make sure to run your tests using: dotnet test This will generate the .dll file (e.g., jovinspecflow.dll), the TestExecution.json, and the Living Doc HTML file.
  4. Install Living Doc CLI (if needed) If you encounter errors generating the Living Doc, install the Living Doc CLI: dotnet tool install --global SpecFlow.Plus.LivingDoc.CLI Paths to Use in Living Doc Command DLL file: “C:\Users\anshulr\source\repos\jovinspecflow\jovinspecflow\bin\Debug\net8.0\jovinspec flow.dll” JSON file: “C:\Users\anshulr\source\repos\jovinspecflow\jovinspecflow\bin\Debug\net8.0\TestExec ution.json” HTML output: “C:\Users\anshulr\source\repos\jovinspecflow\jovinspecflow\bin\Debug\net8.0\LivingDo c.html” By following these steps, you should be able to pass external data from a JSON or Excel file to your SpecFlow scenarios and see that data reflected in your LivingDoc HTML report.

Important Notes: LivingDoc CLI–> If you’re having issues running the livingdoc command, make sure you have the LivingDoc CLI installed.

1.Install the livingdoc cli tool: [ dotnet tool install --global SpecFlow.Plus.LivingDoc.CLI ] Common Error: Package Source Mapping Issue. [ [Package Source Mapping is enabled, but no source found under the specified package ID: specflow.plus.livingdoc.cli] ] This means package source mapping is limiting where the LivingDoc CLI is being downloaded from. You can fix it by ensuring that your NuGet configuration includes the correct package sources.

Step 1: List Current Package Sources a. Run the following command-> [dotnet nuget list source] b. Make sure nuget.org is listed as-> [nuget.org [Enabled] https://api.nuget.org/v3/index.json ]

Step 2: Update NuGet.Config 1.File Ensure your NuGet.Config is properly configured to include LivingDoc packages. After fixing the NuGet configuration, your LivingDoc CLI command should work fine!

1 Like