SpecFlowOSS / SpecFlow

#1 .NET BDD Framework. SpecFlow automates your testing & works with your existing code. Find Bugs before they happen. Behavior Driven Development helps developers, testers, and business representatives to get a better understanding of their collaboration
https://www.specflow.org/
Other
2.25k stars 754 forks source link

LivingDoc doesn't support language defined in specflow.json #2683

Open akamud opened 1 year ago

akamud commented 1 year ago

SpecFlow Version

3.9.22

Which test runner are you using?

NUnit

Test Runner Version Number

3.9.22

.NET Implementation

.NET 6.0

Project Format of the SpecFlow project

Sdk-style project format

.feature.cs files are generated using

SpecFlow.Tools.MsBuild.Generation NuGet package

Test Execution Method

Command line – PLEASE SPECIFY THE FULL COMMAND LINE

SpecFlow Section in app.config or content of specflow.json

{
    "bindingCulture":
    {
        "name" :"pt-BR"
    },
    "language":
    {
        "feature": "pt-BR"
    }
}

Issue Description

I'm changing the language from my features by using the language in the specflow.json as shown here. The tests run fine and the keywords are correctly picked. This is my .feature file:

Funcionalidade: Calculator
![Calculator](https://specflow.org/wp-content/uploads/2020/09/calculator.png)
Simple calculator for adding **two** numbers

Link to a feature: [Calculator]($projectname$/Features/Calculator.feature)
***Further read***: **[Learn more about how to generate Living Documentation](https://docs.specflow.org/projects/specflow-livingdoc/en/latest/LivingDocGenerator/Generating-Documentation.html)**

@mytag
Cenario: Adiciona dois números
    Dado que o primeiro número é 50
    E o segundo número é 70
    Quando os dois números são adicionados
    Entao o resultado esperado deve ser 120

Running the LivingDoc tool doesn't respect the language defined. I see in the docs here that it doesn't say anything about reading the specflow.json, so is this the expected behavior? What would be the recommended way of changing the language for everything (features and LivingDoc) globally?

This is the command I'm running:

dotnet livingdoc test-assembly SpecFlowCalculator.Specs.dll -t TestExecution.json

This is the error I get:

Framework: .NET 5.0.17
Unhandled exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> Gherkin.CompositeParserException: Parser errors:
(2:1): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'Funcionalidade: Calculator'
(3:1): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got '![Calculator](https://specflow.org/wp-content/uploads/2020/09/calculator.png)'
(4:1): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'Simple calculator for adding **two** numbers'
(6:1): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'Link to a feature: [Calculator]($projectname$/Features/Calculator.feature)'
(7:1): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got '***Further read***: **[Learn more about how to generate Living Documentation](https://docs.specflow.org/projects/specflow-livingdoc/en/latest/LivingDocGenerator/Generating-Documentation.html)**'
(10:1): expected: #TagLine, #FeatureLine, #Comment, #Empty, got 'Cenario: Adiciona dois números'
(11:2): expected: #TagLine, #FeatureLine, #Comment, #Empty, got 'Dado o primeiro número é 50'
(12:2): expected: #TagLine, #FeatureLine, #Comment, #Empty, got 'E o segundo número é 70'
(13:2): expected: #TagLine, #FeatureLine, #Comment, #Empty, got 'Quando os dois números são adicionados'
(14:2): expected: #TagLine, #FeatureLine, #Comment, #Empty, got 'Entao o resultado esperado deve ser 120'
(15:0): unexpected end of file, expected: #TagLine, #FeatureLine, #Comment, #Empty
   at Gherkin.Parser`1.AddError(ParserContext context, ParserException error)
   at Gherkin.Parser`1.MatchTokenAt_2(Token token, ParserContext context)
   at Gherkin.Parser`1.MatchToken(Int32 state, Token token, ParserContext context)
   at Gherkin.Parser`1.Parse(ITokenScanner tokenScanner, ITokenMatcher tokenMatcher)
   at LivingDoc.CLI.Parser.Parser.ParseFeatureFileContent(String featureFileContent, String defaultLanguage) in D:\a\1\s\src\SpecFlow.Integration\LivingDoc.CLI\Parser\Parser.cs:line 295
   at LivingDoc.CLI.Parser.Parser.Parse(String rootNodeTitle, String projectLanguage, String workItemPrefix, String workItemUrlTemplate) in D:\a\1\s\src\SpecFlow.Integration\LivingDoc.CLI\Parser\Parser.cs:line 64
   at LivingDoc.CLI.ReportGenerator.Generate(GeneratorSource source, Parameters parameters) in D:\a\1\s\src\SpecFlow.Integration\LivingDoc.CLI\ReportGenerator.cs:line 75
   at LivingDoc.CLI.ArgumentResolver.Handle(String workingFolder, GeneratorSource source, Parameters parameters) in D:\a\1\s\src\SpecFlow.Integration\LivingDoc.CLI\ArgumentResolver.cs:line 234
   at LivingDoc.CLI.ArgumentResolver.<>c__DisplayClass5_0.<Resolve>b__0(Parameters p) in D:\a\1\s\src\SpecFlow.Integration\LivingDoc.CLI\ArgumentResolver.cs:line 176
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Delegate.DynamicInvokeImpl(Object[] args)
   at System.Delegate.DynamicInvoke(Object[] args)
   at System.CommandLine.Invocation.ModelBindingCommandHandler.InvokeAsync(InvocationContext context)
   at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseParseErrorReporting>b__21_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass25_0.<<UseVersionOption>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass23_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__22_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseParseDirective>b__20_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseDebugDirective>b__11_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__10_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass14_0.<<UseExceptionHandler>b__0>d.MoveNext()

As a workaround, specifying the language again in my .feature file makes it work as expected, but is repetitive.

Steps to Reproduce

  1. Define a specflow.json with the contents shared here.
  2. Change the language globally from en-us to anything else.
  3. Try to use the LivingDoc tool to generate the documentation

Link to Repro Project

No response

SabotageAndi commented 1 year ago

Tbh, I am not even sure anymore that we look into the app.config to get the language.

akamud commented 1 year ago

Tbh, I am not even sure anymore that we look into the app.config to get the language.

I'm using a specflow.json, are they the same thing?

mmarramarco commented 2 weeks ago

Hello, this seems to still be an issue?

I'm doing the same steps (only différence is using the dotnet 8 instead of Dotnet 6 and the fr-FR culture) I'm also defining the culture in specflow.json.