Specflow-我们能否在Specflow示例表中传递参数

问题描述 投票:2回答:1

我的情况是

Scenario Outline: Verify if the user can create an response if user posts a request with invalid payload
    Given User had specified name <name> description <description> in create application request
    And User had specified tenantId id <tenantId> in header of createApplication request
    When User sends a create request to application service with invalidPayload
    Then User should get an error code <errorCode> in the createApplication response with error message as <errorMessage>
Examples:
| description| name | errorCode | errorMessage|tenantid|                                                            
| testdescription| DummyApplication| 857 | Application named ${name} already exists for a given tenant | mock|                   

在上一节中,我想验证错误消息,但具有名称参数,其值已在示例表中定义。我作为参数传递的预期错误消息是,“给定租户的名称为'DummyApplication'的应用程序已经存在。”

c# api automation bdd specflow
1个回答
0
投票
通常的方法是在拥有变量时存储该变量,并在以后需要时重新使用它。您可以使用ScenarioContext并具有一个属性。

private string Name { get { return ScenarioContext.Current["Name"].ToString(); } set { ScenarioContext.Current["Name"] = value; } } [Given(@"User had specified name (.*) description (.*) in create application request")] public void GivenUserHadSpecifiedNameDummyApplicationDescriptionTestdescriptionInCreateApplicationRequest(string name, string description) { // store the name this.Name = name; } [Then(@"User should get an error code (.*) in the createApplication response with error message as (.*)")] public void ThenUserShouldGetAnErrorCodeInTheCreateApplicationResponseWithErrorMessageAsApplicationNamedNameAlreadyExistsForAGivenTenant(int errorCode, string errorMessage) { // retrieve the name and use var expected = errorMessage.Replace("${name}", $"'{this.Name}'"); //Application named 'DummyApplication' already exists for a given tenant }

© www.soinside.com 2019 - 2024. All rights reserved.