specflow标识预期错误

时间:2018-01-04 20:22:35

标签: c# bdd specflow gherkin

生成步骤定义后,我遇到了构建解决方案的问题。 在THEN行

上有一个错误“标识符预期”,代码CS10001用于特征文件

这是特色文件

Feature: Contact
In order to contact with customer service
As an application user
I want to send a message to them

 Background: 
Given I am on Contact us page

Scenario Outline: Sending message with invalid/empty email adress
Given I enter '<email>' adress 
And I enter '<message>' 
When I click Send
Then Email field '<validation>' appears 

Examples: 

| email                |  | message     |     validation         |
| testemail@gmaill.com |  | testMessage | Invalid email address. |

这是代码

public class ContactSteps
    {
        [Given(@"I am on Contact us page")]
        public void GivenIAmOnContactUsPage()
        {
            ScenarioContext.Current.Pending();
        }

        [Given(@"I enter '(.*)' adress")]
        public void GivenIEnterAdress(string p0)
        {
            ScenarioContext.Current.Pending();
        }

        [Given(@"I enter '(.*)'")]
        public void GivenIEnter(string p0)
        {
            ScenarioContext.Current.Pending();
        }

        [When(@"I click Send")]
        public void WhenIClickSend()
        {
            ScenarioContext.Current.Pending();
        }

        [Then(@"Email field '(.*)' appears")]
        public void ThenEmailFieldAppears(string p0)
        {
            ScenarioContext.Current.Pending();
        }
    }

构建解决方案后

enter image description here

编辑:

这是后面的这个功能代码 - 也许这里是问题的根源

    using TechTalk.SpecFlow;


    [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "2.2.0.0")]
    [System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    [TechTalk.SpecRun.FeatureAttribute("Contact", Description="\tIn order to contact with customer service\r\n\tAs an application user\r\n\tI want to s" +
        "end a message to them", SourceFile="Features\\Contact.feature", SourceLine=0)]
    public partial class ContactFeature
    {

        private TechTalk.SpecFlow.ITestRunner testRunner;

#line 1 "Contact.feature"
#line hidden

        [TechTalk.SpecRun.FeatureInitialize()]
        public virtual void FeatureSetup()
        {
            testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner();
            TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Contact", "\tIn order to contact with customer service\r\n\tAs an application user\r\n\tI want to s" +
                    "end a message to them", ProgrammingLanguage.CSharp, ((string[])(null)));
            testRunner.OnFeatureStart(featureInfo);
        }

        [TechTalk.SpecRun.FeatureCleanup()]
        public virtual void FeatureTearDown()
        {
            testRunner.OnFeatureEnd();
            testRunner = null;
        }

        public virtual void TestInitialize()
        {
        }

        [TechTalk.SpecRun.ScenarioCleanup()]
        public virtual void ScenarioTearDown()
        {
            testRunner.OnScenarioEnd();
        }

        public virtual void ScenarioSetup(TechTalk.SpecFlow.ScenarioInfo scenarioInfo)
        {
            testRunner.OnScenarioStart(scenarioInfo);
        }

        public virtual void ScenarioCleanup()
        {
            testRunner.CollectScenarioErrors();
        }

        public virtual void FeatureBackground()
        {
#line 6
#line 7
testRunner.Given("I am on Contact us page", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given ");
#line hidden
        }

        public virtual void SendingMessageWithInvalidEmptyEmailAdress(string email, string , string message, string validation, string[] exampleTags)
        {
            TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Sending message with invalid/empty email adress", exampleTags);
#line 9
 this.ScenarioSetup(scenarioInfo);
#line 6
this.FeatureBackground();
#line 10
 testRunner.Given(string.Format("I enter \'{0}\' adress", email), ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given ");
#line 11
 testRunner.And(string.Format("I enter \'{0}\'", message), ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
#line 12
 testRunner.When("I click Send", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When ");
#line 13
 testRunner.Then(string.Format("Email field \'{0}\' appears", validation), ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then ");
#line hidden
            this.ScenarioCleanup();
        }

        [TechTalk.SpecRun.ScenarioAttribute("Sending message with invalid/empty email adress, testemail@gmail", SourceLine=17)]
        public virtual void SendingMessageWithInvalidEmptyEmailAdress_TestemailGmail()
        {
#line 9
 this.SendingMessageWithInvalidEmptyEmailAdress("testemail@gmail", "", "testMessage", "Invalid email address.", ((string[])(null)));
#line hidden
        }

        [TechTalk.SpecRun.TestRunCleanup()]
        public virtual void TestRunCleanup()
        {
            TechTalk.SpecFlow.TestRunnerManager.GetTestRunner().OnTestRunEnd();
        }
    }
}

编辑:

功能文件

的屏幕截图

enter image description here

编辑:

错误列表的屏幕截图

enter image description here

1 个答案:

答案 0 :(得分:1)

我看到了你的问题。您的specflow示例中有一个空列。这意味着这里没有标识符。

所以改变:

| email                |  | message     |     validation         |
| testemail@gmaill.com |  | testMessage | Invalid email address. |

要:

| email                | message     |     validation         |
| testemail@gmaill.com | testMessage | Invalid email address. |