Specflow: Generating step definitions in language other than English

Created on 3 Oct 2019  Â·  12Comments  Â·  Source: SpecFlowOSS/SpecFlow

SpecFlow Version:

  • [X] 3.0
  • [ ] 2.4
  • [ ] 2.3
  • [ ] 2.2
  • [ ] 2.1
  • [ ] 2.0
  • [ ] 1.9

Used Test Runner

  • [ ] SpecFlow+Runner
  • [ ] MSTest
  • [X] NUnit
  • [ ] Xunit


Version number:3.0.225

Project Format of the SpecFlow project

  • [ ] Classic project format using packages.config
  • [X] Classic project format using <PackageReference> tags
  • [ ] Sdk-style project format

.feature.cs files are generated using

  • [X] SpecFlow.Tools.MsBuild.Generation NuGet package
  • [ ] SpecFlowSingleFileGenerator custom tool

Visual Studio Version

  • [X] VS 2019
  • [ ] VS 2017
  • [ ] VS 2015

Enable SpecFlowSingleFileGenerator Custom Tool option in Visual Studio extension settings

  • [ ] Enabled
  • [X] Disabled

Are the latest Visual Studio updates installed?

  • [x] Yes
  • [ ] No, I use Visual Studio version <Major>.<Minor>.<Patch>

.NET Framework:

  • [ ] >= .NET 4.5
  • [ ] before .NET 4.5
  • [ ] .NET Core 2.0
  • [ ] .NET Core 2.1
  • [ ] .NET Core 2.2
  • [X] .NET Core 3.0

Test Execution Method:

  • [X] Visual Studio Test Explorer
  • [ ] TFS/VSTS/Azure DevOps – Task – PLEASE SPECIFY THE NAME OF THE TASK
  • [ ] Command line – PLEASE SPECIFY THE FULL COMMAND LINE

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

SPECFLOW.JSON
{
    "bindingCulture":
    {
        "language" :"da-DK"
    },
    "language":
    {
        "feature": "da-DK"
    }
}

Repro Project

Issue Description

Working on a project where I wish to write feature files in Danish, am able to do so by changing
specflow.json as above. On generating step definitions from these feature files, they are in English and the feature files will not recognise that step definitions have been generated.

Steps to Reproduce

  1. Create new project NUnit Test Project(.NET Core)

  2. Add NuGet packages: NUnit, NUnit3TestAdapter, SpecFlow, SpecFlow NUnit, SpecFlowNUnit.Runnerer, SpecFlow.Tools.MsBuild,Generation

  3. Change specflow.json as above.
    In feature files now have access to Danish keywords - e.g. Givet instead of Given

4.. From feature files, choose "Generate Step Definitions"
Definition files that are generated use English keywords - i.e. Given not givet, and the
feature files will not recognise that step definitions have been generated - all step
in the feature file are still in purple.

Feature-Request Runtime up-for-grabs Question PR has to come from community low

Most helpful comment

@gasparnagy Sounds like a plan.

So if someone from the community want to contribute this feature, I am happy to help them.

All 12 comments

I think what you are writing here is how it is supposed to work, that is that they do not support using keywords in any other language than English. At least all examples I have seen have used english keywords with native regexes or method names. If it is supposed to work with native keywords, it would be nice if the examples could be updated

@RobIngleby Could you please post the complete bindings that are generated?

Attached below example of a simple feature file, and the binding generated.- in any case ref.
metarevens comment have I completely misunderstood this - that generating the steps files with English keywords is intended functionality?

FEATURE FILE

Egenskab: OpenIndreLinksFraNavBar
    Til bruge webstedet
    Som bruger
    Jeg ville åbner indre links
Baggrund: 
    Givet Jeg er på hjemmesiden 

@IndreUndersiderTests
Abstrakt Scenario: Ã…ben indre undersider
        NÃ¥r jeg klik en '<IndreLink>'
        Så skal den rigtigt side åbnes i den sammen tab

Eksempler: 
|IndreLink|
|Client Testimonials |
|About me |
|Services |
|Find and contact me |

STEPS FILE

using System;
using TechTalk.SpecFlow;

namespace LiveTests
{
    [Binding]
    public class OpenIndreLinksFraNavBarSteps
    {
        [When(@"jeg klik en '(.*)'")]
        public void NarJegKlikEn(string p0)
        {
           // ScenarioContext.Current.Pending();
        }

        [Then(@"skal den rigtigt side åbnes i den sammen tab")]
        public void SaSkalDenRigtigtSideAbnesIDenSammenTab()
        {
          //  ScenarioContext.Current.Pending();
        }
    }
}

@RobIngleby

Thanks for the example. And I tried to reproduce it, but I still don't understand what you mean.
The only english keywords I see are the Given, When and Then attributes on the methods.
Do you mean these?

@metareven
Yes, nearly all of the examples are in english. We have one example where we show how to use another language (German in this case). It is here: https://github.com/techtalk/SpecFlow-Examples/tree/master/BowlingKata/BowlingKata-German

@SabotageAndi Yes, but I think that in this issue, the problem is that the keywords Given, When and Then are not in Danish. It would be nice if these could be in the language that is specified in the feature files instead of defaulting to english. In the documentation, even the non-english examples end up with these keywords in english.

@metareven So you would like to have the attributes in your language?

Apologies for delay in reply - been unwell. It was indeed that I thought intended functionality was that the keywords in the steps file attributes should be in the same language as the keywords in the feature files. If this is not current intended functionality it would be a very good future enhancement.

Ok, now I understand the question.
The current behaviour is the intended one. There are only the attributes GivenAttribute, WhenAttribute and ThenAttribute in SpecFlow.
Too be honest, until now I never thought of having this attributes also in another language than english.

I think it would be possible to do, but it will be a lot of work.
Here are the things I currently have in mind too pull this off:

  • Add for all supported languages in Gherkin additional attributes.
    This file contains all languages for Gherkin: https://github.com/cucumber/cucumber/blob/master/gherkin/gherkin-languages.json
    That's a lot and some languages (like German) have multiple words for Given/When/Then.
  • Adjust reflection code that searches for attributes
  • Adjust the binding skeleton generation so that the correct attribute is used.

The first point is the easy one. ;-)

@gasparnagy What do you say to this feature request?

I have also got this request from others. I think we can do this step-by-step. First I would just change the BindingSourceProcessor (https://github.com/techtalk/SpecFlow/blob/master/TechTalk.SpecFlow/Bindings/Discovery/BindingSourceProcessor.cs#L75) to use assignable-to instead of equals. With this the users could at least define their own derived attributes from Given/When/Then and use it in the code.

Once this is working, we can figure out how the attributes (for the most common languages at least) could be supported (maybe a separate NuGet package).

@gasparnagy Sounds like a plan.

So if someone from the community want to contribute this feature, I am happy to help them.

May I request an update? What is left to do here now? I see that the mentioned changes to discovery were made, is there anything left to do in terms of code generation?

Everything else is missing. So the translated attributes and then an adjusted code generation.

Was this page helpful?
0 / 5 - 0 ratings